From: Ian Jackson Date: Sat, 20 Aug 2022 11:30:24 +0000 (+0100) Subject: prefork: Break out flock_file X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=e9a8bb71b2270968be8be74785703b157deccb8f;hp=8acd6705563dabfb61ec38bcdbf9339c68752254;p=chiark-utils.git prefork: Break out flock_file Signed-off-by: Ian Jackson --- diff --git a/cprogs/prefork.c b/cprogs/prefork.c index 21c4b7a..12d6021 100644 --- a/cprogs/prefork.c +++ b/cprogs/prefork.c @@ -184,14 +184,12 @@ void find_socket_path(void) { } // Returns fd -int acquire_lock(void) { +int flock_file(const char *lock_path) { int r; int lockfd = -1; struct stat stab_fd; struct stat stab_path; - lock_path = m_asprintf("%s/l%s",run_base,ident); - for (;;) { if (lockfd >= 0) { close(lockfd); lockfd = -1; } @@ -216,6 +214,12 @@ int acquire_lock(void) { return lockfd; } +// Returns fd +int acquire_lock(void) { + lock_path = m_asprintf("%s/l%s",run_base,ident); + return flock_file(lock_path); +} + static void shbang_opts(const char *const **argv_io, const struct cmdinfo *cmdinfos) { myopt(argv_io, cmdinfos); diff --git a/cprogs/prefork.h b/cprogs/prefork.h index a046835..11329ce 100644 --- a/cprogs/prefork.h +++ b/cprogs/prefork.h @@ -44,6 +44,7 @@ bool find_run_base_var_run(void); void find_socket_path(void); int acquire_lock(void); +int flock_file(const char *lock_path); extern const struct cmdinfo cmdinfos[]; #define PREFORK_CMDINFOS \