]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Remove the unused locking mechanism
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 12 Oct 2024 17:11:36 +0000 (17:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 12 Oct 2024 17:11:36 +0000 (17:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c

index 6d0e9c7b5452bd7f4ff9ead0dc54f27a479c8846..32836b3cec1c49f87b4eaaf734f67591a4ee6eb5 100644 (file)
@@ -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);
index 1cae2522a8b3254c7255618aa20b068c988ab63c..1870084d45cfeb8d09c0cad2652e98f5f52a3269 100644 (file)
 #include <pakfire/transaction.h>
 #include <pakfire/util.h>
 
-#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];