Skip to content
Snippets Groups Projects
Commit 77758a68 authored by Moe Jette's avatar Moe Jette
Browse files
parent 7d45ed74
No related branches found
No related tags found
No related merge requests found
......@@ -168,6 +168,9 @@ documents those changes that are of interest to users and admins.
* Changes in SLURM 2.1.7
========================
-- Modify srun, salloc and sbatch parsing for the --signal option to accept
either a signal name in addition to the previously supported signal
numbers (e.g. "--signal=USR2@200").
* Changes in SLURM 2.1.6-2
==========================
......
......@@ -757,8 +757,8 @@ When a job is within \fIsig_time\fR seconds of its end time,
send it the signal \fIsig_num\fR.
Due to the resolution of event handling by SLURM, the signal may
be sent up to 60 seconds earlier than specified.
Both \fIsig_time\fR and \fIsig_num\fR must have integer values
between zero and 65535.
\fIsig_num\fR may either be a signal number or name (e.g. "10" or "USR1").
\fIsig_time\fR must have integer value between zero and 65535.
By default, no signal is sent before the job's end time.
If a \fIsig_num\fR is specified without any \fIsig_time\fR,
the default time will be 60 seconds.
......
......@@ -841,8 +841,8 @@ When a job is within \fIsig_time\fR seconds of its end time,
send it the signal \fIsig_num\fR.
Due to the resolution of event handling by SLURM, the signal may
be sent up to 60 seconds earlier than specified.
Both \fIsig_time\fR and \fIsig_num\fR must have integer values
between zero and 65535.
\fIsig_num\fR may either be a signal number or name (e.g. "10" or "USR1").
\fIsig_time\fR must have integer value between zero and 65535.
By default, no signal is sent before the job's end time.
If a \fIsig_num\fR is specified without any \fIsig_time\fR,
the default time will be 60 seconds.
......
......@@ -953,8 +953,8 @@ When a job is within \fIsig_time\fR seconds of its end time,
send it the signal \fIsig_num\fR.
Due to the resolution of event handling by SLURM, the signal may
be sent up to 60 seconds earlier than specified.
Both \fIsig_time\fR and \fIsig_num\fR must have integer values
between zero and 65535.
\fIsig_num\fR may either be a signal number or name (e.g. "10" or "USR1").
\fIsig_time\fR must have integer value between zero and 65535.
By default, no signal is sent before the job's end time.
If a \fIsig_num\fR is specified without any \fIsig_time\fR,
the default time will be 60 seconds.
......
......@@ -753,17 +753,20 @@ int get_signal_opts(char *optarg, uint16_t *warn_signal, uint16_t *warn_time)
if (optarg == NULL)
return -1;
num = strtol(optarg, &endptr, 10);
if ((num < 0) || (num > 0x0ffff))
endptr = strchr(optarg, '@');
if (endptr)
endptr[0] = '\0';
num = (uint16_t) sig_name2num(optarg);
if (endptr)
endptr[0] = '@';
if ((num < 1) || (num > 0x0ffff))
return -1;
*warn_signal = (uint16_t) num;
if (endptr[0] == '\0') {
if (!endptr) {
*warn_time = 60;
return 0;
}
if (endptr[0] != '@')
return -1;
num = strtol(endptr+1, &endptr, 10);
if ((num < 0) || (num > 0x0ffff))
......@@ -773,3 +776,46 @@ int get_signal_opts(char *optarg, uint16_t *warn_signal, uint16_t *warn_time)
return 0;
return -1;
}
/* Convert a signal name to it's numeric equivalent.
* Return -1 on failure */
int sig_name2num(char *signal_name)
{
char *sig_name[] = {"HUP", "INT", "QUIT", "KILL", "TERM",
"USR1", "USR2", "CONT", NULL};
int sig_num[] = {SIGHUP, SIGINT, SIGQUIT, SIGKILL, SIGTERM,
SIGUSR1, SIGUSR2, SIGCONT};
char *ptr;
long tmp;
int sig;
int i;
tmp = strtol(signal_name, &ptr, 10);
if (ptr != signal_name) { /* found a number */
if (xstring_is_whitespace(ptr))
sig = (int)tmp;
else
return 0;
} else {
ptr = (char *)signal_name;
while (isspace(*ptr))
ptr++;
if (strncasecmp(ptr, "SIG", 3) == 0)
ptr += 3;
for (i = 0; ; i++) {
if (sig_name[i] == NULL)
return 0;
if (strncasecmp(ptr, sig_name[i],
strlen(sig_name[i])) == 0) {
/* found the signal name */
if (!xstring_is_whitespace(ptr +
strlen(sig_name[i])))
return 0;
sig = sig_num[i];
break;
}
}
}
return sig;
}
......@@ -132,4 +132,8 @@ char *print_geometry(const uint16_t *geometry);
* RET 0 on success, -1 on failure */
int get_signal_opts(char *optarg, uint16_t *warn_signal, uint16_t *warn_time);
/* Convert a signal name to it's numeric equivalent.
* Return 0 on failure */
int sig_name2num(char *signal_name);
#endif /* !_PROC_ARGS_H */
......@@ -189,7 +189,6 @@ static bool _opt_verify(void);
static void _proc_get_user_env(char *optarg);
static void _process_env_var(env_vars_t *e, const char *val);
static int _parse_signal(const char *signal_name);
static void _usage(void);
/*---[ end forward declarations of static functions ]---------------------*/
......@@ -741,9 +740,11 @@ void set_options(const int argc, char **argv)
break;
case 'K': /* argument is optional */
if (optarg) {
opt.kill_command_signal =_parse_signal(optarg);
if (opt.kill_command_signal == 0)
opt.kill_command_signal = sig_name2num(optarg);
if (opt.kill_command_signal == 0) {
error("Invalid signal name %s", optarg);
exit(error_exit);
}
}
opt.kill_command_signal_set = true;
break;
......@@ -1581,61 +1582,6 @@ static char *print_constraints()
return buf;
}
/*
* Takes a string containing the number or name of a signal and returns
* the signal number. The signal name is case insensitive, and may be of
* the form "SIGHUP" or just "HUP".
*
* Allowed signal names are HUP, INT, QUIT, KILL, TERM, USR1, USR2, and CONT.
*/
static int _parse_signal(const char *signal_name)
{
char *sig_name[] = {"HUP", "INT", "QUIT", "KILL", "TERM",
"USR1", "USR2", "CONT", NULL};
int sig_num[] = {SIGHUP, SIGINT, SIGQUIT, SIGKILL, SIGTERM,
SIGUSR1, SIGUSR2, SIGCONT};
char *ptr;
long tmp;
int sig;
int i;
tmp = strtol(signal_name, &ptr, 10);
if (ptr != signal_name) { /* found a number */
if (xstring_is_whitespace(ptr)) {
sig = (int)tmp;
} else {
goto fail;
}
} else {
ptr = (char *)signal_name;
while (isspace(*ptr))
ptr++;
if (strncasecmp(ptr, "SIG", 3) == 0)
ptr += 3;
for (i = 0; ; i++) {
if (sig_name[i] == NULL) {
goto fail;
}
if (strncasecmp(ptr, sig_name[i],
strlen(sig_name[i])) == 0) {
/* found the signal name */
if (!xstring_is_whitespace(
ptr + strlen(sig_name[i]))) {
goto fail;
}
sig = sig_num[i];
break;
}
}
}
return sig;
fail:
error("\"%s\" is not a valid signal", signal_name);
return 0;
}
#define tf_(b) (b == true) ? "true" : "false"
static void _opt_list()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment