]> git.ipfire.org Git - pakfire.git/commitdiff
mount: Remove the special Pakfire logger
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Oct 2024 14:33:13 +0000 (14:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Oct 2024 14:33:13 +0000 (14:33 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/mount.h
src/libpakfire/jail.c
src/libpakfire/mount.c

index 92e489eb5214ec7fe23e2269d6e46c2b19a5fdc8..f907113d4a0205e775da7cb4720abd1ed0d993e0 100644 (file)
@@ -31,23 +31,25 @@ typedef enum pakfire_mntns {
        PAKFIRE_MNTNS_OUTER = (2 << 0),
 } pakfire_mntns_t;
 
-int pakfire_mount_change_propagation(struct pakfire* pakfire, const char* path, int propagation);
+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, const char* path);
 
-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* pakfire);
+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 7b77ac12127cc0bbe66f038e96ed8982cf12c5c4..4e45878a74dfa77a26624425e894be6bb03f0fe2 100644 (file)
@@ -715,7 +715,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
@@ -745,17 +745,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;
 
@@ -772,7 +772,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;
        }
@@ -1181,7 +1181,7 @@ static int pakfire_jail_child(struct pakfire_jail* jail, struct pakfire_jail_exe
        CTX_DEBUG(jail->ctx, "  GID: %u (effective %u)\n", gid, egid);
 
        // Log all mountpoints
-       pakfire_mount_list(jail->pakfire);
+       pakfire_mount_list(jail->ctx);
 
        // Fail if we are not PID 1
        if (pid != 1) {
@@ -1196,7 +1196,7 @@ static int pakfire_jail_child(struct pakfire_jail* jail, struct pakfire_jail_exe
        }
 
        // 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;
 
@@ -1204,17 +1204,17 @@ static int pakfire_jail_child(struct pakfire_jail* jail, struct pakfire_jail_exe
        const char* arch = pakfire_get_effective_arch(jail->pakfire);
 
        // Change mount propagation to slave to receive anything from the parent namespace
-       r = pakfire_mount_change_propagation(jail->pakfire, "/", MS_SLAVE);
+       r = pakfire_mount_change_propagation(jail->ctx, "/", MS_SLAVE);
        if (r)
                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, root);
        if (r)
                return r;
 
        // Change mount propagation to private
-       r = pakfire_mount_change_propagation(jail->pakfire, root, MS_PRIVATE);
+       r = pakfire_mount_change_propagation(jail->ctx, root, MS_PRIVATE);
        if (r)
                return r;
 
index 6843296f0e05dbb0e5517a78b08471e6889375d8..8ae94ee923f15ab6f859e45fe0642ebe519cf212 100644 (file)
@@ -261,26 +261,26 @@ static const struct pakfire_symlink {
        { NULL },
 };
 
-int pakfire_mount_change_propagation(struct pakfire* pakfire, const char* path, int propagation) {
-       PAKFIRE_DEBUG(pakfire, "Changing mount propagation on %s\n", path);
+int pakfire_mount_change_propagation(struct pakfire_ctx* ctx, const char* path, int propagation) {
+       CTX_DEBUG(ctx, "Changing mount propagation on %s\n", path);
 
        int r = mount(NULL, path, NULL, propagation|MS_REC, NULL);
        if (r)
-               PAKFIRE_ERROR(pakfire, "Failed to change mount propagation on %s: %m\n", path);
+               CTX_ERROR(ctx, "Failed to change mount propagation on %s: %m\n", path);
 
        return r;
 }
 
-static int pakfire_mount_is_mountpoint(struct pakfire* pakfire, const char* path) {
+static int pakfire_mount_is_mountpoint(struct pakfire_ctx* ctx, const char* path) {
        // XXX THIS STILL NEEDS TO BE IMPLEMENTED
        return 1;
 }
 
-int pakfire_mount_make_mounpoint(struct pakfire* pakfire, const char* path) {
+int pakfire_mount_make_mounpoint(struct pakfire_ctx* ctx, const char* path) {
        int r;
 
        // Check if path already is a mountpoint
-       r = pakfire_mount_is_mountpoint(pakfire, path);
+       r = pakfire_mount_is_mountpoint(ctx, path);
        switch (r) {
                // Already is a mountpoint
                case 0:
@@ -291,21 +291,21 @@ int pakfire_mount_make_mounpoint(struct pakfire* pakfire, const char* path) {
                        break;
 
                default:
-                       PAKFIRE_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) {
-               PAKFIRE_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,
+static int pakfire_mount(struct pakfire_ctx* ctx, const char* source, const char* target,
                const char* fstype, unsigned long mflags, const void* data) {
        const char* options = (const char*)data;
 
@@ -315,38 +315,38 @@ static int pakfire_mount(struct pakfire* pakfire, const char* source, const char
                return 1;
        }
 
-       PAKFIRE_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) {
-               PAKFIRE_ERROR(pakfire, "Could not mount %s: %m\n", target);
+               CTX_ERROR(ctx, "Could not mount %s: %m\n", target);
        }
 
        return r;
 }
 
 static int __pakfire_mount_list(char* line, size_t length, void* data) {
-       struct pakfire* pakfire = data;
+       struct pakfire_ctx* ctx = data;
 
        // Send the line to the logger
-       PAKFIRE_DEBUG(pakfire, "  %.*s", (int)length, line);
+       CTX_DEBUG(ctx, "  %.*s", (int)length, line);
 
        return 0;
 }
 
-int pakfire_mount_list(struct pakfire* pakfire) {
-       PAKFIRE_DEBUG(pakfire, "Mountpoints:\n");
+int pakfire_mount_list(struct pakfire_ctx* ctx) {
+       CTX_DEBUG(ctx, "Mountpoints:\n");
 
-       return pakfire_parse_file("/proc/self/mounts", __pakfire_mount_list, pakfire);
+       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++) {
-               PAKFIRE_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))
@@ -371,26 +371,26 @@ int pakfire_populate_dev(struct pakfire* pakfire, int flags) {
                        goto MOUNT;
 
                // Otherwise log an error and end
-               PAKFIRE_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) {
-                       PAKFIRE_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, devnode->path, path, "bind", MS_BIND, NULL);
                if (r)
                        return r;
        }
 
        // Create symlinks
        for (const struct pakfire_symlink* s = symlinks; s->target; s++) {
-               PAKFIRE_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)
@@ -398,7 +398,7 @@ MOUNT:
 
                r = symlink(s->target, path);
                if (r) {
-                       PAKFIRE_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;
                }
        }
@@ -406,7 +406,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
@@ -419,7 +419,7 @@ int pakfire_mount_interpreter(struct pakfire* pakfire) {
        if (!interpreter)
                return 0;
 
-       PAKFIRE_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);
@@ -437,14 +437,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, interpreter, target, NULL, MS_BIND|MS_RDONLY, NULL);
        if (r)
-               PAKFIRE_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;
 
@@ -467,13 +467,13 @@ 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) {
-                               PAKFIRE_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, mp->source, target, mp->fstype, mp->flags, mp->options);
                if (r)
                        return r;
        }
@@ -481,7 +481,8 @@ int pakfire_mount_all(struct pakfire* pakfire, pakfire_mntns_t ns, int flags) {
        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];
 
@@ -492,11 +493,11 @@ int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int
        if (r)
                return r;
 
-       PAKFIRE_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) {
-               PAKFIRE_ERROR(pakfire, "Could not stat %s: %m\n", src);
+               CTX_ERROR(ctx, "Could not stat %s: %m\n", src);
                return 1;
        }
 
@@ -531,7 +532,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, src, mountpoint, "bind", MS_BIND|MS_REC, NULL);
                if (r)
                        return r;
 
@@ -540,5 +541,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, src, mountpoint, "bind", flags|MS_BIND|MS_REC, NULL);
 }