chiark / gitweb /
port fragment loader to new utility functions
[elogind.git] / load-fragment.c
index ef1e1de90aeaf9b63216ebd6a4e05119872ba336..2df5c04f779f1c9b6d890bb5076fdcb79beddfb3 100644 (file)
@@ -450,34 +450,37 @@ static int config_parse_service_restart(
         return 0;
 }
 
-#define FOLLOW_MAX 8
+int config_parse_bindtodevice(
+                const char *filename,
+                unsigned line,
+                const char *section,
+                const char *lvalue,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
 
-static char *build_path(const char *path, const char *filename) {
-        char *e, *r;
-        size_t k;
+        Socket *s = data;
+        char *n;
 
-        assert(path);
         assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
 
-        /* This removes the last component of path and appends
-         * filename, unless the latter is absolute anyway or the
-         * former isn't */
-
-        if (path_is_absolute(filename))
-                return strdup(filename);
+        if (rvalue[0] && !streq(rvalue, "*")) {
+                if (!(n = strdup(rvalue)))
+                        return -ENOMEM;
+        } else
+                n = NULL;
 
-        if (!(e = strrchr(path, '/')))
-                return strdup(filename);
+        free(s->bind_to_device);
+        s->bind_to_device = n;
 
-        k = strlen(filename);
-        if (!(r = new(char, e-path+1+k+1)))
-                return NULL;
+        return 0;
+}
 
-        memcpy(r, path, e-path+1);
-        memcpy(r+(e-path)+1, filename, k+1);
+#define FOLLOW_MAX 8
 
-        return r;
-}
 
 static int open_follow(char **filename, FILE **_f, Set *names, char **_id) {
         unsigned c = 0;
@@ -524,7 +527,7 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_id) {
                 if ((r = readlink_malloc(*filename, &target)) < 0)
                         return r;
 
-                k = build_path(*filename, target);
+                k = file_in_same_dir(*filename, target);
                 free(target);
 
                 if (!k)
@@ -599,6 +602,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "ListenFIFO",             config_parse_listen,          &u->socket,                                      "Socket"  },
                 { "BindIPv6Only",           config_parse_socket_bind,     &u->socket,                                      "Socket"  },
                 { "Backlog",                config_parse_unsigned,        &u->socket.backlog,                              "Socket"  },
+                { "BindToDevice",           config_parse_bindtodevice,    &u->socket,                                      "Socket"  },
                 { "ExecStartPre",           config_parse_exec,            u->socket.exec_command+SOCKET_EXEC_START_PRE,    "Socket"  },
                 { "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"  },