#include <sys/personality.h>
#include <sys/prctl.h>
#include <sys/resource.h>
-#include <sys/signalfd.h>
#include <sys/timerfd.h>
#include <sys/types.h>
#include <sys/wait.h>
return -1;
}
-// Signals
-
-#if 0
-static int pakfire_jail_handle_signals(struct pakfire_jail* jail) {
- sigset_t mask;
- int r;
-
- sigemptyset(&mask);
- sigaddset(&mask, SIGINT);
-
- // Block signals
- r = sigprocmask(SIG_BLOCK, &mask, NULL);
- if (r < 0) {
- ERROR(jail->pakfire, "Failed to block signals: %m\n");
- return r;
- }
-
- // Create a file descriptor
- r = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);
- if (r < 0) {
- ERROR(jail->pakfire, "Failed to create signalfd: %m\n");
- return r;
- }
-
- return r;
-}
-#endif
-
/*
This function replaces any logging in the child process.
const int log_DEBUG = pakfire_jail_get_pipe_to_read(jail, &ctx->pipes.log_DEBUG);
#endif /* ENABLE_DEBUG */
-#if 0
- // Signals
- const int signalfd = pakfire_jail_handle_signals(jail);
-#endif
-
// Make a list of all file descriptors we are interested in
const struct pakfire_wait_fds {
const int fd;
// Child Processes
{ ctx->pidfd1, EPOLLIN },
-#if 0
- // Signals
- { signafd, EPOLLIN },
-#endif
-
// Log Pipes
{ log_INFO, EPOLLIN },
{ log_ERROR, EPOLLIN },
// There is nothing else to do
continue;
-#if 0
- // Handle signals
- } else if (fd == signalfd) {
- // Read the signal
- r = read(signalfd, &siginfo, sizeof(siginfo));
- if (r < 1) {
- ERROR(jail->pakfire, "Could not read signal: %m\n");
- goto ERROR;
- }
-
- DEBUG(jail->pakfire, "Received signal %u\n", siginfo.ssi_signo);
-
- // Handle signals
- switch (siginfo.ssi_signo) {
- // Pass SIGINT down to the child process
- case SIGINT:
- r = pidfd_send_signal(pidfd, siginfo.ssi_signo, NULL, 0);
- if (r) {
- ERROR(jail->pakfire, "Could not send signal to process: %m\n");
- goto ERROR;
- }
- break;
-
- default:
- ERROR(jail->pakfire, "Received unhandled signal %u\n",
- siginfo.ssi_signo);
- break;
- }
-
- // Don't fall through to log processing
- continue;
-#endif
-
// Handle socket messages
} else if (fd == socket_recv) {
// Receive the FD of the second child process
close(epollfd);
if (timerfd >= 0)
close(timerfd);
-#if 0
- if (signalfd >= 0)
- close(signalfd);
-#endif
return r;
}
"0 %lu %lu\n", subgid->id, subgid->length);
} else {
r = pakfire_file_write(jail->pakfire, path, 0, 0, 0,
- "0 %lu 1\n%1 %lu %lu\n", gid, subgid->id, subgid->length);
+ "0 %lu 1\n1 %lu %lu\n", gid, subgid->id, subgid->length);
}
if (r) {
CTX_DEBUG(jail->ctx, "Launched child process in jail with PID %d\n", pid);
- // Die with parent
- r = prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
- if (r) {
- CTX_ERROR(jail->ctx, "Could not configure to die with parent: %m\n");
- return 126;
- }
-
// Make this process dumpable
r = prctl (PR_SET_DUMPABLE, 1, 0, 0, 0);
if (r) {
// Fail if we are not PID 1
if (pid != 1) {
CTX_ERROR(jail->ctx, "Child process is not PID 1\n");
- //return 126;
+ return 126;
}
// Fail if we are not running as root
if (uid || gid || euid || egid) {
ERROR(jail->pakfire, "Child process is not running as root\n");
- //return 126;
+ return 126;
}
const char* arch = pakfire_get_effective_arch(jail->pakfire);
ERROR:
// Destroy the temporary cgroup (if any)
if (ctx.cgroup) {
-#if 0
- // XXX this is currently disabled because it overwrites r
// Read cgroup stats
- r = pakfire_cgroup_stat(ctx.cgroup, &ctx.cgroup_stats);
- if (r) {
- ERROR(jail->pakfire, "Could not read cgroup stats: %m\n");
- } else {
- pakfire_cgroup_stat_dump(ctx.cgroup, &ctx.cgroup_stats);
- }
-#endif
-
+ pakfire_cgroup_stat(ctx.cgroup, &ctx.cgroup_stats);
+ pakfire_cgroup_stat_dump(ctx.cgroup, &ctx.cgroup_stats);
pakfire_cgroup_destroy(ctx.cgroup);
pakfire_cgroup_unref(ctx.cgroup);
}