teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0364-environment-append-unit_id-to-error-messages-regardi.patch

84b277
From 432496f644241d282d706285181a0b94c7c788f5 Mon Sep 17 00:00:00 2001
84b277
From: Lukas Nykryn <lnykryn@redhat.com>
84b277
Date: Fri, 17 Oct 2014 11:46:01 +0200
84b277
Subject: [PATCH] environment: append unit_id to error messages regarding
84b277
 EnvironmentFile
84b277
84b277
(cherry-picked from 7491ccf2cb237a2a88b831b2c7374ba2bb255cba)
84b277
Conflicts:
84b277
	src/core/execute.c
84b277
84b277
Resolves: #1147691
84b277
---
84b277
 src/core/execute.c     |  6 +++---
84b277
 src/core/execute.h     |  2 +-
84b277
 src/shared/env-util.c  | 13 ++++++++++---
84b277
 src/shared/env-util.h  |  2 +-
84b277
 src/test/test-fileio.c |  2 +-
84b277
 5 files changed, 16 insertions(+), 9 deletions(-)
84b277
84b277
diff --git a/src/core/execute.c b/src/core/execute.c
84b277
index 0894156..be99149 100644
84b277
--- a/src/core/execute.c
84b277
+++ b/src/core/execute.c
84b277
@@ -1071,7 +1071,7 @@ int exec_spawn(ExecCommand *command,
84b277
         } else
84b277
                 socket_fd = -1;
84b277
 
84b277
-        r = exec_context_load_environment(context, &files_env);
84b277
+        r = exec_context_load_environment(context, unit_id, &files_env);
84b277
         if (r < 0) {
84b277
                 log_struct_unit(LOG_ERR,
84b277
                            unit_id,
84b277
@@ -1776,7 +1776,7 @@ void exec_command_free_array(ExecCommand **c, unsigned n) {
84b277
         }
84b277
 }
84b277
 
84b277
-int exec_context_load_environment(const ExecContext *c, char ***l) {
84b277
+int exec_context_load_environment(const ExecContext *c, const char *unit_id, char ***l) {
84b277
         char **i, **r = NULL;
84b277
 
84b277
         assert(c);
84b277
@@ -1833,7 +1833,7 @@ int exec_context_load_environment(const ExecContext *c, char ***l) {
84b277
                         }
84b277
                         /* Log invalid environment variables with filename */
84b277
                         if (p)
84b277
-                                p = strv_env_clean_log(p, pglob.gl_pathv[n]);
84b277
+                                p = strv_env_clean_log(p, unit_id, pglob.gl_pathv[n]);
84b277
 
84b277
                         if (r == NULL)
84b277
                                 r = p;
84b277
diff --git a/src/core/execute.h b/src/core/execute.h
84b277
index 5055890..b66bd5f 100644
84b277
--- a/src/core/execute.h
84b277
+++ b/src/core/execute.h
84b277
@@ -200,7 +200,7 @@ void exec_context_tmp_dirs_done(ExecContext *c);
84b277
 void exec_context_dump(ExecContext *c, FILE* f, const char *prefix);
84b277
 void exec_context_tty_reset(const ExecContext *context);
84b277
 
84b277
-int exec_context_load_environment(const ExecContext *c, char ***l);
84b277
+int exec_context_load_environment(const ExecContext *c, const char *unit_id, char ***l);
84b277
 
84b277
 bool exec_context_may_touch_console(ExecContext *c);
84b277
 void exec_context_serialize(const ExecContext *c, Unit *u, FILE *f);
84b277
diff --git a/src/shared/env-util.c b/src/shared/env-util.c
84b277
index 7976881..5b5da48 100644
84b277
--- a/src/shared/env-util.c
84b277
+++ b/src/shared/env-util.c
84b277
@@ -29,6 +29,13 @@
84b277
 #include "env-util.h"
84b277
 #include "def.h"
84b277
 
84b277
+#define log_full_unit(level, unit, ...) log_meta_object(level, __FILE__, __LINE__, __func__, getpid() == 1 ? "UNIT=" : "USER_UNIT=", unit, __VA_ARGS__)
84b277
+#define log_debug_unit(unit, ...)       log_full_unit(LOG_DEBUG, unit, __VA_ARGS__)
84b277
+#define log_info_unit(unit, ...)        log_full_unit(LOG_INFO, unit, __VA_ARGS__)
84b277
+#define log_notice_unit(unit, ...)      log_full_unit(LOG_NOTICE, unit, __VA_ARGS__)
84b277
+#define log_warning_unit(unit, ...)     log_full_unit(LOG_WARNING, unit, __VA_ARGS__)
84b277
+#define log_error_unit(unit, ...)       log_full_unit(LOG_ERR, unit, __VA_ARGS__)
84b277
+
84b277
 #define VALID_CHARS_ENV_NAME                    \
84b277
         DIGITS LETTERS                          \
84b277
         "_"
84b277
@@ -375,7 +382,7 @@ char *strv_env_get(char **l, const char *name) {
84b277
         return strv_env_get_n(l, name, strlen(name));
84b277
 }
84b277
 
84b277
-char **strv_env_clean_log(char **e, const char *message) {
84b277
+char **strv_env_clean_log(char **e, const char *unit_id, const char *message) {
84b277
         char **p, **q;
84b277
         int k = 0;
84b277
 
84b277
@@ -385,7 +392,7 @@ char **strv_env_clean_log(char **e, const char *message) {
84b277
 
84b277
                 if (!env_assignment_is_valid(*p)) {
84b277
                         if (message)
84b277
-                                log_error("Ignoring invalid environment '%s': %s", *p, message);
84b277
+                                log_error_unit(unit_id, "Ignoring invalid environment '%s': %s", *p, message);
84b277
                         free(*p);
84b277
                         continue;
84b277
                 }
84b277
@@ -412,5 +419,5 @@ char **strv_env_clean_log(char **e, const char *message) {
84b277
 }
84b277
 
84b277
 char **strv_env_clean(char **e) {
84b277
-        return strv_env_clean_log(e, NULL);
84b277
+        return strv_env_clean_log(e, NULL, NULL);
84b277
 }
84b277
diff --git a/src/shared/env-util.h b/src/shared/env-util.h
84b277
index 8d2114b..5ea82ad 100644
84b277
--- a/src/shared/env-util.h
84b277
+++ b/src/shared/env-util.h
84b277
@@ -30,7 +30,7 @@ bool env_assignment_is_valid(const char *e);
84b277
 
84b277
 bool strv_env_is_valid(char **e);
84b277
 char **strv_env_clean(char **l);
84b277
-char **strv_env_clean_log(char **e, const char *message);
84b277
+char **strv_env_clean_log(char **e, const char *unit_id, const char *message);
84b277
 
84b277
 bool strv_env_name_or_assignment_is_valid(char **l);
84b277
 
84b277
diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c
84b277
index 06f3e28..c92bb6e 100644
84b277
--- a/src/test/test-fileio.c
84b277
+++ b/src/test/test-fileio.c
84b277
@@ -88,7 +88,7 @@ static void test_parse_env_file(void) {
84b277
         assert_se(streq(a[9], "ten="));
84b277
         assert_se(a[10] == NULL);
84b277
 
84b277
-        strv_env_clean_log(a, "test");
84b277
+        strv_env_clean_log(a, NULL, "test");
84b277
 
84b277
         k = 0;
84b277
         STRV_FOREACH(i, b) {