From: Michael Tremer Date: Tue, 22 Jun 2021 14:36:44 +0000 (+0000) Subject: pakfire: Add convenience function to check if pakfire is running on root X-Git-Tag: 0.9.28~1195 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=028ed5350a1d2a2aef42cee94e32c75eb5c4161f;p=pakfire.git pakfire: Add convenience function to check if pakfire is running on root Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 635254dfc..aca231700 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -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; }