]> git.ipfire.org Git - pakfire.git/commitdiff
mount: Remove the legacy logger
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Jan 2024 18:02:54 +0000 (18:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Jan 2024 18:02:54 +0000 (18:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/mount.h
src/libpakfire/jail.c
src/libpakfire/mount.c
src/libpakfire/pakfire.c

index 5ba4517d2f8e762928942f1c5a1c1fdca634d9a0..dfaac970beb88b0cee8962f856cf68f58ece2fd5 100644 (file)
@@ -33,23 +33,27 @@ typedef enum pakfire_mntns {
 
 int pakfire_mount_change_propagation(struct pakfire_ctx* ctx, const char* path, int propagation);
 
-int pakfire_mount_make_mounpoint(struct pakfire* pakfire, const char* path);
+int pakfire_mount_make_mounpoint(struct pakfire_ctx* ctx,
+       struct pakfire* pakfire, const char* path);
 
-int pakfire_make_ramdisk(struct pakfire* pakfire, char* path, const char* args);
+int pakfire_make_ramdisk(struct pakfire_ctx* ctx,
+       struct pakfire* pakfire, char* path, const char* args);
 
-int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags);
+int pakfire_bind(struct pakfire_ctx* ctx, struct pakfire* pakfire,
+       const char* src, const char* dst, int flags);
 
 int pakfire_mount_list(struct pakfire_ctx* ctx);
 
-int pakfire_populate_dev(struct pakfire* pakfire, int flags);
+int pakfire_populate_dev(struct pakfire_ctx* ctx, struct pakfire* pakfire, int flags);
 
-int pakfire_mount_interpreter(struct pakfire* pakfire);
+int pakfire_mount_interpreter(struct pakfire_ctx* ctx, struct pakfire* pakfire);
 
 enum pakfire_mount_flags {
        PAKFIRE_MOUNT_LOOP_DEVICES = (1 << 0),
 };
 
-int pakfire_mount_all(struct pakfire* pakfire, pakfire_mntns_t ns, int flags);
+int pakfire_mount_all(struct pakfire_ctx* ctx, struct pakfire* pakfire,
+       pakfire_mntns_t ns, int flags);
 
 #endif /* PAKFIRE_PRIVATE */
 
index 8a61363c36bf880c2a7504637df0b5fb6435ddd1..b42c623881813a734bbb9b2db226ae07b18e75a5 100644 (file)
@@ -1680,7 +1680,7 @@ static int pakfire_jail_mount_networking(struct pakfire_jail* jail) {
 
        // Bind-mount all paths read-only
        for (const char** path = paths; *path; path++) {
-               r = pakfire_bind(jail->pakfire, *path, NULL, MS_RDONLY);
+               r = pakfire_bind(jail->ctx, jail->pakfire, *path, NULL, MS_RDONLY);
                if (r) {
                        switch (errno) {
                                // Ignore if we don't have permission
@@ -1710,17 +1710,17 @@ static int pakfire_jail_mount(struct pakfire_jail* jail, struct pakfire_jail_exe
                flags |= PAKFIRE_MOUNT_LOOP_DEVICES;
 
        // Mount all default stuff
-       r = pakfire_mount_all(jail->pakfire, PAKFIRE_MNTNS_OUTER, flags);
+       r = pakfire_mount_all(jail->ctx, jail->pakfire, PAKFIRE_MNTNS_OUTER, flags);
        if (r)
                return r;
 
        // Populate /dev
-       r = pakfire_populate_dev(jail->pakfire, flags);
+       r = pakfire_populate_dev(jail->ctx, jail->pakfire, flags);
        if (r)
                return r;
 
        // Mount the interpreter (if needed)
-       r = pakfire_mount_interpreter(jail->pakfire);
+       r = pakfire_mount_interpreter(jail->ctx, jail->pakfire);
        if (r)
                return r;
 
@@ -1737,7 +1737,7 @@ static int pakfire_jail_mount(struct pakfire_jail* jail, struct pakfire_jail_exe
                mp = &jail->mountpoints[i];
 
                // Mount it
-               r = pakfire_bind(jail->pakfire, mp->source, mp->target, mp->flags);
+               r = pakfire_bind(jail->ctx, jail->pakfire, mp->source, mp->target, mp->flags);
                if (r)
                        return r;
        }
@@ -2146,7 +2146,7 @@ static int pakfire_jail_child(struct pakfire_jail* jail, struct pakfire_jail_exe
        const int socket_send = pakfire_jail_get_pipe_to_write(jail, &ctx->socket);
 
        // Mount all default stuff
-       r = pakfire_mount_all(jail->pakfire, PAKFIRE_MNTNS_INNER, 0);
+       r = pakfire_mount_all(jail->ctx, jail->pakfire, PAKFIRE_MNTNS_INNER, 0);
        if (r)
                return 126;
 
@@ -2159,7 +2159,7 @@ static int pakfire_jail_child(struct pakfire_jail* jail, struct pakfire_jail_exe
                return r;
 
        // Make root a mountpoint in the new mount namespace
-       r = pakfire_mount_make_mounpoint(jail->pakfire, root);
+       r = pakfire_mount_make_mounpoint(jail->ctx, jail->pakfire, root);
        if (r)
                return r;
 
index 031e428455c7b8a7603ffb15850410456f97f783..a364baf0c701172f79a79ac066d0af12cf2c34fd 100644 (file)
@@ -26,9 +26,6 @@
 #include <sys/sysmacros.h>
 #include <sys/types.h>
 
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
 #include <pakfire/arch.h>
 #include <pakfire/logging.h>
 #include <pakfire/pakfire.h>
@@ -279,7 +276,8 @@ static int pakfire_mount_is_mountpoint(struct pakfire* pakfire, const char* path
        return 1;
 }
 
-int pakfire_mount_make_mounpoint(struct pakfire* pakfire, const char* path) {
+int pakfire_mount_make_mounpoint(struct pakfire_ctx* ctx, struct pakfire* pakfire,
+               const char* path) {
        int r;
 
        // Check if path already is a mountpoint
@@ -294,22 +292,22 @@ int pakfire_mount_make_mounpoint(struct pakfire* pakfire, const char* path) {
                        break;
 
                default:
-                       ERROR(pakfire, "Could not determine whether %s is a mountpoint: %m\n", path);
+                       CTX_ERROR(ctx, "Could not determine whether %s is a mountpoint: %m\n", path);
                        return r;
        }
 
        // Bind-mount to self
        r = mount(path, path, NULL, MS_BIND|MS_REC, NULL);
        if (r) {
-               ERROR(pakfire, "Could not make %s a mountpoint: %m\n", path);
+               CTX_ERROR(ctx, "Could not make %s a mountpoint: %m\n", path);
                return r;
        }
 
        return 0;
 }
 
-static int pakfire_mount(struct pakfire* pakfire, const char* source, const char* target,
-               const char* fstype, unsigned long mflags, const void* data) {
+static int pakfire_mount(struct pakfire_ctx* ctx, struct pakfire* pakfire, const char* source,
+               const char* target, const char* fstype, unsigned long mflags, const void* data) {
        const char* options = (const char*)data;
 
        // Check for some basic inputs
@@ -318,12 +316,12 @@ static int pakfire_mount(struct pakfire* pakfire, const char* source, const char
                return 1;
        }
 
-       DEBUG(pakfire, "Mounting %s from %s (%s - %s)\n", target, source, fstype, options);
+       CTX_DEBUG(ctx, "Mounting %s from %s (%s - %s)\n", target, source, fstype, options);
 
        // Perform mount()
        int r = mount(source, target, fstype, mflags, data);
        if (r) {
-               ERROR(pakfire, "Could not mount %s: %m\n", target);
+               CTX_ERROR(ctx, "Could not mount %s: %m\n", target);
        }
 
        return r;
@@ -344,12 +342,12 @@ int pakfire_mount_list(struct pakfire_ctx* ctx) {
        return pakfire_parse_file("/proc/self/mounts", __pakfire_mount_list, ctx);
 }
 
-int pakfire_populate_dev(struct pakfire* pakfire, int flags) {
+int pakfire_populate_dev(struct pakfire_ctx* ctx, struct pakfire* pakfire, int flags) {
        char path[PATH_MAX];
 
        // Create device nodes
        for (const struct pakfire_devnode* devnode = devnodes; devnode->path; devnode++) {
-               DEBUG(pakfire, "Creating device node %s\n", devnode->path);
+               CTX_DEBUG(ctx, "Creating device node %s\n", devnode->path);
 
                // Check if flags match
                if (devnode->flags && !(flags & devnode->flags))
@@ -374,26 +372,26 @@ int pakfire_populate_dev(struct pakfire* pakfire, int flags) {
                        goto MOUNT;
 
                // Otherwise log an error and end
-               ERROR(pakfire, "Could not create %s: %m\n", devnode->path);
+               CTX_ERROR(ctx, "Could not create %s: %m\n", devnode->path);
                return r;
 
 MOUNT:
                // Create an empty file
                r = pakfire_touch(path, 0444);
                if (r) {
-                       ERROR(pakfire, "Could not create %s: %m\n", path);
+                       CTX_ERROR(ctx, "Could not create %s: %m\n", path);
                        return r;
                }
 
                // Create a bind-mount over the file
-               r = pakfire_mount(pakfire, devnode->path, path, "bind", MS_BIND, NULL);
+               r = pakfire_mount(ctx, pakfire, devnode->path, path, "bind", MS_BIND, NULL);
                if (r)
                        return r;
        }
 
        // Create symlinks
        for (const struct pakfire_symlink* s = symlinks; s->target; s++) {
-               DEBUG(pakfire, "Creating symlink %s -> %s\n", s->path, s->target);
+               CTX_DEBUG(ctx, "Creating symlink %s -> %s\n", s->path, s->target);
 
                int r = pakfire_path(pakfire, path, "%s", s->path);
                if (r)
@@ -401,7 +399,7 @@ MOUNT:
 
                r = symlink(s->target, path);
                if (r) {
-                       ERROR(pakfire, "Could not create symlink %s: %m\n", s->path);
+                       CTX_ERROR(ctx, "Could not create symlink %s: %m\n", s->path);
                        return r;
                }
        }
@@ -409,7 +407,7 @@ MOUNT:
        return 0;
 }
 
-int pakfire_mount_interpreter(struct pakfire* pakfire) {
+int pakfire_mount_interpreter(struct pakfire_ctx* ctx, struct pakfire* pakfire) {
        char target[PATH_MAX];
 
        // Fetch the target architecture
@@ -422,7 +420,7 @@ int pakfire_mount_interpreter(struct pakfire* pakfire) {
        if (!interpreter)
                return 0;
 
-       DEBUG(pakfire, "Mounting interpreter %s for %s\n", interpreter, arch);
+       CTX_DEBUG(ctx, "Mounting interpreter %s for %s\n", interpreter, arch);
 
        // Where to mount this?
        int r = pakfire_path(pakfire, target, "%s", interpreter);
@@ -440,14 +438,14 @@ int pakfire_mount_interpreter(struct pakfire* pakfire) {
                return 1;
        fclose(f);
 
-       r = pakfire_mount(pakfire, interpreter, target, NULL, MS_BIND|MS_RDONLY, NULL);
+       r = pakfire_mount(ctx, pakfire, interpreter, target, NULL, MS_BIND|MS_RDONLY, NULL);
        if (r)
-               ERROR(pakfire, "Could not mount interpreter %s to %s: %m\n", interpreter, target);
+               CTX_ERROR(ctx, "Could not mount interpreter %s to %s: %m\n", interpreter, target);
 
        return r;
 }
 
-int pakfire_mount_all(struct pakfire* pakfire, pakfire_mntns_t ns, int flags) {
+int pakfire_mount_all(struct pakfire_ctx* ctx, struct pakfire* pakfire, pakfire_mntns_t ns, int flags) {
        char target[PATH_MAX];
        int r;
 
@@ -470,13 +468,14 @@ int pakfire_mount_all(struct pakfire* pakfire, pakfire_mntns_t ns, int flags) {
                if (!pakfire_path_exists(target)) {
                        r = pakfire_mkdir(target, 0755);
                        if (r) {
-                               ERROR(pakfire, "Could not create %s: %m\n", target);
+                               CTX_ERROR(ctx, "Could not create %s: %m\n", target);
                                return r;
                        }
                }
 
                // Perform mount()
-               r = pakfire_mount(pakfire, mp->source, target, mp->fstype, mp->flags, mp->options);
+               r = pakfire_mount(ctx, pakfire, mp->source, target,
+                       mp->fstype, mp->flags, mp->options);
                if (r)
                        return r;
        }
@@ -484,7 +483,8 @@ int pakfire_mount_all(struct pakfire* pakfire, pakfire_mntns_t ns, int flags) {
        return 0;
 }
 
-int pakfire_make_ramdisk(struct pakfire* pakfire, char* path, const char* args) {
+int pakfire_make_ramdisk(struct pakfire_ctx* ctx, struct pakfire* pakfire,
+               char* path, const char* args) {
        int r;
 
        // Create a new temporary directory
@@ -493,18 +493,20 @@ int pakfire_make_ramdisk(struct pakfire* pakfire, char* path, const char* args)
                return -errno;
 
        // Mount the ramdisk
-       r = pakfire_mount(pakfire, "pakfire_ramdisk", p, "tmpfs", 0, args);
+       r = pakfire_mount(ctx, pakfire, "pakfire_ramdisk", p, "tmpfs", 0, args);
        if (r) {
-               ERROR_ERRNO(pakfire, r, "Could not mount ramdisk at %s (%s): %m\n", p, args);
+               CTX_ERROR(ctx, "Could not mount ramdisk at %s (%s): %s\n",
+                       p, args, strerror(errno));
                return r;
        }
 
-       DEBUG(pakfire, "Ramdisk mounted at %s (%s)\n", p, args);
+       CTX_DEBUG(ctx, "Ramdisk mounted at %s (%s)\n", p, args);
 
        return 0;
 }
 
-int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags) {
+int pakfire_bind(struct pakfire_ctx* ctx, struct pakfire* pakfire,
+               const char* src, const char* dst, int flags) {
        struct stat st;
        char mountpoint[PATH_MAX];
 
@@ -515,11 +517,11 @@ int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int
        if (r)
                return r;
 
-       DEBUG(pakfire, "Bind-mounting %s to %s\n", src, mountpoint);
+       CTX_DEBUG(ctx, "Bind-mounting %s to %s\n", src, mountpoint);
 
        r = stat(src, &st);
        if (r < 0) {
-               ERROR(pakfire, "Could not stat %s: %m\n", src);
+               CTX_ERROR(ctx, "Could not stat %s: %m\n", src);
                return 1;
        }
 
@@ -554,7 +556,7 @@ int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int
        // as read-only and requires us to mount the source first, and then remount it
        // again using MS_RDONLY.
        if (flags & MS_RDONLY) {
-               r = pakfire_mount(pakfire, src, mountpoint, "bind", MS_BIND|MS_REC, NULL);
+               r = pakfire_mount(ctx, pakfire, src, mountpoint, "bind", MS_BIND|MS_REC, NULL);
                if (r)
                        return r;
 
@@ -563,5 +565,5 @@ int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int
        }
 
        // Perform mount
-       return pakfire_mount(pakfire, src, mountpoint, "bind", flags|MS_BIND|MS_REC, NULL);
+       return pakfire_mount(ctx, pakfire, src, mountpoint, "bind", flags|MS_BIND|MS_REC, NULL);
 }
index 8aab98aa1f20033a04d1c45bce7888b580765aaa..99cc684a1b9db165810260fc8a631b81e0609d4b 100644 (file)
@@ -814,7 +814,7 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx*
 
        // Create a ramdisk if no path was given
        if (!path) {
-               r = pakfire_make_ramdisk(p, tempdir, NULL);
+               r = pakfire_make_ramdisk(p->ctx, p, tempdir, NULL);
                if (r)
                        goto ERROR;