X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=service.c;h=67950d4e649d587cf7f77930c926eee2093da7d7;hp=b564c986b96dc2d872a565c450119903383baffd;hb=47be870bd83fb3719dffc3ee9348a409ab762a14;hpb=94f043472a5af62dc9cd5767e89ba33872212d5e diff --git a/service.c b/service.c index b564c986b..67950d4e6 100644 --- a/service.c +++ b/service.c @@ -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 . +***/ + #include #include @@ -111,13 +130,13 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) { ServiceExecCommand c; Service *s = SERVICE(u); - char *prefix2; + const char *prefix2; + char *p2; assert(s); - prefix2 = strappend(prefix, "\t"); - if (!prefix2) - prefix2 = ""; + p2 = strappend(prefix, "\t"); + prefix2 = p2 ? p2 : prefix; fprintf(f, "%sService State: %s\n", @@ -142,7 +161,7 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) { exec_command_dump_list(s->exec_command[c], f, prefix2); } - free(prefix2); + free(p2); } static int service_load_pid_file(Service *s) { @@ -224,7 +243,7 @@ fail: static int service_notify_sockets(Service *s) { Iterator i; Set *set; - Socket *socket; + Socket *sock; int r; assert(s); @@ -234,8 +253,8 @@ static int service_notify_sockets(Service *s) { if ((r = service_get_sockets(s, &set)) < 0) return r; - SET_FOREACH(socket, set, i) - socket_notify_service_dead(socket); + SET_FOREACH(sock, set, i) + socket_notify_service_dead(sock); set_free(set); @@ -262,7 +281,8 @@ static void service_set_state(Service *s, ServiceState state) { state != SERVICE_AUTO_RESTART) unit_unwatch_timer(UNIT(s), &s->timer_watch); - if (state != SERVICE_START_POST && + if (state != SERVICE_START && + state != SERVICE_START_POST && state != SERVICE_RUNNING && state != SERVICE_RELOAD && state != SERVICE_STOP && @@ -318,7 +338,7 @@ static int service_collect_fds(Service *s, int **fds, unsigned *n_fds) { int *rfds = NULL; unsigned rn_fds = 0; Set *set; - Socket *socket; + Socket *sock; assert(s); assert(fds); @@ -327,11 +347,11 @@ static int service_collect_fds(Service *s, int **fds, unsigned *n_fds) { if ((r = service_get_sockets(s, &set)) < 0) return r; - SET_FOREACH(socket, set, i) { + SET_FOREACH(sock, set, i) { int *cfds; unsigned cn_fds; - if ((r = socket_collect_fds(socket, &cfds, &cn_fds)) < 0) + if ((r = socket_collect_fds(sock, &cfds, &cn_fds)) < 0) goto fail; if (!cfds) @@ -590,6 +610,13 @@ static void service_enter_start(Service *s) { s->control_pid = pid; s->control_command = s->exec_command[SERVICE_EXEC_START]; + } else if (s->type == SERVICE_FINISH) { + + /* For finishing services we wait until the start + * process exited, too, but it is our main process. */ + + s->main_pid = pid; + s->control_command = s->exec_command[SERVICE_EXEC_START]; } else assert_not_reached("Unknown service type"); @@ -806,7 +833,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { exec_status_fill(&s->main_exec_status, pid, code, status); s->main_pid = 0; - if (s->type == SERVICE_SIMPLE) { + if (s->type == SERVICE_SIMPLE || s->type == SERVICE_FINISH) { assert(s->exec_command[SERVICE_EXEC_START]); s->exec_command[SERVICE_EXEC_START]->exec_status = s->main_exec_status; } @@ -825,6 +852,16 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { * done */ break; + case SERVICE_START: + assert(s->type == SERVICE_FINISH); + + /* This was our main goal, so let's go on */ + if (success) + service_enter_start_post(s); + else + service_enter_stop(s, false); + break; + case SERVICE_RUNNING: service_enter_stop(s, success); break;