chiark / gitweb /
systemd: do not remove empty paths from unit lookup path
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Feb 2013 03:49:19 +0000 (22:49 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Feb 2013 04:16:16 +0000 (23:16 -0500)
The ability to start a new unit with 'systemctl start ...' should not
depend on whether there are other units in the directory. Previously,
an additional 'systemctl daemon-reload' would be necessary to tell
systemd to update the list of unit lookup paths.

src/core/manager.c
src/shared/path-lookup.c
src/shared/path-util.c

index b538a9a3ae92007687eff628e135ae85d86be5bb..25aa1be12fa906b743dcfd4881e6aa2131bead7e 100644 (file)
@@ -621,14 +621,15 @@ int manager_coldplug(Manager *m) {
 
 static void manager_build_unit_path_cache(Manager *m) {
         char **i;
-        DIR *d = NULL;
+        DIR _cleanup_free_ *d = NULL;
         int r;
 
         assert(m);
 
         set_free_free(m->unit_path_cache);
 
-        if (!(m->unit_path_cache = set_new(string_hash_func, string_compare_func))) {
+        m->unit_path_cache = set_new(string_hash_func, string_compare_func);
+        if (!m->unit_path_cache) {
                 log_error("Failed to allocate unit path cache.");
                 return;
         }
@@ -641,7 +642,8 @@ static void manager_build_unit_path_cache(Manager *m) {
 
                 d = opendir(*i);
                 if (!d) {
-                        log_error("Failed to open directory: %m");
+                        if (errno != ENOENT)
+                                log_error("Failed to open directory %s: %m", *i);
                         continue;
                 }
 
@@ -657,7 +659,8 @@ static void manager_build_unit_path_cache(Manager *m) {
                                 goto fail;
                         }
 
-                        if ((r = set_put(m->unit_path_cache, p)) < 0) {
+                        r = set_put(m->unit_path_cache, p);
+                        if (r < 0) {
                                 free(p);
                                 goto fail;
                         }
@@ -674,9 +677,6 @@ fail:
 
         set_free_free(m->unit_path_cache);
         m->unit_path_cache = NULL;
-
-        if (d)
-                closedir(d);
 }
 
 int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
index 6e5529e0c729861db3aa6974ba28a629e1062796..8ee9ddc9c6e65662560481a28a927f6207e2eb98 100644 (file)
@@ -316,7 +316,6 @@ int lookup_paths_init(
                 return -ENOMEM;
 
         strv_uniq(p->unit_path);
-        path_strv_remove_empty(p->unit_path);
 
         if (!strv_isempty(p->unit_path)) {
 
@@ -379,8 +378,6 @@ int lookup_paths_init(
 
                 strv_uniq(p->sysvinit_path);
                 strv_uniq(p->sysvrcnd_path);
-                path_strv_remove_empty(p->sysvinit_path);
-                path_strv_remove_empty(p->sysvrcnd_path);
 
                 if (!strv_isempty(p->sysvinit_path)) {
 
index dd12d3d63409654fb446028ba92a0860bc83e4c1..4857971b33002f29b496f6292a380d742c069b28 100644 (file)
@@ -190,13 +190,17 @@ char **path_strv_canonicalize(char **l) {
 
                 errno = 0;
                 u = canonicalize_file_name(t);
-                free(t);
 
                 if (!u) {
-                        if (errno == ENOMEM || !errno)
-                                enomem = true;
-
-                        continue;
+                        if (errno == ENOENT)
+                                u = t;
+                        else {
+                                free(t);
+                                if (errno == ENOMEM || !errno)
+                                        enomem = true;
+
+                                continue;
+                        }
                 }
 
                 l[k++] = u;