chiark / gitweb /
systemctl: fail in the case that no unit files were found
authorLukas Nykryn <lnykryn@redhat.com>
Tue, 19 Aug 2014 18:53:29 +0000 (20:53 +0200)
committerLukas Nykryn <lnykryn@redhat.com>
Wed, 20 Aug 2014 08:45:18 +0000 (10:45 +0200)
Previously systemctl died with message

-bash-4.2# systemctl --root /rawhi list-unit-files
(src/systemctl/systemctl.c:868) Out of memory.

in the case that no unit files were found in the --root
or the directory did not exist.

So lets return ENOENT in the case that --root does not exist
and empty list in the case that there are no unit files.

src/shared/install.c
src/systemctl/systemctl.c

index 0fe1371129c59a9d169b1a06b4aa0221c9a8f198..03c7a9da2eb08e91031f51085f77a4a759bf1b7b 100644 (file)
@@ -2044,6 +2044,12 @@ int unit_file_get_list(
         if (root_dir && scope != UNIT_FILE_SYSTEM)
                 return -EINVAL;
 
         if (root_dir && scope != UNIT_FILE_SYSTEM)
                 return -EINVAL;
 
+        if (root_dir) {
+                r = access(root_dir, F_OK);
+                if (r < 0)
+                        return -errno;
+        }
+
         r = lookup_paths_init_from_scope(&paths, scope, root_dir);
         if (r < 0)
                 return r;
         r = lookup_paths_init_from_scope(&paths, scope, root_dir);
         if (r < 0)
                 return r;
index 36db652316a0120b41281d2dfc0785491003a83b..072f615ad547f18c152f45ec29d8a32a9460c8c4 100644 (file)
@@ -1350,6 +1350,10 @@ static int list_unit_files(sd_bus *bus, char **args) {
                 }
 
                 n_units = hashmap_size(h);
                 }
 
                 n_units = hashmap_size(h);
+
+                if (n_units == 0)
+                        return 0;
+
                 units = new(UnitFileList, n_units);
                 if (!units) {
                         unit_file_list_free(h);
                 units = new(UnitFileList, n_units);
                 if (!units) {
                         unit_file_list_free(h);