+ default:
+ assert_not_reached("Uh, main process died at wrong time.");
+ }
+
+ } else if (s->control_pid == pid) {
+ assert(s->control_command);
+
+ exec_status_fill(&s->control_command->exec_status, pid, code, status);
+ s->control_pid = 0;
+
+ log_debug("%s: control process exited, code=%s status=%i", unit_id(u), sigchld_code(code), status);
+
+ /* If we are shutting things down anyway we
+ * don't care about failing commands. */
+
+ if (s->control_command->command_next &&
+ (success || (s->state == SERVICE_EXEC_STOP || s->state == SERVICE_EXEC_STOP_POST)))
+
+ /* There is another command to *
+ * execute, so let's do that. */
+
+ service_run_next(s, success);
+
+ else {
+ /* No further commands for this step, so let's
+ * figure out what to do next */
+
+ log_debug("%s got final SIGCHLD for state %s", unit_id(u), state_string_table[s->state]);
+
+ switch (s->state) {
+
+ case SERVICE_START_PRE:
+ if (success)
+ service_enter_start(s);
+ else
+ service_enter_stop(s, false);
+ break;
+
+ case SERVICE_START:
+ assert(s->type == SERVICE_FORKING);
+
+ /* Let's try to load the pid
+ * file here if we can. We
+ * ignore the return value,
+ * since the PID file might
+ * actually be created by a
+ * START_POST script */
+
+ if (success) {
+ if (s->pid_file)
+ service_load_pid_file(s);
+
+ service_enter_start_post(s);
+ } else
+ service_enter_stop(s, false);
+
+ break;
+
+ case SERVICE_START_POST:
+ if (success && s->pid_file && !s->main_pid_known) {
+ int r;
+
+ /* Hmm, let's see if we can
+ * load the pid now after the
+ * start-post scripts got
+ * executed. */
+
+ if ((r = service_load_pid_file(s)) < 0)
+ log_warning("%s: failed to load PID file %s: %s", unit_id(UNIT(s)), s->pid_file, strerror(-r));
+ }
+
+ /* Fall through */
+
+ case SERVICE_RELOAD:
+ if (success) {
+ if (main_pid_good(s) != 0)
+ service_set_state(s, SERVICE_RUNNING);
+ else
+ service_enter_stop(s, true);
+ } else
+ service_enter_stop(s, false);
+
+ break;
+
+ case SERVICE_STOP:
+ if (main_pid_good(s) > 0)
+ /* Still not dead and we know the PID? Let's go hunting. */
+ service_enter_signal(s, SERVICE_STOP_SIGTERM, success);
+ else
+ service_enter_stop_post(s, success);
+ break;
+
+ case SERVICE_STOP_SIGTERM:
+ case SERVICE_STOP_SIGKILL:
+ if (main_pid_good(s) <= 0)
+ service_enter_stop_post(s, success);
+
+ /* If there is still a service
+ * process around, wait until
+ * that one quit, too */
+ break;
+
+ case SERVICE_STOP_POST:
+ case SERVICE_FINAL_SIGTERM:
+ case SERVICE_FINAL_SIGKILL:
+ service_enter_dead(s, success, true);
+ break;
+
+ default:
+ assert_not_reached("Uh, control process died at wrong time.");
+ }
+ }
+ } else
+ assert_not_reached("Got SIGCHLD for unkown PID");