X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Fcore%2Fservice.c;h=db1f1e78efcfd8b74cec30dcb12f43dc6ed48b86;hb=f5b51ea7fcb0b6380c3ceb4d4f3f22f647c6fd32;hp=120510c6c130f01dbe50c87cac36c3908c5fb11b;hpb=8545f7ceaa57734236e54614897d40b673a16795;p=elogind.git diff --git a/src/core/service.c b/src/core/service.c index 120510c6c..db1f1e78e 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -21,7 +21,6 @@ #include #include -#include #include #include "async.h" @@ -562,7 +561,7 @@ static int service_add_extras(Service *s) { if (r < 0) return r; - n = strappenda(s->bus_name, ".busname"); + n = strjoina(s->bus_name, ".busname"); r = unit_add_dependency_by_name(UNIT(s), UNIT_AFTER, n, NULL, true); if (r < 0) return r; @@ -619,7 +618,7 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) { assert(s); prefix = strempty(prefix); - prefix2 = strappenda(prefix, "\t"); + prefix2 = strjoina(prefix, "\t"); fprintf(f, "%sService State: %s\n" @@ -879,7 +878,7 @@ static void service_set_state(Service *s, ServiceState state) { s->reload_result = SERVICE_SUCCESS; } -static int service_coldplug(Unit *u) { +static int service_coldplug(Unit *u, Hashmap *deferred_work) { Service *s = SERVICE(u); int r; @@ -1058,7 +1057,11 @@ static int service_spawn( assert(c); assert(_pid); - unit_realize_cgroup(UNIT(s)); + (void) unit_realize_cgroup(UNIT(s)); + if (s->reset_cpu_usage) { + (void) unit_reset_cpu_usage(UNIT(s)); + s->reset_cpu_usage = false; + } r = unit_setup_exec_runtime(UNIT(s)); if (r < 0) @@ -1092,7 +1095,7 @@ static int service_spawn( if (r < 0) goto fail; - our_env = new0(char*, 4); + our_env = new0(char*, 6); if (!our_env) { r = -ENOMEM; goto fail; @@ -1116,6 +1119,46 @@ static int service_spawn( goto fail; } + if (UNIT_DEREF(s->accept_socket)) { + union sockaddr_union sa; + socklen_t salen = sizeof(sa); + + r = getpeername(s->socket_fd, &sa.sa, &salen); + if (r < 0) { + r = -errno; + goto fail; + } + + if (IN_SET(sa.sa.sa_family, AF_INET, AF_INET6)) { + _cleanup_free_ char *addr = NULL; + char *t; + int port; + + r = sockaddr_pretty(&sa.sa, salen, true, false, &addr); + if (r < 0) + goto fail; + + t = strappend("REMOTE_ADDR=", addr); + if (!t) { + r = -ENOMEM; + goto fail; + } + our_env[n_env++] = t; + + port = sockaddr_port(&sa.sa); + if (port < 0) { + r = port; + goto fail; + } + + if (asprintf(&t, "REMOTE_PORT=%u", port) < 0) { + r = -ENOMEM; + goto fail; + } + our_env[n_env++] = t; + } + } + final_env = strv_env_merge(2, UNIT(s)->manager->environment, our_env, NULL); if (!final_env) { r = -ENOMEM; @@ -1123,7 +1166,7 @@ static int service_spawn( } if (is_control && UNIT(s)->cgroup_path) { - path = strappenda(UNIT(s)->cgroup_path, "/control"); + path = strjoina(UNIT(s)->cgroup_path, "/control"); cg_create(SYSTEMD_CGROUP_CONTROLLER, path); } else path = UNIT(s)->cgroup_path; @@ -1489,7 +1532,7 @@ static void service_kill_control_processes(Service *s) { if (!UNIT(s)->cgroup_path) return; - p = strappenda(UNIT(s)->cgroup_path, "/control"); + p = strjoina(UNIT(s)->cgroup_path, "/control"); cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, p, SIGKILL, true, true, true, NULL); } @@ -1829,6 +1872,7 @@ static int service_start(Unit *u) { s->main_pid_known = false; s->main_pid_alien = false; s->forbid_restart = false; + s->reset_cpu_usage = true; free(s->status_text); s->status_text = NULL; @@ -1837,7 +1881,7 @@ static int service_start(Unit *u) { s->notify_state = NOTIFY_UNKNOWN; service_enter_start_pre(s); - return 0; + return 1; } static int service_stop(Unit *u) { @@ -1878,7 +1922,7 @@ static int service_stop(Unit *u) { s->state == SERVICE_EXITED); service_enter_stop(s, SERVICE_SUCCESS); - return 0; + return 1; } static int service_reload(Unit *u) {