X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fload-fragment.c;h=eb9861802b21da0ca226f0549d3efa3d509e11b5;hp=eba3fdbdfdc9f088510a6278228404544a1c918b;hb=6daf4f9001d87da9e92c04ff606b454c209f0951;hpb=d9ff321ad9477664c34b81a9dd4fce616e44124e diff --git a/src/load-fragment.c b/src/load-fragment.c index eba3fdbdf..eb9861802 100644 --- a/src/load-fragment.c +++ b/src/load-fragment.c @@ -1246,8 +1246,8 @@ static int config_parse_socket_service( dbus_error_init(&error); - if (endswith(rvalue, ".service")) { - log_error("[%s:%u] Unit must be of type serivce, ignoring: %s", filename, line, rvalue); + if (!endswith(rvalue, ".service")) { + log_error("[%s:%u] Unit must be of type service, ignoring: %s", filename, line, rvalue); return 0; } @@ -1260,6 +1260,60 @@ static int config_parse_socket_service( return 0; } +static int config_parse_service_sockets( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + const char *rvalue, + void *data, + void *userdata) { + + Service *s = data; + int r; + DBusError error; + char *state, *w; + size_t l; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + dbus_error_init(&error); + + FOREACH_WORD_QUOTED(w, l, rvalue, state) { + char *t; + Unit *sock; + + if (!(t = strndup(w, l))) + return -ENOMEM; + + if (!endswith(t, ".socket")) { + log_error("[%s:%u] Unit must be of type socket, ignoring: %s", filename, line, rvalue); + free(t); + continue; + } + + r = manager_load_unit(s->meta.manager, t, NULL, &error, &sock); + free(t); + + if (r < 0) { + log_error("[%s:%u] Failed to load unit %s, ignoring: %s", filename, line, rvalue, bus_error(&error, r)); + dbus_error_free(&error); + continue; + } + + if ((r = set_ensure_allocated(&s->configured_sockets, trivial_hash_func, trivial_compare_func)) < 0) + return r; + + if ((r = set_put(s->configured_sockets, sock)) < 0) + return r; + } + + return 0; +} + static int config_parse_env_file( const char *filename, unsigned line, @@ -1377,7 +1431,7 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_final) { * unit name. */ name = file_name_from_path(*filename); - if (unit_name_is_valid(name)) { + if (unit_name_is_valid(name, false)) { if (!(id = set_get(names, name))) { if (!(id = strdup(name))) @@ -1615,7 +1669,8 @@ static int load_from_path(Unit *u, const char *path) { { "TCPWrapName", config_parse_string_printf, &(context).tcpwrap_name, section }, \ { "PAMName", config_parse_string_printf, &(context).pam_name, section }, \ { "KillMode", config_parse_kill_mode, &(context).kill_mode, section }, \ - { "KillSignal", config_parse_kill_signal, &(context).kill_signal, section } + { "KillSignal", config_parse_kill_signal, &(context).kill_signal, section }, \ + { "UtmpIdentifier", config_parse_string_printf, &(context).utmp_id, section } const ConfigItem items[] = { { "Names", config_parse_names, u, "Unit" }, @@ -1655,11 +1710,12 @@ static int load_from_path(Unit *u, const char *path) { #ifdef HAVE_SYSV_COMPAT { "SysVStartPriority", config_parse_sysv_priority, &u->service.sysv_start_priority, "Service" }, #else - { "SysVStartPriority", config_parse_warn_compat, NULL, "Service" }, + { "SysVStartPriority", config_parse_warn_compat, NULL, "Service" }, #endif { "NonBlocking", config_parse_bool, &u->service.exec_context.non_blocking, "Service" }, { "BusName", config_parse_string_printf, &u->service.bus_name, "Service" }, { "NotifyAccess", config_parse_notify_access, &u->service.notify_access, "Service" }, + { "Sockets", config_parse_service_sockets, &u->service, "Service" }, EXEC_CONTEXT_CONFIG_ITEMS(u->service.exec_context, "Service"), { "ListenStream", config_parse_listen, &u->socket, "Socket" }, @@ -1828,9 +1884,15 @@ static int load_from_path(Unit *u, const char *path) { goto finish; } - /* Now, parse the file contents */ - if ((r = config_parse(filename, f, sections, items, false, u)) < 0) - goto finish; + if (null_or_empty(&st)) + u->meta.load_state = UNIT_MASKED; + else { + /* Now, parse the file contents */ + if ((r = config_parse(filename, f, sections, items, false, u)) < 0) + goto finish; + + u->meta.load_state = UNIT_LOADED; + } free(u->meta.fragment_path); u->meta.fragment_path = filename; @@ -1838,7 +1900,6 @@ static int load_from_path(Unit *u, const char *path) { u->meta.fragment_mtime = timespec_load(&st.st_mtim); - u->meta.load_state = UNIT_LOADED; r = 0; finish: