}
int pakfire_jail_create(struct pakfire_jail** jail, struct pakfire* pakfire) {
+ struct pakfire_jail* self = NULL;
int r;
- const char* arch = pakfire_get_effective_arch(pakfire);
-
// Allocate a new jail
- struct pakfire_jail* j = calloc(1, sizeof(*j));
- if (!j)
- return 1;
+ self = calloc(1, sizeof(*self));
+ if (!self)
+ return -errno;
// Reference context
- j->ctx = pakfire_ctx(pakfire);
+ self->ctx = pakfire_ctx(pakfire);
// Reference Pakfire
- j->pakfire = pakfire_ref(pakfire);
+ self->pakfire = pakfire_ref(pakfire);
// Initialize reference counter
- j->nrefs = 1;
+ self->nrefs = 1;
// Generate a random UUID
- uuid_generate_random(j->uuid);
+ uuid_generate_random(self->uuid);
// Create environment
- r = pakfire_env_create(&j->env, j->ctx);
+ r = pakfire_env_create(&self->env, self->ctx);
if (r < 0)
goto ERROR;
// Set default environment
for (const struct environ* e = ENV; e->key; e++) {
- r = pakfire_env_set(j->env, e->key, "%s", e->val);
+ r = pakfire_env_set(self->env, e->key, "%s", e->val);
if (r < 0)
goto ERROR;
}
+ // Fetch the architecture
+ const char* arch = pakfire_get_effective_arch(pakfire);
+
// Enable all CPU features that CPU has to offer
if (!pakfire_arch_is_supported_by_host(arch)) {
- r = pakfire_env_set(j->env, "QEMU_CPU", "max");
+ r = pakfire_env_set(self->env, "QEMU_CPU", "max");
if (r < 0)
goto ERROR;
}
// Set container UUID
- r = pakfire_env_set(j->env, "container_uuid", "%s", pakfire_jail_uuid(j));
+ r = pakfire_env_set(self->env, "container_uuid", "%s", pakfire_jail_uuid(self));
if (r < 0)
goto ERROR;
// Disable systemctl to talk to systemd
- if (!pakfire_on_root(j->pakfire)) {
- r = pakfire_env_set(j->env, "SYSTEMD_OFFLINE", "1");
+ if (!pakfire_on_root(self->pakfire)) {
+ r = pakfire_env_set(self->env, "SYSTEMD_OFFLINE", "1");
if (r < 0)
goto ERROR;
}
// Log action
- DEBUG(j->ctx, "Created new jail %s\n", pakfire_jail_uuid(j));
+ DEBUG(self->ctx, "Created new jail %s\n", pakfire_jail_uuid(self));
// Done
- *jail = j;
+ *jail = self;
return 0;
ERROR:
- pakfire_jail_free(j);
+ pakfire_jail_free(self);
return r;
}