]> git.ipfire.org Git - pakfire.git/commitdiff
request: Implement locking the running kernel as a pool job
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 Sep 2023 14:50:48 +0000 (14:50 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 Sep 2023 14:51:28 +0000 (14:51 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c
src/libpakfire/request.c

index e1c837b8b9066980f92dd9d89ce5b22a4bc33f37..a3c74f20cfc0f04134b2cfbdadff0202121999cc 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/file.h>
 #include <sys/mount.h>
 #include <sys/stat.h>
+#include <sys/utsname.h>
 #include <sys/types.h>
 #include <syslog.h>
 #include <unistd.h>
@@ -294,6 +295,31 @@ static Id pakfire_namespace_callback(Pool* pool, void* data, Id ns, Id id) {
                return 0;
 }
 
+static int pakfire_lock_running_kernel(struct pakfire* pakfire) {
+       struct utsname utsname;
+       char buffer[NAME_MAX];
+
+       // Call uname()
+       int r = uname(&utsname);
+       if (r) {
+               ERROR(pakfire, "uname() failed: %m\n");
+               return r;
+       }
+
+       DEBUG(pakfire, "Locking running kernel %s\n", utsname.release);
+
+       r = pakfire_string_format(buffer, "kernel(%s)", utsname.release);
+       if (r)
+               return r;
+
+       // Add a locking pool job
+       Id id = pool_str2id(pakfire->pool, buffer, 1);
+       if (id)
+               queue_push2(&pakfire->pool->pooljobs, SOLVER_LOCK|SOLVER_SOLVABLE_PROVIDES, id);
+
+       return 0;
+}
+
 static int pakfire_populate_pool(struct pakfire* pakfire) {
        struct pakfire_db* db = NULL;
        struct pakfire_repo* commandline = NULL;
@@ -370,6 +396,13 @@ static int pakfire_populate_pool(struct pakfire* pakfire) {
        if (r)
                goto ERROR;
 
+       // Lock the running kernel
+       if (pakfire_on_root(pakfire)) {
+               r = pakfire_lock_running_kernel(pakfire);
+               if (r)
+                       goto ERROR;
+       }
+
 ERROR:
        if (db)
                pakfire_db_unref(db);
index e0259658aa30674c8f03e437325c1bc2ce4ac7ad..0a348e6c98a376fa1ce33ef07dbf723923fe4b9c 100644 (file)
@@ -22,7 +22,6 @@
 #include <errno.h>
 #include <linux/limits.h>
 #include <stdlib.h>
-#include <sys/utsname.h>
 
 #include <solv/queue.h>
 #include <solv/selection.h>
@@ -62,31 +61,6 @@ 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)
-               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) {
        // Automatically update when installation is requested
        solver_set_flag(request->solver, SOLVER_FLAG_INSTALL_ALSO_UPDATES, 1);
@@ -103,10 +77,6 @@ static int setup_solver(struct pakfire_request* request, int flags) {
        if (flags & PAKFIRE_REQUEST_WITHOUT_RECOMMENDED)
                solver_set_flag(request->solver, SOLVER_FLAG_IGNORE_RECOMMENDED, 1);
 
-       // Lock the running kernel
-       if (pakfire_on_root(request->pakfire))
-               pakfire_request_lock_running_kernel(request);
-
        return 0;
 }