]> git.ipfire.org Git - pakfire.git/commitdiff
mount: Use mount(2) to perform any mount operations
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 Jul 2022 09:37:30 +0000 (09:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 Jul 2022 09:37:30 +0000 (09:37 +0000)
libmount did too much voodoo here which prevented us from running
smoothly for unprivileged users.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/mount.c

index b0194b19c37fed6ac62462e9bc7a84cbcd59a9a5..e671a69552cb0709371450ebac86c69d1415024d 100644 (file)
@@ -166,9 +166,6 @@ int pakfire_is_mountpoint(struct pakfire* pakfire, const char* path) {
 static int pakfire_mount(struct pakfire* pakfire, const char* source, const char* target,
                const char* fstype, unsigned long mflags, const void* data) {
        const char* options = (const char*)data;
-       int r;
-
-       char error[1024];
 
        // Check for some basic inputs
        if (!source || !target) {
@@ -176,74 +173,14 @@ 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);
-
-#ifdef PAKFIRE_DEBUG
-       // Enable debugging for libmount
-       mnt_init_debug(0xffff);
-#endif
-
-       // Allocate a new mount context
-       struct libmnt_context* ctx = mnt_new_context();
-       if (!ctx)
-               return 1;
+       DEBUG(pakfire, "Mounting %s from %s (%s - %s)\n", target, source, fstype, options);
 
-       // Set source
-       r = mnt_context_set_source(ctx, source);
+       // Perform mount()
+       int r = mount(source, target, fstype, mflags, data);
        if (r) {
-               ERROR(pakfire, "Could not set source: %m\n");
-               goto ERROR;
+               ERROR(pakfire, "Could not mount %s: %m\n", target);
        }
 
-       // Set target
-       r = mnt_context_set_target(ctx, target);
-       if (r) {
-               ERROR(pakfire, "Could not set target: %m\n");
-               goto ERROR;
-       }
-
-       // Set filesystem type
-       if (fstype) {
-               r = mnt_context_set_fstype(ctx, fstype);
-               if (r) {
-                       ERROR(pakfire, "Could not set filesystem type: %m\n");
-                       goto ERROR;
-               }
-       }
-
-       // Set mount flags
-       if (mflags) {
-               r = mnt_context_set_mflags(ctx, mflags);
-               if (r) {
-                       ERROR(pakfire, "Could not set mount flags: %m\n");
-                       goto ERROR;
-               }
-       }
-
-       // Set options
-       if (options) {
-               r = mnt_context_set_options(ctx, options);
-               if (r) {
-                       ERROR(pakfire, "Could not set mount options: %m\n");
-                       goto ERROR;
-               }
-       }
-
-       // Perform mount operation
-       r = mnt_context_mount(ctx);
-       if (r) {
-               // Fetch the error message
-               mnt_context_get_excode(ctx, r, error, sizeof(error));
-
-               ERROR(pakfire, "Mount unsuccessful: %s\n", error);
-               goto ERROR;
-       }
-
-ERROR:
-       if (ctx)
-               mnt_free_context(ctx);
-
        return r;
 }
 
@@ -395,7 +332,6 @@ RETRY:
                                goto RETRY;
                        }
 
-                       ERROR(pakfire, "Could not mount /%s: %m\n", mp->target);
                        return r;
                }
        }