[RFC] stopsignal stanza
Marc - A. Dahlhaus
mad at wol.de
Mon May 2 19:32:06 UTC 2011
Am 02.05.2011 20:37, schrieb Marc - A. Dahlhaus:
--8<--
>> system_send_signal () is less yoda ;-)
>
> Looks like more of the force is needed to get such things into the code...
>
>> Scott
>
A first version...
I did not change the testsuite for now so it doesn't compile for now on
make check...
Is it ok so far?
diff -Nurp a/init/job_class.c b/init/job_class.c
--- a/init/job_class.c 2011-03-16 23:34:18.000000000 +0100
+++ b/init/job_class.c 2011-05-02 21:07:01.000000000 +0200
@@ -26,6 +26,7 @@
#include <errno.h>
#include <string.h>
+#include <signal.h>
#include <nih/macros.h>
#include <nih/alloc.h>
@@ -199,6 +200,7 @@ job_class_new (const void *parent,
class->task = FALSE;
class->kill_timeout = JOB_DEFAULT_KILL_TIMEOUT;
+ class->kill_signal = SIGTERM;
class->respawn = FALSE;
class->respawn_limit = JOB_DEFAULT_RESPAWN_LIMIT;
diff -Nurp a/init/job_class.h b/init/job_class.h
--- a/init/job_class.h 2011-03-15 19:35:29.000000000 +0100
+++ b/init/job_class.h 2011-05-02 21:06:06.000000000 +0200
@@ -129,6 +129,7 @@ typedef struct job_class {
int task;
time_t kill_timeout;
+ int kill_signal;
int respawn;
int respawn_limit;
diff -Nurp a/init/job_process.c b/init/job_process.c
--- a/init/job_process.c 2011-03-22 18:18:00.000000000 +0100
+++ b/init/job_process.c 2011-05-02 21:20:01.000000000 +0200
@@ -785,12 +785,13 @@ job_process_kill (Job *job,
nih_info (_("Sending TERM signal to %s %s process (%d)"),
job_name (job), process_name (process), job->pid[process]);
- if (system_kill (job->pid[process], FALSE) < 0) {
+ if (system_send_signal (job->pid[process], job->class->kill_signal) < 0) {
NihError *err;
err = nih_error_get ();
if (err->number != ESRCH)
- nih_warn (_("Failed to send TERM signal to %s %s process (%d): %s"),
+ nih_warn (_("Failed to send %s signal to %s %s process (%d): %s"),
+ nih_signal_to_name (job->class->kill_signal),
job_name (job), process_name (process),
job->pid[process], err->message);
nih_free (err);
@@ -833,7 +834,7 @@ job_process_kill_timer (Job *job,
nih_info (_("Sending KILL signal to %s %s process (%d)"),
job_name (job), process_name (process), job->pid[process]);
- if (system_kill (job->pid[process], TRUE) < 0) {
+ if (system_send_signal (job->pid[process], SIGKILL) < 0) {
NihError *err;
err = nih_error_get ();
diff -Nurp a/init/parse_job.c b/init/parse_job.c
--- a/init/parse_job.c 2011-03-15 19:41:10.000000000 +0100
+++ b/init/parse_job.c 2011-05-02 21:01:24.000000000 +0200
@@ -1782,6 +1782,7 @@ stanza_kill (JobClass *class,
{
size_t a_pos, a_lineno;
int ret = -1;
+ char *endptr;
nih_local char *arg = NULL;
nih_assert (class != NULL);
@@ -1799,7 +1800,6 @@ stanza_kill (JobClass *class,
if (! strcmp (arg, "timeout")) {
nih_local char *timearg = NULL;
- char *endptr;
/* Update error position to the timeout value */
*pos = a_pos;
@@ -1816,14 +1816,40 @@ stanza_kill (JobClass *class,
if (errno || *endptr || (class->kill_timeout < 0))
nih_return_error (-1, PARSE_ILLEGAL_INTERVAL,
_(PARSE_ILLEGAL_INTERVAL_STR));
+ } else if (! strcmp (arg, "signal")) {
+ unsigned long status;
+ nih_local char *sigarg = NULL;
+ int signal
- ret = nih_config_skip_comment (file, len, &a_pos, &a_lineno);
+ /* Update error position to the exit status */
+ *pos = a_pos;
+ if (lineno)
+ *lineno = a_lineno;
+
+ sigarg = nih_config_next_arg (NULL, file, len, &a_pos,
+ &a_lineno);
+ if (! sigarg)
+ goto finish;
+
+ signal = nih_signal_from_name (exitarg);
+ if (signal < 0) {
+ errno = 0;
+ status = strtoul (sigarg, &endptr, 10);
+ if (errno || *endptr || (status > INT_MAX))
+ nih_return_error (-1, PARSE_ILLEGAL_EXIT,
+ _(PARSE_ILLEGAL_EXIT_STR));
+ }
+
+ /* Set the signal */
+ class->kill_signal = signal;
} else {
nih_return_error (-1, NIH_CONFIG_UNKNOWN_STANZA,
_(NIH_CONFIG_UNKNOWN_STANZA_STR));
}
+ ret = nih_config_skip_comment (file, len, &a_pos, &a_lineno);
+
finish:
*pos = a_pos;
if (lineno)
diff -Nurp a/init/system.c b/init/system.c
--- a/init/system.c 2011-02-01 19:42:30.000000000 +0100
+++ b/init/system.c 2011-05-02 21:24:06.000000000 +0200
@@ -46,29 +46,23 @@
/**
- * system_kill:
+ * system_send_signal:
* @pid: process id of process,
- * @force: force the death.
+ * @signal: signal to send.
*
- * Kill all processes in the same process group as @pid, which may not
- * necessarily be the group leader.
- *
- * When @force is FALSE, the TERM signal is sent; when it is TRUE, KILL
- * is sent instead.
+ * Send all processes in the same process group as @pid, which may not
+ * necessarily be the group leader the @signal.
*
* Returns: zero on success, negative value on raised error.
**/
int
-system_kill (pid_t pid,
- int force)
+system_send_signal (pid_t pid,
+ int signal)
{
- int signal;
pid_t pgid;
nih_assert (pid > 0);
- signal = (force ? SIGKILL : SIGTERM);
-
pgid = getpgid (pid);
if (kill (pgid > 0 ? -pgid : pid, signal) < 0)
diff -Nurp a/init/system.h b/init/system.h
--- a/init/system.h 2011-02-01 19:42:30.000000000 +0100
+++ b/init/system.h 2011-05-02 21:02:25.000000000 +0200
@@ -29,7 +29,7 @@
NIH_BEGIN_EXTERN
-int system_kill (pid_t pid, int force)
+int system_send_signal (pid_t pid, int signal)
__attribute__ ((warn_unused_result));
int system_setup_console (ConsoleType type, int reset)
More information about the upstart-devel
mailing list