daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
Blob Blame History Raw
From 432496f644241d282d706285181a0b94c7c788f5 Mon Sep 17 00:00:00 2001
From: Lukas Nykryn <lnykryn@redhat.com>
Date: Fri, 17 Oct 2014 11:46:01 +0200
Subject: [PATCH] environment: append unit_id to error messages regarding
 EnvironmentFile

(cherry-picked from 7491ccf2cb237a2a88b831b2c7374ba2bb255cba)
Conflicts:
	src/core/execute.c

Resolves: #1147691
---
 src/core/execute.c     |  6 +++---
 src/core/execute.h     |  2 +-
 src/shared/env-util.c  | 13 ++++++++++---
 src/shared/env-util.h  |  2 +-
 src/test/test-fileio.c |  2 +-
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/core/execute.c b/src/core/execute.c
index 0894156..be99149 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -1071,7 +1071,7 @@ int exec_spawn(ExecCommand *command,
         } else
                 socket_fd = -1;
 
-        r = exec_context_load_environment(context, &files_env);
+        r = exec_context_load_environment(context, unit_id, &files_env);
         if (r < 0) {
                 log_struct_unit(LOG_ERR,
                            unit_id,
@@ -1776,7 +1776,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);
@@ -1833,7 +1833,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 5055890..b66bd5f 100644
--- a/src/core/execute.h
+++ b/src/core/execute.h
@@ -200,7 +200,7 @@ void exec_context_tmp_dirs_done(ExecContext *c);
 void exec_context_dump(ExecContext *c, FILE* f, const char *prefix);
 void exec_context_tty_reset(const ExecContext *context);
 
-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);
 void exec_context_serialize(const ExecContext *c, Unit *u, FILE *f);
diff --git a/src/shared/env-util.c b/src/shared/env-util.c
index 7976881..5b5da48 100644
--- a/src/shared/env-util.c
+++ b/src/shared/env-util.c
@@ -29,6 +29,13 @@
 #include "env-util.h"
 #include "def.h"
 
+#define log_full_unit(level, unit, ...) log_meta_object(level, __FILE__, __LINE__, __func__, getpid() == 1 ? "UNIT=" : "USER_UNIT=", unit, __VA_ARGS__)
+#define log_debug_unit(unit, ...)       log_full_unit(LOG_DEBUG, unit, __VA_ARGS__)
+#define log_info_unit(unit, ...)        log_full_unit(LOG_INFO, unit, __VA_ARGS__)
+#define log_notice_unit(unit, ...)      log_full_unit(LOG_NOTICE, unit, __VA_ARGS__)
+#define log_warning_unit(unit, ...)     log_full_unit(LOG_WARNING, unit, __VA_ARGS__)
+#define log_error_unit(unit, ...)       log_full_unit(LOG_ERR, unit, __VA_ARGS__)
+
 #define VALID_CHARS_ENV_NAME                    \
         DIGITS LETTERS                          \
         "_"
@@ -375,7 +382,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;
 
@@ -385,7 +392,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;
                 }
@@ -412,5 +419,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 8d2114b..5ea82ad 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 06f3e28..c92bb6e 100644
--- a/src/test/test-fileio.c
+++ b/src/test/test-fileio.c
@@ -88,7 +88,7 @@ static void test_parse_env_file(void) {
         assert_se(streq(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) {