chiark / gitweb /
env-util: don't include files from src/core/
authorLennart Poettering <lennart@poettering.net>
Tue, 23 Dec 2014 18:04:56 +0000 (19:04 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 23 Dec 2014 18:15:27 +0000 (19:15 +0100)
src/core/execute.c
src/shared/env-util.c
src/shared/env-util.h
src/test/test-fileio.c

index c472dadfeda734e73c981a304f6c3c3685c8c0cd..a806d42827a8afa5389bc52948e6498b7cfee884 100644 (file)
@@ -2026,6 +2026,17 @@ void exec_command_free_array(ExecCommand **c, unsigned n) {
                 c[i] = exec_command_free_list(c[i]);
 }
 
+typedef struct InvalidEnvInfo {
+        const char *unit_id;
+        const char *path;
+} InvalidEnvInfo;
+
+static void invalid_env(const char *p, void *userdata) {
+        InvalidEnvInfo *info = userdata;
+
+        log_unit_error(info->unit_id, "Ignoring invalid environment assignment '%s': %s", p, info->path);
+}
+
 int exec_context_load_environment(const ExecContext *c, const char *unit_id, char ***l) {
         char **i, **r = NULL;
 
@@ -2082,8 +2093,14 @@ int exec_context_load_environment(const ExecContext *c, const char *unit_id, cha
                                 return k;
                         }
                         /* Log invalid environment variables with filename */
-                        if (p)
-                                p = strv_env_clean_log(p, unit_id, pglob.gl_pathv[n]);
+                        if (p) {
+                                InvalidEnvInfo info = {
+                                        .unit_id = unit_id,
+                                        .path = pglob.gl_pathv[n]
+                                };
+
+                                p = strv_env_clean_with_callback(p, invalid_env, &info);
+                        }
 
                         if (r == NULL)
                                 r = p;
index fbdc73dd2c6459f324d487ba8826d00f8ced4cf4..038246d21b7cd134fa34997be73d036d9ac036b2 100644 (file)
@@ -28,7 +28,6 @@
 #include "util.h"
 #include "env-util.h"
 #include "def.h"
-#include "unit.h"
 
 #define VALID_CHARS_ENV_NAME                    \
         DIGITS LETTERS                          \
@@ -415,7 +414,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 *unit_id, const char *message) {
+char **strv_env_clean_with_callback(char **e, void (*invalid_callback)(const char *p, void *userdata), void *userdata) {
         char **p, **q;
         int k = 0;
 
@@ -424,8 +423,8 @@ char **strv_env_clean_log(char **e, const char *unit_id, const char *message) {
                 bool duplicate = false;
 
                 if (!env_assignment_is_valid(*p)) {
-                        if (message)
-                                log_unit_error(unit_id, "Ignoring invalid environment '%s': %s", *p, message);
+                        if (invalid_callback)
+                                invalid_callback(*p, userdata);
                         free(*p);
                         continue;
                 }
@@ -450,7 +449,3 @@ char **strv_env_clean_log(char **e, const char *unit_id, const char *message) {
 
         return e;
 }
-
-char **strv_env_clean(char **e) {
-        return strv_env_clean_log(e, NULL, NULL);
-}
index 3c6f9d743f270dfa476c43055202e6568c6a1d3c..fb3a52b707028a49be3c19239f006fd2e3e37d45 100644 (file)
@@ -29,8 +29,8 @@ bool env_value_is_valid(const char *e);
 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 *unit_id, const char *message);
+#define strv_env_clean(l) strv_env_clean_with_callback(l, NULL, NULL)
+char **strv_env_clean_with_callback(char **l, void (*invalid_callback)(const char *p, void *userdata), void *userdata);
 
 bool strv_env_name_or_assignment_is_valid(char **l);
 
index cdf1973ea597826f6789db563e72b0cd83463c43..63e4a19b7638e41c6ac86324f7875380698c7aa0 100644 (file)
@@ -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, NULL, "test");
+        strv_env_clean(a);
 
         k = 0;
         STRV_FOREACH(i, b) {