chiark / gitweb /
unit: rename load_path to fragment_path to make clear what kind of configuration...
[elogind.git] / load-fragment.c
index c271ce5a5cc2f930f65fe1a5bff0ebf297fafb5a..4183b5c8fa912eec2ed5f412804c7eb6e1b29659 100644 (file)
@@ -1,5 +1,24 @@
 /*-*- Mode: C; c-basic-offset: 8 -*-*/
 
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
 #include <linux/oom.h>
 #include <assert.h>
 #include <errno.h>
@@ -266,7 +285,7 @@ static int config_parse_oom_adjust(
         return 0;
 }
 
-static int config_parse_umask(
+static int config_parse_mode(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -287,12 +306,12 @@ static int config_parse_umask(
         errno = 0;
         l = strtol(rvalue, &x, 8);
         if (!x || *x || errno) {
-                log_error("[%s:%u] Failed to parse umask value: %s", filename, line, rvalue);
+                log_error("[%s:%u] Failed to parse mode value: %s", filename, line, rvalue);
                 return errno ? -errno : -EINVAL;
         }
 
-        if (l < 0000 || l > 0777) {
-                log_error("[%s:%u] umask value out of range: %s", filename, line, rvalue);
+        if (l < 0000 || l > 07777) {
+                log_error("[%s:%u] mode value out of range: %s", filename, line, rvalue);
                 return -ERANGE;
         }
 
@@ -453,7 +472,7 @@ static int config_parse_service_restart(
         return 0;
 }
 
-int config_parse_bindtodevice(
+static int config_parse_bindtodevice(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -482,7 +501,7 @@ int config_parse_bindtodevice(
         return 0;
 }
 
-int config_parse_output(
+static int config_parse_output(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -508,7 +527,7 @@ int config_parse_output(
         return 0;
 }
 
-int config_parse_input(
+static int config_parse_input(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -534,7 +553,7 @@ int config_parse_input(
         return 0;
 }
 
-int config_parse_facility(
+static int config_parse_facility(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -564,7 +583,7 @@ int config_parse_facility(
         return 0;
 }
 
-int config_parse_level(
+static int config_parse_level(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -593,7 +612,7 @@ int config_parse_level(
         return 0;
 }
 
-int config_parse_io_class(
+static int config_parse_io_class(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -624,7 +643,7 @@ int config_parse_io_class(
         return 0;
 }
 
-int config_parse_io_priority(
+static int config_parse_io_priority(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -652,7 +671,7 @@ int config_parse_io_priority(
         return 0;
 }
 
-int config_parse_cpu_sched_policy(
+static int config_parse_cpu_sched_policy(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -684,7 +703,7 @@ int config_parse_cpu_sched_policy(
         return 0;
 }
 
-int config_parse_cpu_sched_prio(
+static int config_parse_cpu_sched_prio(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -713,7 +732,7 @@ int config_parse_cpu_sched_prio(
         return 0;
 }
 
-int config_parse_cpu_affinity(
+static int config_parse_cpu_affinity(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -756,7 +775,7 @@ int config_parse_cpu_affinity(
         return 0;
 }
 
-int config_parse_capabilities(
+static int config_parse_capabilities(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -788,7 +807,7 @@ int config_parse_capabilities(
         return 0;
 }
 
-int config_parse_secure_bits(
+static int config_parse_secure_bits(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -829,7 +848,7 @@ int config_parse_secure_bits(
         return 0;
 }
 
-int config_parse_bounding_set(
+static int config_parse_bounding_set(
                 const char *filename,
                 unsigned line,
                 const char *section,
@@ -1026,7 +1045,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "CPUSchedulingPriority",  config_parse_cpu_sched_prio,  &(context),                                      section   }, \
                 { "CPUSchedulingResetOnFork", config_parse_bool,          &(context).cpu_sched_reset_on_fork,              section   }, \
                 { "CPUAffinity",            config_parse_cpu_affinity,    &(context),                                      section   }, \
-                { "UMask",                  config_parse_umask,           &(context).umask,                                section   }, \
+                { "UMask",                  config_parse_mode,            &(context).umask,                                section   }, \
                 { "Environment",            config_parse_strv,            &(context).environment,                          section   }, \
                 { "Output",                 config_parse_output,          &(context).output,                               section   }, \
                 { "Input",                  config_parse_input,           &(context).input,                                section   }, \
@@ -1052,7 +1071,8 @@ static int load_from_path(Unit *u, const char *path) {
                 { "LimitMSGQUEUE",          config_parse_limit,           &(context).rlimit[RLIMIT_MSGQUEUE],              section   }, \
                 { "LimitNICE",              config_parse_limit,           &(context).rlimit[RLIMIT_NICE],                  section   }, \
                 { "LimitRTPRIO",            config_parse_limit,           &(context).rlimit[RLIMIT_RTPRIO],                section   }, \
-                { "LimitRTTIME",            config_parse_limit,           &(context).rlimit[RLIMIT_RTTIME],                section   }
+                { "LimitRTTIME",            config_parse_limit,           &(context).rlimit[RLIMIT_RTTIME],                section   }, \
+                { "NonBlocking",            config_parse_bool,            &(context).non_blocking,                         section   }
 
         const ConfigItem items[] = {
                 { "Names",                  config_parse_names,           u,                                               "Meta"    },
@@ -1092,6 +1112,8 @@ static int load_from_path(Unit *u, const char *path) {
                 { "ExecStartPost",          config_parse_exec,            u->socket.exec_command+SOCKET_EXEC_START_POST,   "Socket"  },
                 { "ExecStopPre",            config_parse_exec,            u->socket.exec_command+SOCKET_EXEC_STOP_PRE,     "Socket"  },
                 { "ExecStopPost",           config_parse_exec,            u->socket.exec_command+SOCKET_EXEC_STOP_POST,    "Socket"  },
+                { "DirectoryMode",          config_parse_mode,            &u->socket.directory_mode,                       "Socket"  },
+                { "SocketMode",             config_parse_mode,            &u->socket.socket_mode,                          "Socket"  },
                 EXEC_CONTEXT_CONFIG_ITEMS(u->socket.exec_context, "Socket"),
 
                 EXEC_CONTEXT_CONFIG_ITEMS(u->automount.exec_context, "Automount"),
@@ -1106,7 +1128,7 @@ static int load_from_path(Unit *u, const char *path) {
         int r;
         Set *symlink_names;
         FILE *f;
-        char *filename, *id;
+        char *filename = NULL, *id;
 
         sections[0] = "Meta";
         sections[1] = section_table[u->meta.type];
@@ -1115,18 +1137,56 @@ static int load_from_path(Unit *u, const char *path) {
         if (!(symlink_names = set_new(string_hash_func, string_compare_func)))
                 return -ENOMEM;
 
-        /* Instead of opening the path right away, we manually
-         * follow all symlinks and add their name to our unit
-         * name set while doing so */
-        if (!(filename = path_make_absolute(path, unit_path()))) {
-                r = -ENOMEM;
-                goto finish;
-        }
+        if (path_is_absolute(path)) {
+
+                if (!(filename = strdup(path))) {
+                        r = -ENOMEM;
+                        goto finish;
+                }
+
+                if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) {
+                        free(filename);
+                        filename = NULL;
+
+                        if (r != -ENOENT)
+                                goto finish;
+                }
 
-        if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) {
-                if (r == -ENOENT)
-                        r = 0; /* returning 0 means: no suitable config file found */
+        } else  {
+                char **p;
+
+                STRV_FOREACH(p, u->meta.manager->unit_path) {
+
+                        /* Instead of opening the path right away, we manually
+                         * follow all symlinks and add their name to our unit
+                         * name set while doing so */
+                        if (!(filename = path_make_absolute(path, *p))) {
+                                r = -ENOMEM;
+                                goto finish;
+                        }
+
+                        if ((r = open_follow(&filename, &f, symlink_names, &id)) < 0) {
+                                char *sn;
+
+                                free(filename);
+                                filename = NULL;
+
+                                if (r != -ENOENT)
+                                        goto finish;
+
+                                /* Empty the symlink names for the next run */
+                                while ((sn = set_steal_first(symlink_names)))
+                                        free(sn);
+
+                                continue;
+                        }
+
+                        break;
+                }
+        }
 
+        if (!filename) {
+                r = 0; /* returning 0 means: no suitable config file found */
                 goto finish;
         }
 
@@ -1147,8 +1207,8 @@ static int load_from_path(Unit *u, const char *path) {
         }
 
 
-        free(u->meta.load_path);
-        u->meta.load_path = filename;
+        free(u->meta.fragment_path);
+        u->meta.fragment_path = filename;
         filename = NULL;
 
         r = 1; /* returning 1 means: suitable config file found and loaded */
@@ -1169,8 +1229,8 @@ int unit_load_fragment(Unit *u) {
         assert(u);
         assert(u->meta.load_state == UNIT_STUB);
 
-        if (u->meta.load_path)
-                r = load_from_path(u, u->meta.load_path);
+        if (u->meta.fragment_path)
+                r = load_from_path(u, u->meta.fragment_path);
         else {
                 Iterator i;
                 char *t;