]> git.ipfire.org Git - pakfire.git/commitdiff
systemd: Automatically apply tmpfiles
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 19 Mar 2023 12:57:35 +0000 (12:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 19 Mar 2023 19:04:31 +0000 (19:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/jail.h
src/libpakfire/jail.c
src/libpakfire/packager.c
src/libpakfire/pakfire.c
src/libpakfire/transaction.c

index 03500bb8269ac933c510a8571f546459c2227ce7..d691086c3d8b171d529201fb427002c70ba56572 100644 (file)
@@ -88,6 +88,7 @@ int pakfire_jail_exec_script(struct pakfire_jail* jail,
 
 int pakfire_jail_shell(struct pakfire_jail* jail);
 int pakfire_jail_ldconfig(struct pakfire* pakfire);
+int pakfire_jail_run_systemd_tmpfiles(struct pakfire* pakfire);
 
 #endif /* PAKFIRE_PRIVATE */
 
index c00be6d3e2c4f4560cd25464e76cf1d479a083a5..f9d18a83c8739de314b6790928a58a4aac3fb91c 100644 (file)
@@ -1919,27 +1919,39 @@ int pakfire_jail_shell(struct pakfire_jail* jail) {
        return pakfire_jail_exec_interactive(jail, argv);
 }
 
-int pakfire_jail_ldconfig(struct pakfire* pakfire) {
+static int pakfire_jail_run_if_possible(struct pakfire* pakfire, const char** argv) {
        char path[PATH_MAX];
+       int r;
 
-       const char* ldconfig = "/sbin/ldconfig";
-
-       // Check if ldconfig exists before calling it to avoid overhead
-       int r = pakfire_path(pakfire, path, "%s", ldconfig);
+       r = pakfire_path(pakfire, path, "%s", *argv);
        if (r)
                return r;
 
-       // Check if ldconfig is executable
+       // Check if the file is executable
        r = access(path, X_OK);
        if (r) {
-               DEBUG(pakfire, "%s is not executable. Skipping...\n", ldconfig);
+               DEBUG(pakfire, "%s is not executable. Skipping...\n", *argv);
                return 0;
        }
 
+       return pakfire_jail_run(pakfire, argv, 0, NULL);
+}
+
+int pakfire_jail_ldconfig(struct pakfire* pakfire) {
        const char* argv[] = {
-               ldconfig, NULL,
+               "/sbin/ldconfig",
+               NULL,
        };
 
-       // Run ldconfig
-       return pakfire_jail_run(pakfire, argv, 0, NULL);
+       return pakfire_jail_run_if_possible(pakfire, argv);
+}
+
+int pakfire_jail_run_systemd_tmpfiles(struct pakfire* pakfire) {
+       const char* argv[] = {
+               "/usr/bin/systemd-tmpfiles",
+               "--create",
+               NULL,
+       };
+
+       return pakfire_jail_run_if_possible(pakfire, argv);
 }
index b379895ac0b414aa4d58d46bb13c709450fc7512..dc5038376a06dd85797732efc3d1a30659bcab21 100644 (file)
@@ -579,6 +579,15 @@ int pakfire_packager_add_file(struct pakfire_packager* packager, struct pakfire_
                pakfire_file_set_gname(file, "root");
        }
 
+       if (pakfire_file_matches(file, "/usr/lib/tmpfiles.d/*.conf")) {
+               pakfire_package_add_dep(packager->pkg,
+                       PAKFIRE_PKG_REQUIRES, "pakfire(systemd-tmpfiles)");
+
+               // Ask to pre-install systemd
+               pakfire_package_add_dep(packager->pkg,
+                       PAKFIRE_PKG_PREREQUIRES, "systemd");
+       }
+
        // Append the file to the filelist
        return pakfire_filelist_add(packager->filelist, file);
 }
index 584416ced616e8859015d7d5a64a36987e148de9..ad1093ac946e7582ed6a0d1e7f902033332695e3 100644 (file)
@@ -155,6 +155,9 @@ static const struct pakfire_feature {
        { "Digest-SHA2-512" },
        { "Digest-SHA2-256" },
 
+       // Systemd
+       { "systemd-tmpfiles" },
+
        // The end
        { NULL },
 };
index 2c97ea2006b2d9d0dd77c1e8119e8a02e9a57aaa..d8a39b8e894e27231cd52dd540b5d1a38b71d38e 100644 (file)
@@ -814,6 +814,15 @@ static int pakfire_transaction_package_is_userinstalled(
        return 0;
 }
 
+static int pakfire_transaction_apply_systemd_tmpfiles(
+               struct pakfire_transaction* transaction, struct pakfire_package* pkg) {
+       // Apply any tmpfiles (ignore any errors)
+       if (pakfire_package_matches_dep(pkg, PAKFIRE_PKG_REQUIRES, "pakfire(systemd-tmpfiles)"))
+               pakfire_jail_run_systemd_tmpfiles(transaction->pakfire);
+
+       return 0;
+}
+
 static int pakfire_transaction_run_step(struct pakfire_transaction* transaction,
                struct pakfire_db* db, const enum pakfire_actions action, struct pakfire_package* pkg, struct pakfire_archive* archive) {
        if (!pkg) {
@@ -917,6 +926,11 @@ static int pakfire_transaction_run_step(struct pakfire_transaction* transaction,
                                        if (r)
                                                break;
 
+                                       // Apply systemd tmpfiles
+                                       r = pakfire_transaction_apply_systemd_tmpfiles(transaction, pkg);
+                                       if (r)
+                                               break;
+
                                        r = pakfire_transaction_run_script(transaction, db,
                                                "postin", pkg, archive);
                                        break;
@@ -937,6 +951,11 @@ static int pakfire_transaction_run_step(struct pakfire_transaction* transaction,
                                        if (r)
                                                break;
 
+                                       // Apply systemd tmpfiles
+                                       r = pakfire_transaction_apply_systemd_tmpfiles(transaction, pkg);
+                                       if (r)
+                                               break;
+
                                        r = pakfire_transaction_run_script(transaction, db,
                                                "postup", pkg, archive);
                                        break;