#endif
#define STACK_SIZE (1024 * 1024)
-#define OPT_ARGS "cC:d:e:EfFG:h:ij:J:ln:NoO:pP:r:R:sS:uU:w:T:y"
+#define OPT_ARGS "cC:d:e:EfFG:h:ij:J:ln:NoO:pP:r:R:sS:uU:w:t:T:y"
#define OCI_VERSION_STRING "1.0.2"
char *ocibundle;
bool immediately;
struct blob_attr *annotations;
+ int term_timeout;
} opts;
static struct blob_buf ocibuf;
if (hook_running) {
DEBUG("forwarding signal %d to the hook process\n", signo);
kill(hook_process.pid, signo);
+ /* set timeout to send SIGKILL hook process in case SIGTERM doesn't succeed */
+ if (signo == SIGTERM)
+ uloop_timeout_set(&hook_process_timeout, opts.term_timeout * 1000);
}
if (jail_running) {
DEBUG("forwarding signal %d to the jailed process\n", signo);
kill(jail_process.pid, signo);
+ /* set timeout to send SIGKILL jail process in case SIGTERM doesn't succeed */
+ if (signo == SIGTERM)
+ uloop_timeout_set(&jail_process_timeout, opts.term_timeout * 1000);
}
}
if (!sigismember(&sigmask, i))
continue;
- if ((i == SIGCHLD) || (i == SIGPIPE) || (i == SIGSEGV))
+ if ((i == SIGCHLD) || (i == SIGPIPE) || (i == SIGSEGV) || (i == SIGSTOP) || (i == SIGKILL))
continue;
s.sa_handler = jail_handle_signal;
opts.setns.time = -1;
#endif
+ /* default 5 seconds timeout after SIGTERM before SIGKILL is sent */
+ opts.term_timeout = 5;
+
umask(022);
mount_list_init();
init_library_search();
case 'O':
opts.overlaydir = realpath(optarg, NULL);
break;
+ case 't':
+ opts.term_timeout = atoi(optarg);
+ break;
case 'T':
opts.tmpoverlaysize = optarg;
break;
static inline int
jail_run(struct service_instance *in, char **argv)
{
+ char *term_timeout_str;
struct blobmsg_list_node *var;
struct jail *jail = &in->jail;
int argc = 0;
argv[argc++] = UJAIL_BIN_PATH;
+ asprintf(&term_timeout_str, "%d", in->term_timeout);
+ argv[argc++] = "-t";
+ argv[argc++] = term_timeout_str;
+
if (jail->name) {
argv[argc++] = "-n";
argv[argc++] = jail->name;
in->halt = halt;
in->restart = in->respawn = false;
kill(in->proc.pid, SIGTERM);
- uloop_timeout_set(&in->timeout, in->term_timeout * 1000);
+ if (!in->has_jail)
+ uloop_timeout_set(&in->timeout, in->term_timeout * 1000);
}
static void
in->halt = true;
in->restart = true;
kill(in->proc.pid, SIGTERM);
- uloop_timeout_set(&in->timeout, in->term_timeout * 1000);
+ if (!in->has_jail)
+ uloop_timeout_set(&in->timeout, in->term_timeout * 1000);
}
static void
blobmsg_parse(jail_attr, __JAIL_ATTR_MAX, tb,
blobmsg_data(attr), blobmsg_data_len(attr));
- jail->argc = 2;
+ jail->argc = 4;
if (tb[JAIL_ATTR_REQUIREJAIL] && blobmsg_get_bool(tb[JAIL_ATTR_REQUIREJAIL])) {
in->require_jail = true;