From: Michael Tremer Date: Tue, 22 Jun 2021 14:49:29 +0000 (+0000) Subject: pakfire: Lock the running kernel X-Git-Tag: 0.9.28~1194 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7752c65bce34b8ff97e3c9263530bc2c4d61da1e;p=pakfire.git pakfire: Lock the running kernel This package cannot be removed Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index aca231700..32eee22e9 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -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)