Commit 058c15af authored by Niels Möller's avatar Niels Möller
Browse files

(do_lsh_file_lock): Initialize info attribute in

new object.
(do_lsh_file_lock_p): New function, corresponding to a new method
for checking if a lock exists, without creating one.

Rev: src/lock_file.c:1.2
Rev: src/lock_file.h:1.2
parent e524c819
......@@ -78,11 +78,21 @@ do_lsh_file_lock(struct lsh_file_lock_info *self)
NEW(lsh_file_lock, lock);
init_resource(&lock->super, do_kill_file_lock);
lock->info = self;
close(fd);
return &lock->super;
}
}
/* Checks if a file is locked, without actually trying to lock it. */
static struct resource *
do_lsh_file_lock_p(struct lsh_file_lock_info *self)
{
struct stat sbuf;
return (stat(lsh_get_cstring(self->lockname), &sbuf) == 0);
}
struct lsh_file_lock_info *
make_lsh_file_lock_info(struct lsh_string *name)
......@@ -90,6 +100,7 @@ make_lsh_file_lock_info(struct lsh_string *name)
NEW(lsh_file_lock_info, self);
self->lockname = name;
self->lock = do_lsh_file_lock;
self->lock_p = do_lsh_file_lock_p;
return self;
}
......@@ -37,10 +37,12 @@ struct lsh_file_lock_info;
(name lsh_file_lock_info)
(vars
(lockname string)
(lock method "struct resource *")))
(lock method "struct resource *")
(lock_p method int)))
*/
#define LSH_FILE_LOCK(i) ((i)->lock((i)))
#define LSH_FILE_LOCK_P(i) ((i)->lock_p((i)))
struct lsh_file_lock_info *
make_lsh_file_lock_info(struct lsh_string *name);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment