return 0;
}
-static int pakfire_jail_SIGTERM(
- sd_event_source* source, const struct signalfd_siginfo* si, void* data) {
- struct pakfire_jail_exec* ctx = data;
- struct pakfire_jail* self = ctx->jail;
+/*
+ Immediately terminates the process that is running inside the jail
+*/
+static int pakfire_jail_terminate(sd_event_source* source,
+ const struct signalfd_siginfo* si, void* data) {
+ struct pakfire_jail_exec* exec = data;
+ struct pakfire_jail* self = exec->jail;
int r;
// Log action
- DEBUG(self->ctx, "Received SIGTERM\n");
+ DEBUG(self->ctx, "Received %s\n", strsignal(si->ssi_signo));
// Fail if we don't have a PID file descriptor
- if (ctx->pidfd < 0)
+ if (exec->pidfd < 0)
return -ENOTSUP;
// Send a signal to the child process
- r = pidfd_send_signal(ctx->pidfd, SIGKILL, NULL, 0);
+ r = pidfd_send_signal(exec->pidfd, SIGKILL, NULL, 0);
if (r < 0) {
ERROR(self->ctx, "Could not terminate jail: %m\n");
return -errno;
}
- return 0;
+ return sd_event_exit(exec->loop, 128 + si->ssi_signo);
}
/*
// Listen for SIGTERM
r = sd_event_add_signal(ctx.loop, NULL, SIGTERM|SD_EVENT_SIGNAL_PROCMASK,
- pakfire_jail_SIGTERM, &ctx);
+ pakfire_jail_terminate, &ctx);
if (r < 0) {
ERROR(jail->ctx, "Failed to register SIGTERM: %s\n", strerror(-r));
goto ERROR;
}
+ // Listen for SIGINT
+ r = sd_event_add_signal(ctx.loop, NULL, SIGINT|SD_EVENT_SIGNAL_PROCMASK,
+ pakfire_jail_terminate, &ctx);
+ if (r < 0) {
+ ERROR(jail->ctx, "Failed to register SIGINT: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
// Set the size for the input buffer
pakfire_buffer_set_max_length(&ctx.stdin, 4096);