chiark / gitweb /
update TODO
[elogind.git] / src / shared / install.c
index 24905e1af637b3fef03b5f68b8df25e49e9f22f8..9e870392f232c0c620b429351793ba2c2e5deb28 100644 (file)
 #include "install.h"
 #include "conf-parser.h"
 #include "conf-files.h"
-
-typedef struct {
-        char *name;
-        char *path;
-
-        char **aliases;
-        char **wanted_by;
-        char **required_by;
-} InstallInfo;
+#include "specifier.h"
+#include "install-printf.h"
 
 typedef struct {
         Hashmap *will_install;
@@ -707,7 +700,7 @@ int unit_file_link(
                 UnitFileChange **changes,
                 unsigned *n_changes) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
         char **i;
         char _cleanup_free_ *config_path = NULL;
         int r, q;
@@ -963,6 +956,33 @@ static int config_parse_also(
         return 0;
 }
 
+static int config_parse_user(
+                const char *filename,
+                unsigned line,
+                const char *section,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        InstallInfo *i = data;
+        char* printed;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        printed = install_full_printf(i, rvalue);
+        if (!printed)
+                return -ENOMEM;
+
+        free(i->user);
+        i->user = printed;
+
+        return 0;
+}
+
 static int unit_file_load(
                 InstallContext *c,
                 InstallInfo *info,
@@ -974,6 +994,7 @@ static int unit_file_load(
                 { "Install", "WantedBy",   config_parse_strv, 0, &info->wanted_by   },
                 { "Install", "RequiredBy", config_parse_strv, 0, &info->required_by },
                 { "Install", "Also",       config_parse_also, 0, c                  },
+                { "Exec",    "User",       config_parse_user, 0, info               },
                 { NULL, NULL, NULL, 0, NULL }
         };
 
@@ -1095,7 +1116,7 @@ static int unit_file_can_install(
                 const char *name,
                 bool allow_symlink) {
 
-        InstallContext _cleanup_install_context_done_ c = {NULL};
+        InstallContext _cleanup_install_context_done_ c = {};
         InstallInfo *i;
         int r;
 
@@ -1177,16 +1198,17 @@ static int install_info_symlink_alias(
         assert(config_path);
 
         STRV_FOREACH(s, i->aliases) {
-                char *alias_path;
+                char _cleanup_free_ *alias_path = NULL, *dst = NULL;
 
-                alias_path = path_make_absolute(*s, config_path);
+                dst = install_full_printf(i, *s);
+                if (!dst)
+                        return -ENOMEM;
 
+                alias_path = path_make_absolute(dst, config_path);
                 if (!alias_path)
                         return -ENOMEM;
 
                 q = create_symlink(i->path, alias_path, force, changes, n_changes);
-                free(alias_path);
-
                 if (r == 0)
                         r = q;
         }
@@ -1208,18 +1230,21 @@ static int install_info_symlink_wants(
         assert(config_path);
 
         STRV_FOREACH(s, i->wanted_by) {
-                char *path;
+                char _cleanup_free_ *path = NULL, *dst = NULL;
+
+                dst = install_full_printf(i, *s);
+                if (!dst)
+                        return -ENOMEM;
 
-                if (!unit_name_is_valid(*s, true)) {
+                if (!unit_name_is_valid(dst, true)) {
                         r = -EINVAL;
                         continue;
                 }
 
-                if (asprintf(&path, "%s/%s.wants/%s", config_path, *s, i->name) < 0)
+                if (asprintf(&path, "%s/%s.wants/%s", config_path, dst, i->name) < 0)
                         return -ENOMEM;
 
                 q = create_symlink(i->path, path, force, changes, n_changes);
-                free(path);
 
                 if (r == 0)
                         r = q;
@@ -1242,18 +1267,21 @@ static int install_info_symlink_requires(
         assert(config_path);
 
         STRV_FOREACH(s, i->required_by) {
-                char *path;
+                char _cleanup_free_ *path = NULL, *dst = NULL;
+
+                dst = install_full_printf(i, *s);
+                if (!dst)
+                        return -ENOMEM;
 
-                if (!unit_name_is_valid(*s, true)) {
+                if (!unit_name_is_valid(dst, true)) {
                         r = -EINVAL;
                         continue;
                 }
 
-                if (asprintf(&path, "%s/%s.requires/%s", config_path, *s, i->name) < 0)
+                if (asprintf(&path, "%s/%s.requires/%s", config_path, dst, i->name) < 0)
                         return -ENOMEM;
 
                 q = create_symlink(i->path, path, force, changes, n_changes);
-                free(path);
 
                 if (r == 0)
                         r = q;
@@ -1424,8 +1452,8 @@ int unit_file_enable(
                 UnitFileChange **changes,
                 unsigned *n_changes) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
-        InstallContext _cleanup_install_context_done_ c = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
+        InstallContext _cleanup_install_context_done_ c = {};
         char **i;
         char _cleanup_free_ *config_path = NULL;
         int r;
@@ -1463,8 +1491,8 @@ int unit_file_disable(
                 UnitFileChange **changes,
                 unsigned *n_changes) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
-        InstallContext _cleanup_install_context_done_ c = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
+        InstallContext _cleanup_install_context_done_ c = {};
         char **i;
         char _cleanup_free_ *config_path = NULL;
         Set _cleanup_set_free_free_ *remove_symlinks_to = NULL;
@@ -1505,8 +1533,8 @@ int unit_file_reenable(
                 UnitFileChange **changes,
                 unsigned *n_changes) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
-        InstallContext _cleanup_install_context_done_ c = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
+        InstallContext _cleanup_install_context_done_ c = {};
         char **i;
         char _cleanup_free_ *config_path = NULL;
         Set _cleanup_set_free_free_ *remove_symlinks_to = NULL;
@@ -1548,7 +1576,7 @@ UnitFileState unit_file_get_state(
                 const char *root_dir,
                 const char *name) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
         UnitFileState state = _UNIT_FILE_STATE_INVALID;
         char **i;
         char _cleanup_free_ *path = NULL;
@@ -1630,7 +1658,7 @@ int unit_file_query_preset(UnitFileScope scope, const char *name) {
         assert(name);
 
         if (scope == UNIT_FILE_SYSTEM)
-                r = conf_files_list(&files, ".preset",
+                r = conf_files_list(&files, ".preset", NULL,
                                     "/etc/systemd/system-preset",
                                     "/usr/local/lib/systemd/system-preset",
                                     "/usr/lib/systemd/system-preset",
@@ -1639,7 +1667,7 @@ int unit_file_query_preset(UnitFileScope scope, const char *name) {
 #endif
                                     NULL);
         else if (scope == UNIT_FILE_GLOBAL)
-                r = conf_files_list(&files, ".preset",
+                r = conf_files_list(&files, ".preset", NULL,
                                     "/etc/systemd/user-preset",
                                     "/usr/local/lib/systemd/user-preset",
                                     "/usr/lib/systemd/user-preset",
@@ -1706,8 +1734,8 @@ int unit_file_preset(
                 UnitFileChange **changes,
                 unsigned *n_changes) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
-        InstallContext _cleanup_install_context_done_ plus = {NULL}, minus = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
+        InstallContext _cleanup_install_context_done_ plus = {}, minus = {NULL};
         char **i;
         char _cleanup_free_ *config_path = NULL;
         Set _cleanup_set_free_free_ *remove_symlinks_to = NULL;
@@ -1772,7 +1800,7 @@ int unit_file_get_list(
                 const char *root_dir,
                 Hashmap *h) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
         char **i;
         char _cleanup_free_ *buf = NULL;
         DIR _cleanup_closedir_ *d = NULL;