From: Michael Tremer Date: Sat, 12 Oct 2024 17:11:36 +0000 (+0000) Subject: pakfire: Remove the unused locking mechanism X-Git-Tag: 0.9.30~1064 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=22dacb92a0954f952ea2a511201c96bc3d77875d;p=pakfire.git pakfire: Remove the unused locking mechanism Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 6d0e9c7b5..32836b3ce 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -115,10 +115,6 @@ int pakfire_get_log_level(struct pakfire* pakfire); void pakfire_log(struct pakfire* pakfire, int level, const char* file, int line, const char* fn, const char* format, ...) __attribute__((format(printf, 6, 7))); -// Locking -int pakfire_acquire_lock(struct pakfire* pakfire); -void pakfire_release_lock(struct pakfire* pakfire); - struct pakfire_config* pakfire_get_config(struct pakfire* pakfire); int pakfire_confirm(struct pakfire* pakfire, const char* message, const char* question); diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 1cae2522a..1870084d4 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -64,14 +64,11 @@ #include #include -#define LOCK_PATH PAKFIRE_PRIVATE_DIR "/.lock" - struct pakfire { struct pakfire_ctx* ctx; int nrefs; char path[PATH_MAX]; - char lock_path[PATH_MAX]; char cache_path[PATH_MAX]; struct pakfire_arches { @@ -389,9 +386,6 @@ static void pakfire_free(struct pakfire* pakfire) { pakfire_repo_unref(repo); } - // Release lock (if not already done so) - pakfire_release_lock(pakfire); - if (pakfire->destroy_on_free && *pakfire->path) { CTX_DEBUG(pakfire->ctx, "Destroying %s\n", pakfire->path); @@ -873,13 +867,6 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* if (*p->distro.slogan) CTX_DEBUG(p->ctx, " slogan = %s\n", p->distro.slogan); - // Set lock path - r = pakfire_path(p, p->lock_path, "%s", LOCK_PATH); - if (r) { - CTX_ERROR(p->ctx, "Could not set lock path: %m\n"); - goto ERROR; - } - // Set cache path r = pakfire_set_cache_path(p); if (r) { @@ -953,60 +940,6 @@ PAKFIRE_EXPORT const char* pakfire_get_path(struct pakfire* pakfire) { return pakfire->path; } -int pakfire_acquire_lock(struct pakfire* pakfire) { - int r; - - // Check if the lock is already held - if (pakfire->lock) { - CTX_ERROR(pakfire->ctx, "Lock is already been acquired by this process\n"); - return -ENOLCK; - } - - CTX_DEBUG(pakfire->ctx, "Acquire lock...\n"); - - // Ensure the parent directory exists - pakfire_mkparentdir(pakfire->lock_path, 0755); - - // Open the lock file - pakfire->lock = fopen(pakfire->lock_path, "w"); - if (!pakfire->lock) { - CTX_ERROR(pakfire->ctx, "Could not open lock file %s: %m\n", pakfire->lock_path); - return -errno; - } - - // Attempt to lock the file exclusively - while (1) { - r = flock(fileno(pakfire->lock), LOCK_EX|LOCK_NB); - - // Success! - if (r == 0) - goto SUCCESS; - - CTX_DEBUG(pakfire->ctx, "Could not acquire lock %s: %m\n", pakfire->lock_path); - - // Wait 500ms until the next attempt - usleep(500000); - } - -SUCCESS: - CTX_DEBUG(pakfire->ctx, "Lock acquired\n"); - - return 0; -} - -void pakfire_release_lock(struct pakfire* pakfire) { - if (!pakfire->lock) - return; - - CTX_DEBUG(pakfire->ctx, "Releasing lock\n"); - - fclose(pakfire->lock); - pakfire->lock = NULL; - - // Attempt to unlink the lock file - unlink(pakfire->lock_path); -} - int __pakfire_path(struct pakfire* pakfire, char* path, const size_t length, const char* format, ...) { char buffer[PATH_MAX];