// We must be root in order to operate in /
if (pakfire->user.uid) {
CTX_ERROR(pakfire->ctx, "Must be running as root on /\n");
- errno = EPERM;
- return 1;
- }
-
- if (strcmp(pakfire->distro.id, "ipfire") != 0) {
- CTX_ERROR(pakfire->ctx, "Not an IPFire system\n");
- errno = EPERM;
- return 1;
+ return -EPERM;
}
return 0;
return 0;
}
-static int pakfire_read_config(struct pakfire* pakfire, FILE* f) {
- int r;
-
- CTX_DEBUG(pakfire->ctx, "Reading configuration\n");
-
- // Read configuration from file
- if (f) {
- r = pakfire_config_read(pakfire->config, f);
- if (r) {
- CTX_ERROR(pakfire->ctx, "Could not parse configuration: %m\n");
- return r;
- }
- }
-
- // Import distro configuration
- r = pakfire_config_import_distro(pakfire);
- if (r)
- return r;
-
-#if 0
- // Read repository configuration
- r = pakfire_read_repo_config(pakfire);
- if (r)
- return r;
-#endif
-
- return 0;
-}
-
static int pakfire_read_os_release(struct pakfire* pakfire) {
char path[PATH_MAX];
int r;
// Compose path
r = pakfire_path(pakfire, path, "%s", "/etc/os-release");
- if (r)
+ if (r < 0)
return r;
- return pakfire_distro(&pakfire->distro, path);
+ // Read the distro
+ r = pakfire_distro(&pakfire->distro, path);
+ if (r < 0) {
+ switch (-r) {
+ case ENOENT:
+ return 0;
+
+ default:
+ break;
+ }
+ }
+
+ return r;
}
static int pakfire_set_cache_path(struct pakfire* pakfire) {
if (r < 0)
goto ERROR;
+ // Store if we have a path
+ if (path)
+ p->internal_flags |= PAKFIRE_HAS_PATH;
+
// Initialise configuration
r = pakfire_config_create(&p->config);
if (r < 0)
goto ERROR;
- // Read configuration file
- r = pakfire_read_config(p, conf);
+ // Read the configuration file
+ if (conf) {
+ r = pakfire_config_read(p->config, conf);
+ if (r < 0) {
+ CTX_ERROR(p->ctx, "Could not read configuration: %s\n", strerror(-r));
+ goto ERROR;
+ }
+ }
+
+ // Import distro configuration
+ r = pakfire_config_import_distro(p);
if (r < 0)
goto ERROR;
+ // Read /etc/os-release
+ if (p->internal_flags & PAKFIRE_HAS_PATH) {
+ r = pakfire_read_os_release(p);
+ if (r < 0)
+ goto ERROR;
+
+ // Perform some safety checks
+ r = pakfire_safety_checks(p);
+ if (r < 0)
+ goto ERROR;
+ }
+
// Set cache path
r = pakfire_set_cache_path(p);
if (r < 0) {
}
}
- // Store if we have a path
- if (path) {
- p->internal_flags |= PAKFIRE_HAS_PATH;
-
- // Otherwise we create our own temporary path
- } else {
+ // If we don't have a path, create something temporary...
+ if (!path) {
// Template when running Pakfire in a temporary environment
char tmppath[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-root-XXXXXX";
if (r < 0)
goto ERROR;
- // Read /etc/os-release
- r = pakfire_read_os_release(p);
- if (r && errno != ENOENT)
+ // Populate pool
+ r = pakfire_populate_pool(p);
+ if (r < 0)
goto ERROR;
- // Bump RLIMIT_NOFILE to maximum
- r = pakfire_rlimit_set(p, PAKFIRE_RLIMIT_NOFILE_MAX);
- if (r)
+ // Create repositories
+ r = pakfire_repo_import(p, p->config);
+ if (r < 0)
goto ERROR;
+ // Read repository configuration
+ if (p->internal_flags & PAKFIRE_HAS_PATH) {
+ r = pakfire_read_repo_config(p);
+ if (r < 0)
+ goto ERROR;
+ }
+
CTX_DEBUG(p->ctx, "Pakfire initialized at %p\n", p);
CTX_DEBUG(p->ctx, " user = %s (%u)\n", p->user.name, p->user.uid);
CTX_DEBUG(p->ctx, " group = %s (%u)\n", p->group.name, p->group.gid);
if (p->group.subgids.id)
CTX_DEBUG(p->ctx, " subgid = %u (%zu)\n", p->group.subgids.id, p->group.subgids.length);
- // Perform some safety checks
- r = pakfire_safety_checks(p);
- if (r)
- goto ERROR;
-
// Dump distribution configuration
CTX_DEBUG(p->ctx, " Distribution: %s\n", p->distro.pretty_name);
CTX_DEBUG(p->ctx, " name = %s\n", p->distro.name);
goto ERROR;
}
- // Populate pool
- r = pakfire_populate_pool(p);
- if (r < 0)
- goto ERROR;
-
- // Create repositories
- r = pakfire_repo_import(p, p->config);
- if (r < 0)
+ // Bump RLIMIT_NOFILE to maximum
+ r = pakfire_rlimit_set(p, PAKFIRE_RLIMIT_NOFILE_MAX);
+ if (r)
goto ERROR;
// Return the pointer