]> git.ipfire.org Git - pakfire.git/commitdiff
request: Move locking running kernel from pakfire
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Jun 2021 14:57:20 +0000 (14:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Jun 2021 14:57:20 +0000 (14:57 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c
src/libpakfire/request.c

index 19e5a3b708281d736cbd0108e6f7b0d5ec2720dd..407c0e8be6eaa8fc1cdbfa91cf05bd30244ca86e 100644 (file)
@@ -93,6 +93,8 @@ int pakfire_sync(Pakfire pakfire, int flags, int* changed);
 
 #include <pakfire/config.h>
 
+int pakfire_on_root(Pakfire pakfire);
+
 void pakfire_log(Pakfire pakfire, int priority, const char *file,
        int line, const char *fn, const char *format, ...)
        __attribute__((format(printf, 6, 7)));
index 6fe53b55107eea46bd8bc22b60ecdb09aa67414d..0da3f13b3bff133afca9f01b3b68dbcd155c6345 100644 (file)
@@ -30,7 +30,6 @@
 #include <sys/stat.h>
 #include <sys/sysmacros.h>
 #include <sys/types.h>
-#include <sys/utsname.h>
 #include <syslog.h>
 #include <unistd.h>
 
@@ -126,7 +125,7 @@ const char* pakfire_multiinstall_packages[] = {
        NULL,
 };
 
-static int pakfire_on_root(Pakfire pakfire) {
+int pakfire_on_root(Pakfire pakfire) {
        return (strcmp(pakfire->path, "/") == 0);
 }
 
@@ -399,40 +398,6 @@ static Id pakfire_namespace_callback(Pool* pool, void* data, Id ns, Id id) {
        return 0;
 }
 
-static void pakfire_pool_add_multiinstall(Pool* pool) {
-       for (const char** package = pakfire_multiinstall_packages; *package; package++) {
-               Id id = pool_str2id(pool, *package, 1);
-               queue_push2(&pool->pooljobs, SOLVER_MULTIVERSION|SOLVER_SOLVABLE_PROVIDES, id);
-       }
-}
-
-static void pakfire_lock_running_kernel(Pakfire pakfire, Pool* pool) {
-       struct utsname utsname;
-       char buffer[NAME_MAX];
-
-       // Nothing to do when not running on /
-       if (!pakfire_on_root(pakfire))
-               return;
-
-       // Call uname()
-       int r = uname(&utsname);
-       if (r) {
-               ERROR(pakfire, "uname() failed: %m\n");
-               return;
-       }
-
-       DEBUG(pakfire, "Locking running kernel %s\n", utsname.release);
-
-       r = pakfire_string_format(buffer, "kernel(%s)", utsname.release);
-       if (r < 0)
-               return;
-
-       // Add a locking pool job
-       Id id = pool_str2id(pool, buffer, 1);
-       if (id)
-               queue_push2(&pool->pooljobs, SOLVER_LOCK|SOLVER_SOLVABLE_PROVIDES, id);
-}
-
 static int pakfire_populate_pool(Pakfire pakfire) {
        struct pakfire_db* db;
        PakfireRepo repo = NULL;
@@ -463,8 +428,6 @@ static int pakfire_populate_pool(Pakfire pakfire) {
        // Add multiinstall packages
        pakfire_pool_add_multiinstall(pool);
 
-       // Lock the running kernel
-       pakfire_lock_running_kernel(pakfire, pool);
 
        // Open database in read-only mode and try to load all installed packages
        r = pakfire_db_open(&db, pakfire, PAKFIRE_DB_READWRITE);
index 0e8169e2fdc307a3c9fabbab2671f77e937367fd..37b3b2ad91a3db2a2762f0f45c2c99e18fc3b90d 100644 (file)
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <linux/limits.h>
 #include <stdlib.h>
+#include <sys/utsname.h>
 
 #include <solv/queue.h>
 #include <solv/selection.h>
@@ -60,6 +61,31 @@ static void pakfire_request_free(struct pakfire_request* request) {
        free(request);
 }
 
+static void pakfire_request_lock_running_kernel(struct pakfire_request* request) {
+       struct utsname utsname;
+       char buffer[NAME_MAX];
+
+       // Call uname()
+       int r = uname(&utsname);
+       if (r) {
+               ERROR(request->pakfire, "uname() failed: %m\n");
+               return;
+       }
+
+       DEBUG(request->pakfire, "Locking running kernel %s\n", utsname.release);
+
+       r = pakfire_string_format(buffer, "kernel(%s)", utsname.release);
+       if (r < 0)
+               return;
+
+       Pool* pool = pakfire_get_solv_pool(request->pakfire);
+
+       // Add a locking pool job
+       Id id = pool_str2id(pool, buffer, 1);
+       if (id)
+               queue_push2(&request->jobs, SOLVER_LOCK|SOLVER_SOLVABLE_PROVIDES, id);
+}
+
 static int setup_solver(struct pakfire_request* request, int flags) {
        if (flags & PAKFIRE_SOLVER_ALLOW_DOWNGRADE)
                solver_set_flag(request->solver, SOLVER_FLAG_ALLOW_DOWNGRADE, 1);
@@ -76,6 +102,10 @@ static int setup_solver(struct pakfire_request* request, int flags) {
        /* no arch change for forcebest */
        solver_set_flag(request->solver, SOLVER_FLAG_BEST_OBEY_POLICY, 1);
 
+       // Lock the running kernel
+       if (pakfire_on_root(request->pakfire))
+               pakfire_request_lock_running_kernel(request);
+
        return 0;
 }