|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From fdbdf6ec29bda40763d7d3e7bb2a63e2f5d60c4c Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From: Lukas Nykryn <lnykryn@redhat.com>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Date: Tue, 19 Aug 2014 20:53:29 +0200
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Subject: [PATCH] systemctl: fail in the case that no unit files were found
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Previously systemctl died with message
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-bash-4.2# systemctl --root /rawhi list-unit-files
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
(src/systemctl/systemctl.c:868) Out of memory.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
in the case that no unit files were found in the --root
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
or the directory did not exist.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
So lets return ENOENT in the case that --root does not exist
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
and empty list in the case that there are no unit files.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/shared/install.c | 6 ++++++
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/systemctl/systemctl.c | 4 ++++
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
2 files changed, 10 insertions(+)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/shared/install.c b/src/shared/install.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 0fe1371129..03c7a9da2e 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/shared/install.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/shared/install.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -2044,6 +2044,12 @@ int unit_file_get_list(
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (root_dir && scope != UNIT_FILE_SYSTEM)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return -EINVAL;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (root_dir) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ r = access(root_dir, F_OK);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return -errno;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
r = lookup_paths_init_from_scope(&paths, scope, root_dir);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 36db652316..072f615ad5 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/systemctl/systemctl.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/systemctl/systemctl.c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -1350,6 +1350,10 @@ static int list_unit_files(sd_bus *bus, char **args) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
n_units = hashmap_size(h);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ if (n_units == 0)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
units = new(UnitFileList, n_units);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
if (!units) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
unit_file_list_free(h);
|