From: Michael Tremer Date: Wed, 26 Mar 2025 15:38:55 +0000 (+0000) Subject: jail: Fix return codes of bind function X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f304c0bbc5886c53d9d3c34f51317acb8d995c17;p=pakfire.git jail: Fix return codes of bind function Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/jail.c b/src/pakfire/jail.c index d02f9362..b13b8bba 100644 --- a/src/pakfire/jail.c +++ b/src/pakfire/jail.c @@ -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; } diff --git a/tests/libpakfire/jail.c b/tests/libpakfire/jail.c index 689a1406..241bd720 100644 --- a/tests/libpakfire/jail.c +++ b/tests/libpakfire/jail.c @@ -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));