|
|
8d419f |
From 8fa3444f3ca7add9af40ab565e045c2754e5a855 Mon Sep 17 00:00:00 2001
|
|
|
8d419f |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
8d419f |
Date: Thu, 10 Mar 2022 16:47:51 +0100
|
|
|
8d419f |
Subject: [PATCH] systemctl: fix silent failure when --root is not found
|
|
|
8d419f |
|
|
|
8d419f |
Some calls to lookup_path_init() were not followed by any log emission.
|
|
|
8d419f |
E.g.:
|
|
|
8d419f |
$ SYSTEMD_LOG_LEVEL=debug systemctl --root=/missing enable unit; echo $?
|
|
|
8d419f |
1
|
|
|
8d419f |
|
|
|
8d419f |
Let's add a helper function and use it in various places.
|
|
|
8d419f |
|
|
|
8d419f |
$ SYSTEMD_LOG_LEVEL=debug build/systemctl --root=/missing enable unit; echo $?
|
|
|
8d419f |
Failed to initialize unit search paths for root directory /missing: No such file or directory
|
|
|
8d419f |
1
|
|
|
8d419f |
$ SYSTEMCTL_SKIP_SYSV=1 build/systemctl --root=/missing enable unit; echo $?
|
|
|
8d419f |
Failed to initialize unit search paths for root directory /missing: No such file or directory
|
|
|
8d419f |
Failed to enable: No such file or directory.
|
|
|
8d419f |
1
|
|
|
8d419f |
|
|
|
8d419f |
The repeated error in the second case is not very nice, but this is a niche
|
|
|
8d419f |
case and I don't think it's worth the trouble to trying to avoid it.
|
|
|
8d419f |
|
|
|
8d419f |
(cherry picked from commit 99aad9a2b9e2c06023a2043976fd9395332ff097)
|
|
|
8d419f |
|
|
|
8d419f |
Related: #2082131
|
|
|
8d419f |
---
|
|
|
8d419f |
src/basic/env-file.c | 83 +++++++++------------------
|
|
|
8d419f |
src/basic/path-lookup.c | 56 ++++++++++--------
|
|
|
8d419f |
src/basic/path-lookup.h | 3 +-
|
|
|
8d419f |
src/core/manager.c | 12 ++--
|
|
|
8d419f |
src/shared/condition.c | 3 +-
|
|
|
8d419f |
src/shared/install.c | 2 +-
|
|
|
8d419f |
src/systemctl/systemctl-edit.c | 8 +--
|
|
|
8d419f |
src/systemctl/systemctl-enable.c | 2 +-
|
|
|
8d419f |
src/systemctl/systemctl-sysv-compat.c | 2 +-
|
|
|
8d419f |
src/sysv-generator/sysv-generator.c | 4 +-
|
|
|
8d419f |
src/test/test-fileio.c | 3 +-
|
|
|
8d419f |
src/test/test-os-util.c | 7 +--
|
|
|
8d419f |
12 files changed, 84 insertions(+), 101 deletions(-)
|
|
|
8d419f |
|
|
|
8d419f |
diff --git a/src/basic/env-file.c b/src/basic/env-file.c
|
|
|
8d419f |
index 0353f3f2a0..0e272da083 100644
|
|
|
8d419f |
--- a/src/basic/env-file.c
|
|
|
8d419f |
+++ b/src/basic/env-file.c
|
|
|
8d419f |
@@ -16,9 +16,8 @@ static int parse_env_file_internal(
|
|
|
8d419f |
FILE *f,
|
|
|
8d419f |
const char *fname,
|
|
|
8d419f |
int (*push) (const char *filename, unsigned line,
|
|
|
8d419f |
- const char *key, char *value, void *userdata, int *n_pushed),
|
|
|
8d419f |
- void *userdata,
|
|
|
8d419f |
- int *n_pushed) {
|
|
|
8d419f |
+ const char *key, char *value, void *userdata),
|
|
|
8d419f |
+ void *userdata) {
|
|
|
8d419f |
|
|
|
8d419f |
size_t n_key = 0, n_value = 0, last_value_whitespace = SIZE_MAX, last_key_whitespace = SIZE_MAX;
|
|
|
8d419f |
_cleanup_free_ char *contents = NULL, *key = NULL, *value = NULL;
|
|
|
8d419f |
@@ -100,7 +99,7 @@ static int parse_env_file_internal(
|
|
|
8d419f |
if (last_key_whitespace != SIZE_MAX)
|
|
|
8d419f |
key[last_key_whitespace] = 0;
|
|
|
8d419f |
|
|
|
8d419f |
- r = push(fname, line, key, value, userdata, n_pushed);
|
|
|
8d419f |
+ r = push(fname, line, key, value, userdata);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
@@ -143,7 +142,7 @@ static int parse_env_file_internal(
|
|
|
8d419f |
if (last_key_whitespace != SIZE_MAX)
|
|
|
8d419f |
key[last_key_whitespace] = 0;
|
|
|
8d419f |
|
|
|
8d419f |
- r = push(fname, line, key, value, userdata, n_pushed);
|
|
|
8d419f |
+ r = push(fname, line, key, value, userdata);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
@@ -262,7 +261,7 @@ static int parse_env_file_internal(
|
|
|
8d419f |
if (last_key_whitespace != SIZE_MAX)
|
|
|
8d419f |
key[last_key_whitespace] = 0;
|
|
|
8d419f |
|
|
|
8d419f |
- r = push(fname, line, key, value, userdata, n_pushed);
|
|
|
8d419f |
+ r = push(fname, line, key, value, userdata);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
@@ -300,8 +299,7 @@ static int check_utf8ness_and_warn(
|
|
|
8d419f |
static int parse_env_file_push(
|
|
|
8d419f |
const char *filename, unsigned line,
|
|
|
8d419f |
const char *key, char *value,
|
|
|
8d419f |
- void *userdata,
|
|
|
8d419f |
- int *n_pushed) {
|
|
|
8d419f |
+ void *userdata) {
|
|
|
8d419f |
|
|
|
8d419f |
const char *k;
|
|
|
8d419f |
va_list aq, *ap = userdata;
|
|
|
8d419f |
@@ -323,9 +321,6 @@ static int parse_env_file_push(
|
|
|
8d419f |
free(*v);
|
|
|
8d419f |
*v = value;
|
|
|
8d419f |
|
|
|
8d419f |
- if (n_pushed)
|
|
|
8d419f |
- (*n_pushed)++;
|
|
|
8d419f |
-
|
|
|
8d419f |
return 1;
|
|
|
8d419f |
}
|
|
|
8d419f |
}
|
|
|
8d419f |
@@ -341,16 +336,13 @@ int parse_env_filev(
|
|
|
8d419f |
const char *fname,
|
|
|
8d419f |
va_list ap) {
|
|
|
8d419f |
|
|
|
8d419f |
- int r, n_pushed = 0;
|
|
|
8d419f |
+ int r;
|
|
|
8d419f |
va_list aq;
|
|
|
8d419f |
|
|
|
8d419f |
va_copy(aq, ap);
|
|
|
8d419f |
- r = parse_env_file_internal(f, fname, parse_env_file_push, &aq, &n_pushed);
|
|
|
8d419f |
+ r = parse_env_file_internal(f, fname, parse_env_file_push, &aq;;
|
|
|
8d419f |
va_end(aq);
|
|
|
8d419f |
- if (r < 0)
|
|
|
8d419f |
- return r;
|
|
|
8d419f |
-
|
|
|
8d419f |
- return n_pushed;
|
|
|
8d419f |
+ return r;
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
int parse_env_file_sentinel(
|
|
|
8d419f |
@@ -371,8 +363,7 @@ int parse_env_file_sentinel(
|
|
|
8d419f |
static int load_env_file_push(
|
|
|
8d419f |
const char *filename, unsigned line,
|
|
|
8d419f |
const char *key, char *value,
|
|
|
8d419f |
- void *userdata,
|
|
|
8d419f |
- int *n_pushed) {
|
|
|
8d419f |
+ void *userdata) {
|
|
|
8d419f |
char ***m = userdata;
|
|
|
8d419f |
char *p;
|
|
|
8d419f |
int r;
|
|
|
8d419f |
@@ -389,34 +380,28 @@ static int load_env_file_push(
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
- if (n_pushed)
|
|
|
8d419f |
- (*n_pushed)++;
|
|
|
8d419f |
-
|
|
|
8d419f |
free(value);
|
|
|
8d419f |
return 0;
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
int load_env_file(FILE *f, const char *fname, char ***rl) {
|
|
|
8d419f |
- char **m = NULL;
|
|
|
8d419f |
+ _cleanup_strv_free_ char **m = NULL;
|
|
|
8d419f |
int r;
|
|
|
8d419f |
|
|
|
8d419f |
- r = parse_env_file_internal(f, fname, load_env_file_push, &m, NULL);
|
|
|
8d419f |
- if (r < 0) {
|
|
|
8d419f |
- strv_free(m);
|
|
|
8d419f |
+ r = parse_env_file_internal(f, fname, load_env_file_push, &m);
|
|
|
8d419f |
+ if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
- }
|
|
|
8d419f |
|
|
|
8d419f |
- *rl = m;
|
|
|
8d419f |
+ *rl = TAKE_PTR(m);
|
|
|
8d419f |
return 0;
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
static int load_env_file_push_pairs(
|
|
|
8d419f |
const char *filename, unsigned line,
|
|
|
8d419f |
const char *key, char *value,
|
|
|
8d419f |
- void *userdata,
|
|
|
8d419f |
- int *n_pushed) {
|
|
|
8d419f |
+ void *userdata) {
|
|
|
8d419f |
+
|
|
|
8d419f |
char ***m = ASSERT_PTR(userdata);
|
|
|
8d419f |
- bool added = false;
|
|
|
8d419f |
int r;
|
|
|
8d419f |
|
|
|
8d419f |
r = check_utf8ness_and_warn(filename, line, key, value);
|
|
|
8d419f |
@@ -427,49 +412,37 @@ static int load_env_file_push_pairs(
|
|
|
8d419f |
for (char **t = *m; t && *t; t += 2)
|
|
|
8d419f |
if (streq(t[0], key)) {
|
|
|
8d419f |
if (value)
|
|
|
8d419f |
- r = free_and_replace(t[1], value);
|
|
|
8d419f |
+ return free_and_replace(t[1], value);
|
|
|
8d419f |
else
|
|
|
8d419f |
- r = free_and_strdup(t+1, "");
|
|
|
8d419f |
- goto finish;
|
|
|
8d419f |
+ return free_and_strdup(t+1, "");
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
r = strv_extend(m, key);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
- return -ENOMEM;
|
|
|
8d419f |
+ return r;
|
|
|
8d419f |
|
|
|
8d419f |
if (value)
|
|
|
8d419f |
- r = strv_push(m, value);
|
|
|
8d419f |
+ return strv_push(m, value);
|
|
|
8d419f |
else
|
|
|
8d419f |
- r = strv_extend(m, "");
|
|
|
8d419f |
- added = true;
|
|
|
8d419f |
- finish:
|
|
|
8d419f |
- if (r < 0)
|
|
|
8d419f |
- return r;
|
|
|
8d419f |
-
|
|
|
8d419f |
- if (n_pushed && added)
|
|
|
8d419f |
- (*n_pushed)++;
|
|
|
8d419f |
- return 0;
|
|
|
8d419f |
+ return strv_extend(m, "");
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
int load_env_file_pairs(FILE *f, const char *fname, char ***rl) {
|
|
|
8d419f |
- char **m = NULL;
|
|
|
8d419f |
+ _cleanup_strv_free_ char **m = NULL;
|
|
|
8d419f |
int r;
|
|
|
8d419f |
|
|
|
8d419f |
- r = parse_env_file_internal(f, fname, load_env_file_push_pairs, &m, NULL);
|
|
|
8d419f |
- if (r < 0) {
|
|
|
8d419f |
- strv_free(m);
|
|
|
8d419f |
+ r = parse_env_file_internal(f, fname, load_env_file_push_pairs, &m);
|
|
|
8d419f |
+ if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
- }
|
|
|
8d419f |
|
|
|
8d419f |
- *rl = m;
|
|
|
8d419f |
+ *rl = TAKE_PTR(m);
|
|
|
8d419f |
return 0;
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
static int merge_env_file_push(
|
|
|
8d419f |
const char *filename, unsigned line,
|
|
|
8d419f |
const char *key, char *value,
|
|
|
8d419f |
- void *userdata,
|
|
|
8d419f |
- int *n_pushed) {
|
|
|
8d419f |
+ void *userdata) {
|
|
|
8d419f |
|
|
|
8d419f |
char ***env = userdata;
|
|
|
8d419f |
char *expanded_value;
|
|
|
8d419f |
@@ -498,7 +471,7 @@ static int merge_env_file_push(
|
|
|
8d419f |
|
|
|
8d419f |
log_debug("%s:%u: setting %s=%s", filename, line, key, value);
|
|
|
8d419f |
|
|
|
8d419f |
- return load_env_file_push(filename, line, key, value, env, n_pushed);
|
|
|
8d419f |
+ return load_env_file_push(filename, line, key, value, env);
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
int merge_env_file(
|
|
|
8d419f |
@@ -510,7 +483,7 @@ int merge_env_file(
|
|
|
8d419f |
* plus "extended" substitutions, unlike other exported parsing functions.
|
|
|
8d419f |
*/
|
|
|
8d419f |
|
|
|
8d419f |
- return parse_env_file_internal(f, fname, merge_env_file_push, env, NULL);
|
|
|
8d419f |
+ return parse_env_file_internal(f, fname, merge_env_file_push, env);
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
static void write_env_var(FILE *f, const char *v) {
|
|
|
8d419f |
diff --git a/src/basic/path-lookup.c b/src/basic/path-lookup.c
|
|
|
8d419f |
index 921a30cef7..ab51955e34 100644
|
|
|
8d419f |
--- a/src/basic/path-lookup.c
|
|
|
8d419f |
+++ b/src/basic/path-lookup.c
|
|
|
8d419f |
@@ -509,7 +509,7 @@ static int get_paths_from_environ(const char *var, char ***paths, bool *append)
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
int lookup_paths_init(
|
|
|
8d419f |
- LookupPaths *p,
|
|
|
8d419f |
+ LookupPaths *lp,
|
|
|
8d419f |
UnitFileScope scope,
|
|
|
8d419f |
LookupPathsFlags flags,
|
|
|
8d419f |
const char *root_dir) {
|
|
|
8d419f |
@@ -527,7 +527,7 @@ int lookup_paths_init(
|
|
|
8d419f |
_cleanup_strv_free_ char **paths = NULL;
|
|
|
8d419f |
int r;
|
|
|
8d419f |
|
|
|
8d419f |
- assert(p);
|
|
|
8d419f |
+ assert(lp);
|
|
|
8d419f |
assert(scope >= 0);
|
|
|
8d419f |
assert(scope < _UNIT_FILE_SCOPE_MAX);
|
|
|
8d419f |
|
|
|
8d419f |
@@ -717,7 +717,7 @@ int lookup_paths_init(
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return -ENOMEM;
|
|
|
8d419f |
|
|
|
8d419f |
- *p = (LookupPaths) {
|
|
|
8d419f |
+ *lp = (LookupPaths) {
|
|
|
8d419f |
.search_path = strv_uniq(TAKE_PTR(paths)),
|
|
|
8d419f |
|
|
|
8d419f |
.persistent_config = TAKE_PTR(persistent_config),
|
|
|
8d419f |
@@ -742,41 +742,51 @@ int lookup_paths_init(
|
|
|
8d419f |
return 0;
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
-void lookup_paths_free(LookupPaths *p) {
|
|
|
8d419f |
- if (!p)
|
|
|
8d419f |
+int lookup_paths_init_or_warn(LookupPaths *lp, UnitFileScope scope, LookupPathsFlags flags, const char *root_dir) {
|
|
|
8d419f |
+ int r;
|
|
|
8d419f |
+
|
|
|
8d419f |
+ r = lookup_paths_init(lp, scope, flags, root_dir);
|
|
|
8d419f |
+ if (r < 0)
|
|
|
8d419f |
+ return log_error_errno(r, "Failed to initialize unit search paths%s%s: %m",
|
|
|
8d419f |
+ isempty(root_dir) ? "" : " for root directory ", strempty(root_dir));
|
|
|
8d419f |
+ return r;
|
|
|
8d419f |
+}
|
|
|
8d419f |
+
|
|
|
8d419f |
+void lookup_paths_free(LookupPaths *lp) {
|
|
|
8d419f |
+ if (!lp)
|
|
|
8d419f |
return;
|
|
|
8d419f |
|
|
|
8d419f |
- p->search_path = strv_free(p->search_path);
|
|
|
8d419f |
+ lp->search_path = strv_free(lp->search_path);
|
|
|
8d419f |
|
|
|
8d419f |
- p->persistent_config = mfree(p->persistent_config);
|
|
|
8d419f |
- p->runtime_config = mfree(p->runtime_config);
|
|
|
8d419f |
+ lp->persistent_config = mfree(lp->persistent_config);
|
|
|
8d419f |
+ lp->runtime_config = mfree(lp->runtime_config);
|
|
|
8d419f |
|
|
|
8d419f |
- p->persistent_attached = mfree(p->persistent_attached);
|
|
|
8d419f |
- p->runtime_attached = mfree(p->runtime_attached);
|
|
|
8d419f |
+ lp->persistent_attached = mfree(lp->persistent_attached);
|
|
|
8d419f |
+ lp->runtime_attached = mfree(lp->runtime_attached);
|
|
|
8d419f |
|
|
|
8d419f |
- p->generator = mfree(p->generator);
|
|
|
8d419f |
- p->generator_early = mfree(p->generator_early);
|
|
|
8d419f |
- p->generator_late = mfree(p->generator_late);
|
|
|
8d419f |
+ lp->generator = mfree(lp->generator);
|
|
|
8d419f |
+ lp->generator_early = mfree(lp->generator_early);
|
|
|
8d419f |
+ lp->generator_late = mfree(lp->generator_late);
|
|
|
8d419f |
|
|
|
8d419f |
- p->transient = mfree(p->transient);
|
|
|
8d419f |
+ lp->transient = mfree(lp->transient);
|
|
|
8d419f |
|
|
|
8d419f |
- p->persistent_control = mfree(p->persistent_control);
|
|
|
8d419f |
- p->runtime_control = mfree(p->runtime_control);
|
|
|
8d419f |
+ lp->persistent_control = mfree(lp->persistent_control);
|
|
|
8d419f |
+ lp->runtime_control = mfree(lp->runtime_control);
|
|
|
8d419f |
|
|
|
8d419f |
- p->root_dir = mfree(p->root_dir);
|
|
|
8d419f |
- p->temporary_dir = mfree(p->temporary_dir);
|
|
|
8d419f |
+ lp->root_dir = mfree(lp->root_dir);
|
|
|
8d419f |
+ lp->temporary_dir = mfree(lp->temporary_dir);
|
|
|
8d419f |
}
|
|
|
8d419f |
|
|
|
8d419f |
-void lookup_paths_log(LookupPaths *p) {
|
|
|
8d419f |
- assert(p);
|
|
|
8d419f |
+void lookup_paths_log(LookupPaths *lp) {
|
|
|
8d419f |
+ assert(lp);
|
|
|
8d419f |
|
|
|
8d419f |
- if (strv_isempty(p->search_path)) {
|
|
|
8d419f |
+ if (strv_isempty(lp->search_path)) {
|
|
|
8d419f |
log_debug("Ignoring unit files.");
|
|
|
8d419f |
- p->search_path = strv_free(p->search_path);
|
|
|
8d419f |
+ lp->search_path = strv_free(lp->search_path);
|
|
|
8d419f |
} else {
|
|
|
8d419f |
_cleanup_free_ char *t = NULL;
|
|
|
8d419f |
|
|
|
8d419f |
- t = strv_join(p->search_path, "\n\t");
|
|
|
8d419f |
+ t = strv_join(lp->search_path, "\n\t");
|
|
|
8d419f |
log_debug("Looking for unit files in (higher priority first):\n\t%s", strna(t));
|
|
|
8d419f |
}
|
|
|
8d419f |
}
|
|
|
8d419f |
diff --git a/src/basic/path-lookup.h b/src/basic/path-lookup.h
|
|
|
8d419f |
index af85dc7b4f..1f0e5ea271 100644
|
|
|
8d419f |
--- a/src/basic/path-lookup.h
|
|
|
8d419f |
+++ b/src/basic/path-lookup.h
|
|
|
8d419f |
@@ -54,7 +54,8 @@ struct LookupPaths {
|
|
|
8d419f |
char *temporary_dir;
|
|
|
8d419f |
};
|
|
|
8d419f |
|
|
|
8d419f |
-int lookup_paths_init(LookupPaths *p, UnitFileScope scope, LookupPathsFlags flags, const char *root_dir);
|
|
|
8d419f |
+int lookup_paths_init(LookupPaths *lp, UnitFileScope scope, LookupPathsFlags flags, const char *root_dir);
|
|
|
8d419f |
+int lookup_paths_init_or_warn(LookupPaths *lp, UnitFileScope scope, LookupPathsFlags flags, const char *root_dir);
|
|
|
8d419f |
|
|
|
8d419f |
int xdg_user_dirs(char ***ret_config_dirs, char ***ret_data_dirs);
|
|
|
8d419f |
int xdg_user_runtime_dir(char **ret, const char *suffix);
|
|
|
8d419f |
diff --git a/src/core/manager.c b/src/core/manager.c
|
|
|
8d419f |
index 12c49e7fca..22bd0866c5 100644
|
|
|
8d419f |
--- a/src/core/manager.c
|
|
|
8d419f |
+++ b/src/core/manager.c
|
|
|
8d419f |
@@ -1756,11 +1756,11 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds, const char *roo
|
|
|
8d419f |
|
|
|
8d419f |
/* If we are running in test mode, we still want to run the generators,
|
|
|
8d419f |
* but we should not touch the real generator directories. */
|
|
|
8d419f |
- r = lookup_paths_init(&m->lookup_paths, m->unit_file_scope,
|
|
|
8d419f |
- MANAGER_IS_TEST_RUN(m) ? LOOKUP_PATHS_TEMPORARY_GENERATED : 0,
|
|
|
8d419f |
- root);
|
|
|
8d419f |
+ r = lookup_paths_init_or_warn(&m->lookup_paths, m->unit_file_scope,
|
|
|
8d419f |
+ MANAGER_IS_TEST_RUN(m) ? LOOKUP_PATHS_TEMPORARY_GENERATED : 0,
|
|
|
8d419f |
+ root);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
- return log_error_errno(r, "Failed to initialize path lookup table: %m");
|
|
|
8d419f |
+ return r;
|
|
|
8d419f |
|
|
|
8d419f |
dual_timestamp_get(m->timestamps + manager_timestamp_initrd_mangle(MANAGER_TIMESTAMP_GENERATORS_START));
|
|
|
8d419f |
r = manager_run_environment_generators(m);
|
|
|
8d419f |
@@ -3302,9 +3302,9 @@ int manager_reload(Manager *m) {
|
|
|
8d419f |
m->uid_refs = hashmap_free(m->uid_refs);
|
|
|
8d419f |
m->gid_refs = hashmap_free(m->gid_refs);
|
|
|
8d419f |
|
|
|
8d419f |
- r = lookup_paths_init(&m->lookup_paths, m->unit_file_scope, 0, NULL);
|
|
|
8d419f |
+ r = lookup_paths_init_or_warn(&m->lookup_paths, m->unit_file_scope, 0, NULL);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
- log_warning_errno(r, "Failed to initialize path lookup table, ignoring: %m");
|
|
|
8d419f |
+ return r;
|
|
|
8d419f |
|
|
|
8d419f |
(void) manager_run_environment_generators(m);
|
|
|
8d419f |
(void) manager_run_generators(m);
|
|
|
8d419f |
diff --git a/src/shared/condition.c b/src/shared/condition.c
|
|
|
8d419f |
index 68fbbf643a..21f3714eba 100644
|
|
|
8d419f |
--- a/src/shared/condition.c
|
|
|
8d419f |
+++ b/src/shared/condition.c
|
|
|
8d419f |
@@ -787,7 +787,8 @@ static int condition_test_needs_update(Condition *c, char **env) {
|
|
|
8d419f |
if (r < 0) {
|
|
|
8d419f |
log_debug_errno(r, "Failed to parse timestamp file '%s', using mtime: %m", p);
|
|
|
8d419f |
return true;
|
|
|
8d419f |
- } else if (r == 0) {
|
|
|
8d419f |
+ }
|
|
|
8d419f |
+ if (isempty(timestamp_str)) {
|
|
|
8d419f |
log_debug("No data in timestamp file '%s', using mtime.", p);
|
|
|
8d419f |
return true;
|
|
|
8d419f |
}
|
|
|
8d419f |
diff --git a/src/shared/install.c b/src/shared/install.c
|
|
|
8d419f |
index a541d32fb7..f1a8b7eb9b 100644
|
|
|
8d419f |
--- a/src/shared/install.c
|
|
|
8d419f |
+++ b/src/shared/install.c
|
|
|
8d419f |
@@ -2615,7 +2615,7 @@ int unit_file_enable(
|
|
|
8d419f |
assert(scope >= 0);
|
|
|
8d419f |
assert(scope < _UNIT_FILE_SCOPE_MAX);
|
|
|
8d419f |
|
|
|
8d419f |
- r = lookup_paths_init(&lp, scope, 0, root_dir);
|
|
|
8d419f |
+ r = lookup_paths_init_or_warn(&lp, scope, 0, root_dir);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c
|
|
|
8d419f |
index a97aa7be4c..92abd15636 100644
|
|
|
8d419f |
--- a/src/systemctl/systemctl-edit.c
|
|
|
8d419f |
+++ b/src/systemctl/systemctl-edit.c
|
|
|
8d419f |
@@ -38,9 +38,9 @@ int cat(int argc, char *argv[], void *userdata) {
|
|
|
8d419f |
if (arg_transport != BUS_TRANSPORT_LOCAL)
|
|
|
8d419f |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Cannot remotely cat units.");
|
|
|
8d419f |
|
|
|
8d419f |
- r = lookup_paths_init(&lp, arg_scope, 0, arg_root);
|
|
|
8d419f |
+ r = lookup_paths_init_or_warn(&lp, arg_scope, 0, arg_root);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
- return log_error_errno(r, "Failed to determine unit paths: %m");
|
|
|
8d419f |
+ return r;
|
|
|
8d419f |
|
|
|
8d419f |
r = acquire_bus(BUS_MANAGER, &bus;;
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
@@ -511,9 +511,9 @@ int edit(int argc, char *argv[], void *userdata) {
|
|
|
8d419f |
if (arg_transport != BUS_TRANSPORT_LOCAL)
|
|
|
8d419f |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Cannot edit units remotely.");
|
|
|
8d419f |
|
|
|
8d419f |
- r = lookup_paths_init(&lp, arg_scope, 0, arg_root);
|
|
|
8d419f |
+ r = lookup_paths_init_or_warn(&lp, arg_scope, 0, arg_root);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
- return log_error_errno(r, "Failed to determine unit paths: %m");
|
|
|
8d419f |
+ return r;
|
|
|
8d419f |
|
|
|
8d419f |
r = mac_selinux_init();
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
diff --git a/src/systemctl/systemctl-enable.c b/src/systemctl/systemctl-enable.c
|
|
|
8d419f |
index dcbe2c7302..7860f3dc6c 100644
|
|
|
8d419f |
--- a/src/systemctl/systemctl-enable.c
|
|
|
8d419f |
+++ b/src/systemctl/systemctl-enable.c
|
|
|
8d419f |
@@ -142,7 +142,7 @@ int enable_unit(int argc, char *argv[], void *userdata) {
|
|
|
8d419f |
char **name;
|
|
|
8d419f |
_cleanup_(lookup_paths_free) LookupPaths lp = {};
|
|
|
8d419f |
|
|
|
8d419f |
- r = lookup_paths_init(&lp, arg_scope, 0, arg_root);
|
|
|
8d419f |
+ r = lookup_paths_init_or_warn(&lp, arg_scope, 0, arg_root);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
diff --git a/src/systemctl/systemctl-sysv-compat.c b/src/systemctl/systemctl-sysv-compat.c
|
|
|
8d419f |
index 017dba2034..c6e8defd1b 100644
|
|
|
8d419f |
--- a/src/systemctl/systemctl-sysv-compat.c
|
|
|
8d419f |
+++ b/src/systemctl/systemctl-sysv-compat.c
|
|
|
8d419f |
@@ -128,7 +128,7 @@ int enable_sysv_units(const char *verb, char **args) {
|
|
|
8d419f |
"is-enabled"))
|
|
|
8d419f |
return 0;
|
|
|
8d419f |
|
|
|
8d419f |
- r = lookup_paths_init(&paths, arg_scope, LOOKUP_PATHS_EXCLUDE_GENERATED, arg_root);
|
|
|
8d419f |
+ r = lookup_paths_init_or_warn(&paths, arg_scope, LOOKUP_PATHS_EXCLUDE_GENERATED, arg_root);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
return r;
|
|
|
8d419f |
|
|
|
8d419f |
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
|
|
|
8d419f |
index e9976540b5..bb74b486be 100644
|
|
|
8d419f |
--- a/src/sysv-generator/sysv-generator.c
|
|
|
8d419f |
+++ b/src/sysv-generator/sysv-generator.c
|
|
|
8d419f |
@@ -894,9 +894,9 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
|
|
|
8d419f |
|
|
|
8d419f |
assert_se(arg_dest = dest_late);
|
|
|
8d419f |
|
|
|
8d419f |
- r = lookup_paths_init(&lp, UNIT_FILE_SYSTEM, LOOKUP_PATHS_EXCLUDE_GENERATED, NULL);
|
|
|
8d419f |
+ r = lookup_paths_init_or_warn(&lp, UNIT_FILE_SYSTEM, LOOKUP_PATHS_EXCLUDE_GENERATED, NULL);
|
|
|
8d419f |
if (r < 0)
|
|
|
8d419f |
- return log_error_errno(r, "Failed to find lookup paths: %m");
|
|
|
8d419f |
+ return r;
|
|
|
8d419f |
|
|
|
8d419f |
all_services = hashmap_new(&string_hash_ops);
|
|
|
8d419f |
if (!all_services)
|
|
|
8d419f |
diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c
|
|
|
8d419f |
index 4f91d94709..238ae8f586 100644
|
|
|
8d419f |
--- a/src/test/test-fileio.c
|
|
|
8d419f |
+++ b/src/test/test-fileio.c
|
|
|
8d419f |
@@ -110,8 +110,7 @@ TEST(parse_env_file) {
|
|
|
8d419f |
"eleven", &eleven,
|
|
|
8d419f |
"twelve", &twelve,
|
|
|
8d419f |
"thirteen", &thirteen);
|
|
|
8d419f |
-
|
|
|
8d419f |
- assert_se(r >= 0);
|
|
|
8d419f |
+ assert_se(r == 0);
|
|
|
8d419f |
|
|
|
8d419f |
log_info("one=[%s]", strna(one));
|
|
|
8d419f |
log_info("two=[%s]", strna(two));
|
|
|
8d419f |
diff --git a/src/test/test-os-util.c b/src/test/test-os-util.c
|
|
|
8d419f |
index d6336c53e9..2cee6470c4 100644
|
|
|
8d419f |
--- a/src/test/test-os-util.c
|
|
|
8d419f |
+++ b/src/test/test-os-util.c
|
|
|
8d419f |
@@ -18,7 +18,7 @@ TEST(path_is_os_tree) {
|
|
|
8d419f |
TEST(parse_os_release) {
|
|
|
8d419f |
/* Let's assume that we're running in a valid system, so os-release is available */
|
|
|
8d419f |
_cleanup_free_ char *id = NULL, *id2 = NULL, *name = NULL, *foobar = NULL;
|
|
|
8d419f |
- assert_se(parse_os_release(NULL, "ID", &id) == 1);
|
|
|
8d419f |
+ assert_se(parse_os_release(NULL, "ID", &id) == 0);
|
|
|
8d419f |
log_info("ID: %s", id);
|
|
|
8d419f |
|
|
|
8d419f |
assert_se(setenv("SYSTEMD_OS_RELEASE", "/dev/null", 1) == 0);
|
|
|
8d419f |
@@ -31,7 +31,7 @@ TEST(parse_os_release) {
|
|
|
8d419f |
"NAME=the-name") == 0);
|
|
|
8d419f |
|
|
|
8d419f |
assert_se(setenv("SYSTEMD_OS_RELEASE", tmpfile, 1) == 0);
|
|
|
8d419f |
- assert_se(parse_os_release(NULL, "ID", &id, "NAME", &name) == 2);
|
|
|
8d419f |
+ assert_se(parse_os_release(NULL, "ID", &id, "NAME", &name) == 0);
|
|
|
8d419f |
log_info("ID: %s NAME: %s", id, name);
|
|
|
8d419f |
assert_se(streq(id, "the-id"));
|
|
|
8d419f |
assert_se(streq(name, "the-name"));
|
|
|
8d419f |
@@ -43,8 +43,7 @@ TEST(parse_os_release) {
|
|
|
8d419f |
"NAME='the-name'") == 0);
|
|
|
8d419f |
|
|
|
8d419f |
assert_se(setenv("SYSTEMD_OS_RELEASE", tmpfile2, 1) == 0);
|
|
|
8d419f |
- // FIXME: we return 3, which means that the return value is useless in face of repeats
|
|
|
8d419f |
- assert_se(parse_os_release(NULL, "ID", &id, "NAME", &name) == 3);
|
|
|
8d419f |
+ assert_se(parse_os_release(NULL, "ID", &id, "NAME", &name) == 0);
|
|
|
8d419f |
log_info("ID: %s NAME: %s", id, name);
|
|
|
8d419f |
assert_se(streq(id, "the-id"));
|
|
|
8d419f |
assert_se(streq(name, "the-name"));
|