]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Lock the running kernel
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Jun 2021 14:49:29 +0000 (14:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Jun 2021 14:49:29 +0000 (14:49 +0000)
This package cannot be removed

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index aca23170023693a1921686d39ecd64bbb4b1ae86..32eee22e9f59e1b1e15ff01d27ebbc6359671855 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/stat.h>
 #include <sys/sysmacros.h>
 #include <sys/types.h>
+#include <sys/utsname.h>
 #include <syslog.h>
 #include <unistd.h>
 
@@ -405,6 +406,33 @@ static void pakfire_pool_add_multiinstall(Pool* pool) {
        }
 }
 
+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;
@@ -435,6 +463,9 @@ 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);
        if (r)