[systemd-devel] [PATCH v2] environment: append unit_id to error messages regarding EnvironmentFile

Lukas Nykryn lnykryn at redhat.com
Fri Oct 17 02:46:01 PDT 2014


---

I have swapped parameters in test-fileio in previous version
 src/core/execute.c     | 6 +++---
 src/core/execute.h     | 2 +-
 src/shared/env-util.c  | 7 ++++---
 src/shared/env-util.h  | 2 +-
 src/test/test-fileio.c | 2 +-
 5 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/core/execute.c b/src/core/execute.c
index b165b33..f515934 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -1782,7 +1782,7 @@ int exec_spawn(ExecCommand *command,
                 n_fds = params->n_fds;
         }
 
-        err = exec_context_load_environment(context, &files_env);
+        err = exec_context_load_environment(context, params->unit_id, &files_env);
         if (err < 0) {
                 log_struct_unit(LOG_ERR,
                            params->unit_id,
@@ -2011,7 +2011,7 @@ void exec_command_free_array(ExecCommand **c, unsigned n) {
         }
 }
 
-int exec_context_load_environment(const ExecContext *c, char ***l) {
+int exec_context_load_environment(const ExecContext *c, const char *unit_id, char ***l) {
         char **i, **r = NULL;
 
         assert(c);
@@ -2068,7 +2068,7 @@ int exec_context_load_environment(const ExecContext *c, char ***l) {
                         }
                         /* Log invalid environment variables with filename */
                         if (p)
-                                p = strv_env_clean_log(p, pglob.gl_pathv[n]);
+                                p = strv_env_clean_log(p, unit_id, pglob.gl_pathv[n]);
 
                         if (r == NULL)
                                 r = p;
diff --git a/src/core/execute.h b/src/core/execute.h
index 2694315..c45dde5 100644
--- a/src/core/execute.h
+++ b/src/core/execute.h
@@ -241,7 +241,7 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix);
 
 int exec_context_destroy_runtime_directory(ExecContext *c, const char *runtime_root);
 
-int exec_context_load_environment(const ExecContext *c, char ***l);
+int exec_context_load_environment(const ExecContext *c, const char *unit_id, char ***l);
 
 bool exec_context_may_touch_console(ExecContext *c);
 
diff --git a/src/shared/env-util.c b/src/shared/env-util.c
index 20b208f..d90b878 100644
--- a/src/shared/env-util.c
+++ b/src/shared/env-util.c
@@ -28,6 +28,7 @@
 #include "util.h"
 #include "env-util.h"
 #include "def.h"
+#include "unit.h"
 
 #define VALID_CHARS_ENV_NAME                    \
         DIGITS LETTERS                          \
@@ -414,7 +415,7 @@ char *strv_env_get(char **l, const char *name) {
         return strv_env_get_n(l, name, strlen(name));
 }
 
-char **strv_env_clean_log(char **e, const char *message) {
+char **strv_env_clean_log(char **e, const char *unit_id, const char *message) {
         char **p, **q;
         int k = 0;
 
@@ -424,7 +425,7 @@ char **strv_env_clean_log(char **e, const char *message) {
 
                 if (!env_assignment_is_valid(*p)) {
                         if (message)
-                                log_error("Ignoring invalid environment '%s': %s", *p, message);
+                                log_error_unit(unit_id, "Ignoring invalid environment '%s': %s", *p, message);
                         free(*p);
                         continue;
                 }
@@ -451,5 +452,5 @@ char **strv_env_clean_log(char **e, const char *message) {
 }
 
 char **strv_env_clean(char **e) {
-        return strv_env_clean_log(e, NULL);
+        return strv_env_clean_log(e, NULL, NULL);
 }
diff --git a/src/shared/env-util.h b/src/shared/env-util.h
index c0b1e38..3c6f9d7 100644
--- a/src/shared/env-util.h
+++ b/src/shared/env-util.h
@@ -30,7 +30,7 @@ bool env_assignment_is_valid(const char *e);
 
 bool strv_env_is_valid(char **e);
 char **strv_env_clean(char **l);
-char **strv_env_clean_log(char **e, const char *message);
+char **strv_env_clean_log(char **e, const char *unit_id, const char *message);
 
 bool strv_env_name_or_assignment_is_valid(char **l);
 
diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c
index 76a9e8e..7e7b4ac 100644
--- a/src/test/test-fileio.c
+++ b/src/test/test-fileio.c
@@ -90,7 +90,7 @@ static void test_parse_env_file(void) {
         assert_se(streq_ptr(a[9], "ten="));
         assert_se(a[10] == NULL);
 
-        strv_env_clean_log(a, "test");
+        strv_env_clean_log(a, NULL, "test");
 
         k = 0;
         STRV_FOREACH(i, b) {
-- 
1.8.3.1



More information about the systemd-devel mailing list