- db->fd = open (fname, O_RDONLY);
- if (db->fd == -1)
- return gw_db_free (db);
- lock_file (db->fd, write_flag ? F_WRLCK : F_RDLCK);
+ {
+ if ((db->fd = open (fname, O_RDONLY)) == -1)
+ {
+ gw_log (GW_LOG_WARN|GW_LOG_ERRNO, mod, " open %s", fname);
+ return gw_db_free (db);
+ }
+ }
+ if (block)
+ lock_file (db->fd, 1, write_flag ? F_WRLCK : F_RDLCK);
+ else
+ {
+ r = lock_file (db->fd, 0, write_flag ? F_WRLCK : F_RDLCK);
+ if (r == -1)
+ {
+ gw_log (GW_LOG_WARN|GW_LOG_ERRNO, mod, "flock %s", fname);
+ close (db->fd);
+ return gw_db_free (db);
+ }
+ }