]> git.ipfire.org Git - pakfire.git/commitdiff
jail: Fix return codes of bind function
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 26 Mar 2025 15:38:55 +0000 (15:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 26 Mar 2025 15:38:55 +0000 (15:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/jail.c
tests/libpakfire/jail.c

index d02f93623a2c4e282b0a808b727b0d04296f0b37..b13b8bba35e62c85180264f645f055ce7a64de19 100644 (file)
@@ -817,37 +817,33 @@ ERROR:
 
 // Mountpoints
 
-int pakfire_jail_bind(struct pakfire_jail* jail,
+int pakfire_jail_bind(struct pakfire_jail* self,
                const char* source, const char* target, int flags) {
        struct pakfire_jail_mountpoint* mp = NULL;
        int r;
 
        // Check if there is any space left
-       if (jail->num_mountpoints >= MAX_MOUNTPOINTS) {
-               errno = ENOSPC;
-               return 1;
-       }
+       if (self->num_mountpoints >= MAX_MOUNTPOINTS)
+               return -ENOSPC;
 
        // Check for valid inputs
-       if (!source || !target) {
-               errno = EINVAL;
-               return 1;
-       }
+       if (!source || !target)
+               return -EINVAL;
 
        // Select the next free slot
-       mp = &jail->mountpoints[jail->num_mountpoints];
+       mp = &self->mountpoints[self->num_mountpoints];
 
        // Copy source
        r = pakfire_string_set(mp->source, source);
-       if (r) {
-               ERROR(jail->ctx, "Could not copy source: %m\n");
+       if (r < 0) {
+               ERROR(self->ctx, "Could not copy source: %s\n", strerror(-r));
                return r;
        }
 
        // Copy target
        r = pakfire_string_set(mp->target, target);
-       if (r) {
-               ERROR(jail->ctx, "Could not copy target: %m\n");
+       if (r < 0) {
+               ERROR(self->ctx, "Could not copy target: %s\n", strerror(-r));
                return r;
        }
 
@@ -855,7 +851,7 @@ int pakfire_jail_bind(struct pakfire_jail* jail,
        mp->flags = flags;
 
        // Increment counter
-       jail->num_mountpoints++;
+       self->num_mountpoints++;
 
        return 0;
 }
index 689a140676462392ea38a17e91a84426e400e3d4..241bd72073e5f1929fbc6fe59449c4a717a21e43 100644 (file)
@@ -306,8 +306,8 @@ static int test_bind(const struct test* t) {
        ASSERT_SUCCESS(pakfire_jail_create(&jail, t->pakfire));
 
        // Bind-mount nonsense
-       ASSERT_ERRNO(pakfire_jail_bind(jail, NULL, target, 0), EINVAL);
-       ASSERT_ERRNO(pakfire_jail_bind(jail, source, NULL, 0), EINVAL);
+       ASSERT_ERROR(pakfire_jail_bind(jail, NULL, target, 0), EINVAL);
+       ASSERT_ERROR(pakfire_jail_bind(jail, source, NULL, 0), EINVAL);
 
        // Bind-mount something
        ASSERT_SUCCESS(pakfire_jail_bind(jail, source, target, MS_RDONLY));