From e9a8bb71b2270968be8be74785703b157deccb8f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 20 Aug 2022 12:30:24 +0100 Subject: [PATCH 1/1] prefork: Break out flock_file Signed-off-by: Ian Jackson --- cprogs/prefork.c | 10 +++++++--- cprogs/prefork.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) 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 \ -- 2.30.2