// 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;
}
mp->flags = flags;
// Increment counter
- jail->num_mountpoints++;
+ self->num_mountpoints++;
return 0;
}
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));