chiark / gitweb /
Allow 'list-unit-files' to run with --root.
[elogind.git] / src / install.c
index 9f415edc2e95d53fdf6853452f06ff334b406c45..1fb1f9d5800e7fc3ccad1b6c222be0058bfdbd18 100644 (file)
@@ -72,9 +72,8 @@ static int get_config_path(UnitFileScope scope, bool runtime, const char *root_d
         case UNIT_FILE_SYSTEM:
 
                 if (root_dir && runtime)
-                        return -EINVAL;
-
-                if (runtime)
+                        asprintf(&p, "%s/run/systemd/system", root_dir);
+                else if (runtime)
                         p = strdup("/run/systemd/system");
                 else if (root_dir)
                         asprintf(&p, "%s/%s", root_dir, SYSTEM_CONFIG_UNIT_PATH);
@@ -126,8 +125,6 @@ static int add_file_change(
         UnitFileChange *c;
         unsigned i;
 
-        assert(type >= 0);
-        assert(type < _UNIT_FILE_CHANGE_TYPE_MAX);
         assert(path);
         assert(!changes == !n_changes);
 
@@ -481,7 +478,6 @@ static int find_symlinks_fd(
                                 t = path_make_absolute(name, config_path);
                                 if (!t) {
                                         free(p);
-                                        free(dest);
                                         r = -ENOMEM;
                                         break;
                                 }
@@ -1021,11 +1017,11 @@ static int unit_file_load(
                 const char *path,
                 bool allow_symlink) {
 
-        const ConfigItem items[] = {
-                { "Alias",    config_parse_strv, 0, &info->aliases,   "Install" },
-                { "WantedBy", config_parse_strv, 0, &info->wanted_by, "Install" },
-                { "Also",     config_parse_also, 0, c,                "Install" },
-                { NULL, NULL, 0, NULL, NULL }
+        const ConfigTableItem items[] = {
+                { "Install", "Alias",    config_parse_strv, 0, &info->aliases   },
+                { "Install", "WantedBy", config_parse_strv, 0, &info->wanted_by },
+                { "Install", "Also",     config_parse_also, 0, c                },
+                { NULL, NULL, NULL, 0, NULL }
         };
 
         int fd;
@@ -1046,7 +1042,7 @@ static int unit_file_load(
                 return -ENOMEM;
         }
 
-        r = config_parse(path, f, NULL, items, true, info);
+        r = config_parse(path, f, NULL, config_item_table_lookup, (void*) items, true, info);
         fclose(f);
         if (r < 0)
                 return r;
@@ -1414,6 +1410,10 @@ int unit_file_enable(
                         goto finish;
         }
 
+        /* This will return the number of symlink rules that were
+        supposed to be created, not the ones actually created. This is
+        useful to determine whether the passed files hat any
+        installation data at all. */
         r = install_context_apply(&c, &paths, config_path, root_dir, force, changes, n_changes);
 
 finish:
@@ -1514,6 +1514,7 @@ int unit_file_reenable(
 
         r = remove_marked_symlinks(remove_symlinks_to, config_path, changes, n_changes);
 
+        /* Returns number of symlinks that where supposed to be installed. */
         q = install_context_apply(&c, &paths, config_path, root_dir, force, changes, n_changes);
         if (r == 0)
                 r = q;
@@ -1763,6 +1764,7 @@ int unit_file_preset(
         if (r == 0)
                 r = q;
 
+        /* Returns number of symlinks that where supposed to be installed. */
         q = install_context_apply(&plus, &paths, config_path, root_dir, force, changes, n_changes);
         if (r == 0)
                 r = q;
@@ -1874,7 +1876,7 @@ int unit_file_get_list(
                         }
 
                         r = null_or_empty_path(f->path);
-                        if (r < 0) {
+                        if (r < 0 && r != -ENOENT) {
                                 free(f->path);
                                 free(f);
                                 goto finish;
@@ -1901,7 +1903,7 @@ int unit_file_get_list(
                         } else if (r > 0) {
                                 f->state = UNIT_FILE_DISABLED;
                                 goto found;
-                        } else if (r == 0) {
+                        } else {
                                 f->state = UNIT_FILE_STATIC;
                                 goto found;
                         }
@@ -1942,3 +1944,10 @@ static const char* const unit_file_state_table[_UNIT_FILE_STATE_MAX] = {
 };
 
 DEFINE_STRING_TABLE_LOOKUP(unit_file_state, UnitFileState);
+
+static const char* const unit_file_change_type_table[_UNIT_FILE_CHANGE_TYPE_MAX] = {
+        [UNIT_FILE_SYMLINK] = "symlink",
+        [UNIT_FILE_UNLINK] = "unlink",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(unit_file_change_type, UnitFileChangeType);