]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Add convenience function to check if pakfire is running on root
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Jun 2021 14:36:44 +0000 (14:36 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Jun 2021 14:36:44 +0000 (14:36 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index 635254dfcc7a4b845d3a54c7332c7f888bec8d90..aca23170023693a1921686d39ecd64bbb4b1ae86 100644 (file)
@@ -125,6 +125,10 @@ const char* pakfire_multiinstall_packages[] = {
        NULL,
 };
 
+static int pakfire_on_root(Pakfire pakfire) {
+       return (strcmp(pakfire->path, "/") == 0);
+}
+
 static const struct pakfire_mountpoint {
        const char* source;
        const char* target;
@@ -528,7 +532,7 @@ static void pakfire_free(Pakfire pakfire) {
 // Safety check in case this is being launched on the host system
 static int pakfire_safety_checks(Pakfire pakfire) {
        // Nothing to do if we are not working on root
-       if (strcmp(pakfire->path, "/") != 0)
+       if (!pakfire_on_root(pakfire))
                return 0;
 
        if (strcmp(pakfire->distro.id, "ipfire") != 0) {
@@ -1188,7 +1192,7 @@ ERROR:
 }
 
 PAKFIRE_EXPORT int pakfire_copy_in(Pakfire pakfire, const char* src, const char* dst) {
-       if (strcmp(pakfire->path, "/") == 0) {
+       if (pakfire_on_root(pakfire)) {
                errno = ENOTSUP;
                return 1;
        }
@@ -1202,7 +1206,7 @@ PAKFIRE_EXPORT int pakfire_copy_in(Pakfire pakfire, const char* src, const char*
 }
 
 PAKFIRE_EXPORT int pakfire_copy_out(Pakfire pakfire, const char* src, const char* dst) {
-       if (strcmp(pakfire->path, "/") == 0) {
+       if (pakfire_on_root(pakfire)) {
                errno = ENOTSUP;
                return 1;
        }