chiark / gitweb /
core: move config_parse_set_status() into load-fragment.c
authorLennart Poettering <lennart@poettering.net>
Mon, 3 Mar 2014 20:26:53 +0000 (21:26 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 3 Mar 2014 20:26:53 +0000 (21:26 +0100)
Let's keep specific config parsers close to where they are needed. Only
the really generic ones should be defined in conf-parser.[ch].

src/core/load-fragment.c
src/core/load-fragment.h
src/shared/conf-parser.c
src/shared/conf-parser.h

index 902b905d1b0141e6f103737acc62c152188ca71b..d34160ab9ec5c16154c24bec1396af530449a082 100644 (file)
@@ -2769,6 +2769,85 @@ int config_parse_runtime_directory(
         return 0;
 }
 
+int config_parse_set_status(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        char *w;
+        size_t l;
+        char *state;
+        int r;
+        ExitStatusSet *status_set = data;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        if (isempty(rvalue)) {
+                /* Empty assignment resets the list */
+
+                set_free(status_set->signal);
+                set_free(status_set->code);
+
+                status_set->signal = status_set->code = NULL;
+                return 0;
+        }
+
+        FOREACH_WORD(w, l, rvalue, state) {
+                _cleanup_free_ char *temp;
+                int val;
+
+                temp = strndup(w, l);
+                if (!temp)
+                        return log_oom();
+
+                r = safe_atoi(temp, &val);
+                if (r < 0) {
+                        val = signal_from_string_try_harder(temp);
+
+                        if (val > 0) {
+                                r = set_ensure_allocated(&status_set->signal, trivial_hash_func, trivial_compare_func);
+                                if (r < 0)
+                                        return log_oom();
+
+                                r = set_put(status_set->signal, INT_TO_PTR(val));
+                                if (r < 0) {
+                                        log_syntax(unit, LOG_ERR, filename, line, -r, "Unable to store: %s", w);
+                                        return r;
+                                }
+                        } else {
+                                log_syntax(unit, LOG_ERR, filename, line, -val, "Failed to parse value, ignoring: %s", w);
+                                return 0;
+                        }
+                } else {
+                        if (val < 0 || val > 255)
+                                log_syntax(unit, LOG_ERR, filename, line, ERANGE, "Value %d is outside range 0-255, ignoring", val);
+                        else {
+                                r = set_ensure_allocated(&status_set->code, trivial_hash_func, trivial_compare_func);
+                                if (r < 0)
+                                        return log_oom();
+
+                                r = set_put(status_set->code, INT_TO_PTR(val));
+                                if (r < 0) {
+                                        log_syntax(unit, LOG_ERR, filename, line, -r, "Unable to store: %s", w);
+                                        return r;
+                                }
+                        }
+                }
+        }
+
+        return 0;
+}
+
 #define FOLLOW_MAX 8
 
 static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
index 5488f1d7045cd3002f13b588aa74b07811b4c437..95485db3fe619d396760ee8b6ed7ef3d9f987b31 100644 (file)
@@ -92,6 +92,7 @@ int config_parse_personality(const char *unit, const char *filename, unsigned li
 int config_parse_exec_apparmor_profile(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_address_families(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_runtime_directory(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
+int config_parse_set_status(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 
 /* gperf prototypes */
 const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, unsigned length);
index accbdac6b14fba7f4a3149b6f9f89e2c5751cfa8..161f6ad65a3ef0355dbdb301416ab436ccda7e16 100644 (file)
@@ -867,88 +867,3 @@ int config_parse_log_level(
         *o = (*o & LOG_FACMASK) | x;
         return 0;
 }
-
-int config_parse_set_status(const char *unit,
-                            const char *filename,
-                            unsigned line,
-                            const char *section,
-                            unsigned section_line,
-                            const char *lvalue,
-                            int ltype,
-                            const char *rvalue,
-                            void *data,
-                            void *userdata) {
-
-        char *w;
-        size_t l;
-        char *state;
-        int r;
-        ExitStatusSet *status_set = data;
-
-        assert(filename);
-        assert(lvalue);
-        assert(rvalue);
-        assert(data);
-
-        if (isempty(rvalue)) {
-                /* Empty assignment resets the list */
-
-                set_free(status_set->signal);
-                set_free(status_set->code);
-
-                status_set->signal = status_set->code = NULL;
-                return 0;
-        }
-
-        FOREACH_WORD(w, l, rvalue, state) {
-                int val;
-                char *temp;
-
-                temp = strndup(w, l);
-                if (!temp)
-                        return log_oom();
-
-                r = safe_atoi(temp, &val);
-                if (r < 0) {
-                        val = signal_from_string_try_harder(temp);
-                        free(temp);
-
-                        if (val > 0) {
-                                r = set_ensure_allocated(&status_set->signal, trivial_hash_func, trivial_compare_func);
-                                if (r < 0)
-                                        return log_oom();
-
-                                r = set_put(status_set->signal, INT_TO_PTR(val));
-                                if (r < 0) {
-                                        log_syntax(unit, LOG_ERR, filename, line, -r,
-                                                   "Unable to store: %s", w);
-                                        return r;
-                                }
-                        } else {
-                                log_syntax(unit, LOG_ERR, filename, line, -val,
-                                           "Failed to parse value, ignoring: %s", w);
-                                return 0;
-                        }
-                } else {
-                        free(temp);
-
-                        if (val < 0 || val > 255)
-                                log_syntax(unit, LOG_ERR, filename, line, ERANGE,
-                                           "Value %d is outside range 0-255, ignoring", val);
-                        else {
-                                r = set_ensure_allocated(&status_set->code, trivial_hash_func, trivial_compare_func);
-                                if (r < 0)
-                                        return log_oom();
-
-                                r = set_put(status_set->code, INT_TO_PTR(val));
-                                if (r < 0) {
-                                        log_syntax(unit, LOG_ERR, filename, line, -r,
-                                                   "Unable to store: %s", w);
-                                        return r;
-                                }
-                        }
-                }
-        }
-
-        return 0;
-}
index 50e9270af3c76cc853868fbfe9dc5473e81b75e4..b7f442926f5b73270a16f996c920158fcb069bfa 100644 (file)
@@ -110,7 +110,6 @@ int config_parse_nsec(const char *unit, const char *filename, unsigned line, con
 int config_parse_mode(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_log_facility(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 int config_parse_log_level(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
-int config_parse_set_status(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
 
 int log_syntax_internal(const char *unit, int level,
                         const char *file, unsigned line, const char *func,