+ assert(s);
+
+ cmd = make_message("%s %s/%s", conf.post_remove_hook_arg,
+ conf.dest_dir_arg, s->name);
+ DSS_NOTICE_LOG("executing %s\n", cmd);
+ dss_exec_cmdline_pid(&remove_pid, cmd);
+ free(cmd);
+ snapshot_removal_status = HS_POST_RUNNING;
+}
+
+static void dss_kill(pid_t pid, int sig, const char *msg)
+{
+ const char *signame, *process_name;
+
+ if (pid == 0)
+ return;
+ switch (sig) {
+ case SIGTERM: signame = "TERM"; break;
+ case SIGSTOP: signame = "STOP"; break;
+ case SIGCONT: signame = "CONT"; break;
+ default: signame = "????";
+ }
+
+ if (pid == create_pid)
+ process_name = "create";
+ else if (pid == remove_pid)
+ process_name = "remove";
+ else process_name = "??????";
+
+ if (msg)
+ DSS_INFO_LOG("%s\n", msg);
+ DSS_DEBUG_LOG("sending signal %d (%s) to pid %d (%s process)\n",
+ sig, signame, (int)pid, process_name);
+ if (kill(pid, sig) >= 0)
+ return;
+ DSS_INFO_LOG("failed to send signal %d (%s) to pid %d (%s process)\n",
+ sig, signame, (int)pid, process_name);
+}
+
+static void stop_create_process(void)
+{
+ if (create_process_stopped)
+ return;
+ dss_kill(create_pid, SIGSTOP, "suspending create process");
+ create_process_stopped = 1;
+}
+
+static void restart_create_process(void)
+{
+ if (!create_process_stopped)
+ return;
+ dss_kill(create_pid, SIGCONT, "resuming create process");
+ create_process_stopped = 0;
+}
+
+/**
+ * Print a log message about the exit status of a child.
+ */
+static void log_termination_msg(pid_t pid, int status)
+{
+ if (WIFEXITED(status))
+ DSS_INFO_LOG("child %i exited. Exit status: %i\n", (int)pid,
+ WEXITSTATUS(status));
+ else if (WIFSIGNALED(status))
+ DSS_NOTICE_LOG("child %i was killed by signal %i\n", (int)pid,
+ WTERMSIG(status));
+ else
+ DSS_WARNING_LOG("child %i terminated abormally\n", (int)pid);
+}
+
+static int wait_for_process(pid_t pid, int *status)
+{
+ int ret;
+
+ DSS_DEBUG_LOG("Waiting for process %d to terminate\n", (int)pid);
+ for (;;) {
+ fd_set rfds;
+
+ FD_ZERO(&rfds);
+ FD_SET(signal_pipe, &rfds);
+ ret = dss_select(signal_pipe + 1, &rfds, NULL, NULL);
+ if (ret < 0)
+ break;
+ ret = next_signal();
+ if (!ret)
+ continue;
+ if (ret == SIGCHLD) {
+ ret = waitpid(pid, status, 0);
+ if (ret >= 0)
+ break;
+ if (errno != EINTR) { /* error */
+ ret = -ERRNO_TO_DSS_ERROR(errno);
+ break;
+ }
+ }
+ /* SIGINT or SIGTERM */
+ dss_kill(pid, SIGTERM, "killing child process");
+ }
+ if (ret < 0)
+ DSS_ERROR_LOG("failed to wait for process %d\n", (int)pid);
+ else
+ log_termination_msg(pid, *status);