// Handle errors
if (bytes_read < 0) {
- ERROR(pakfire, "Could not read from fd %d: %s\n", fd, strerror(errno));
+ ERROR(pakfire, "Could not read from fd %d: %m\n", fd);
return -1;
}
// Setup epoll
epollfd = epoll_create1(0);
if (epollfd < 0) {
- ERROR(pakfire, "Could not initialize epoll(): %s\n", strerror(errno));
+ ERROR(pakfire, "Could not initialize epoll(): %m\n");
r = -errno;
goto OUT;
}
// Set modified flags
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
- ERROR(pakfire, "Could not set file descriptor %d into non-blocking mode: %s\n",
- fd, strerror(errno));
+ ERROR(pakfire, "Could not set file descriptor %d into non-blocking mode: %m\n",
+ fd);
r = -errno;
goto OUT;
}
ev.data.fd = fd;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) < 0) {
- ERROR(pakfire, "Could not add file descriptor %d to epoll(): %s\n",
- fd, strerror(errno));
+ ERROR(pakfire, "Could not add file descriptor %d to epoll(): %m\n", fd);
r = -errno;
goto OUT;
}
int fds = epoll_wait(epollfd, events, EPOLL_MAX_EVENTS, -1);
if (fds < 1) {
- ERROR(pakfire, "epoll_wait() failed: %s\n", strerror(errno));
+ ERROR(pakfire, "epoll_wait() failed: %m\n");
r = -errno;
goto OUT;
if (strcmp(root, "/") != 0) {
int r = chroot(root);
if (r) {
- ERROR(pakfire, "chroot() to %s failed: %s\n", root, strerror(errno));
+ ERROR(pakfire, "chroot() to %s failed: %m\n", root);
return 1;
}
r = chdir("/");
if (r) {
- ERROR(pakfire, "chdir() after chroot() failed: %s\n", strerror(errno));
+ ERROR(pakfire, "chdir() after chroot() failed: %m\n");
return 1;
}
}
// Connect standard output and error
if (env->stdout[1] && env->stderr[1]) {
if (dup2(env->stdout[1], STDOUT_FILENO) < 0) {
- ERROR(pakfire, "Could not connect fd %d to stdout: %s\n",
- env->stdout[1], strerror(errno));
+ ERROR(pakfire, "Could not connect fd %d to stdout: %m\n",
+ env->stdout[1]);
return 1;
}
if (dup2(env->stderr[1], STDERR_FILENO) < 0) {
- ERROR(pakfire, "Could not connect fd %d to stderr: %s\n",
- env->stderr[1], strerror(errno));
+ ERROR(pakfire, "Could not connect fd %d to stderr: %m\n",
+ env->stderr[1]);
return 1;
}
// exec() command
r = execvpe(env->argv[0], (char**)env->argv, env->envp);
if (r < 0) {
- ERROR(pakfire, "Could not execve(): %s\n", strerror(errno));
+ ERROR(pakfire, "Could not execve(): %m\n");
}
// Translate errno into regular exit code
// Make some file descriptors for stdout & stderr
} else {
if (pipe(env.stdout) < 0) {
- ERROR(pakfire, "Could not create file descriptors for stdout: %s\n",
- strerror(errno));
+ ERROR(pakfire, "Could not create file descriptors for stdout: %m\n");
r = -1;
goto ERROR;
}
if (pipe(env.stderr) < 0) {
- ERROR(pakfire, "Could not create file descriptors for stderr: %s\n",
- strerror(errno));
+ ERROR(pakfire, "Could not create file descriptors for stderr: %m\n");
r = -1;
goto ERROR;
}
// Create cgroup
r = pakfire_cgroup_create(pakfire, env.cgroup);
if (r) {
- ERROR(pakfire, "Could not create cgroup %s: %s\n", env.cgroup, strerror(errno));
+ ERROR(pakfire, "Could not create cgroup %s: %m\n", env.cgroup);
goto ERROR;
}
// Launch the new process straight into their cgroup
cgroupdir = pakfire_cgroup_opendir(pakfire, env.cgroup);
if (!cgroupdir) {
- ERROR(pakfire, "Could not open cgroup %s: %s\n", env.cgroup, strerror(errno));
+ ERROR(pakfire, "Could not open cgroup %s: %m\n", env.cgroup);
goto ERROR;
}
// Fork this process
pid_t pid = syscall(__NR_clone3, &args, sizeof(args));
if (pid < 0) {
- ERROR(pakfire, "Could not fork: %s\n", strerror(errno));
+ ERROR(pakfire, "Could not fork: %m\n");
return -errno;
// Child process
close(env.stderr[1]);
if (pakfire_execute_logger(pakfire, logging_callback, data, pid, env.stdout[0], env.stderr[0], &status)) {
- ERROR(pakfire, "Log reading aborted: %s\n", strerror(errno));
+ ERROR(pakfire, "Log reading aborted: %m\n");
}
}
// Fetch CPU usage stats
r = pakfire_cgroup_cpustat(pakfire, env.cgroup, &cpustat);
if (r) {
- ERROR(pakfire, "Could not read CPU usage stats: %s\n", strerror(errno));
+ ERROR(pakfire, "Could not read CPU usage stats: %m\n");
r = -1;
goto ERROR;
}
// Open a temporary file
int fd = mkstemp(path);
if (fd < 0) {
- ERROR(pakfire, "Could not open a temporary file: %s\n",
- strerror(errno));
-
+ ERROR(pakfire, "Could not open a temporary file: %m\n");
r = errno;
}
// Write data
ssize_t bytes_written = write(fd, script, size);
if (bytes_written < (ssize_t)size) {
- ERROR(pakfire, "Could not write script to file %s: %s\n",
- path, strerror(errno));
-
+ ERROR(pakfire, "Could not write script to file %s: %m\n", path);
r = errno;
goto out;
}
// Make the script executable
r = fchmod(fd, S_IRUSR|S_IWUSR|S_IXUSR);
if (r) {
- ERROR(pakfire, "Could not set executable permissions on %s: %s\n",
- path, strerror(errno));
-
+ ERROR(pakfire, "Could not set executable permissions on %s: %m\n", path);
r = errno;
goto out;
}
// Close file
r = close(fd);
if (r) {
- ERROR(pakfire, "Could not close script file %s: %s\n",
- path, strerror(errno));
-
+ ERROR(pakfire, "Could not close script file %s: %m\n", path);
r = errno;
goto out;
}
argv = calloc(argc + 1, sizeof(*argv));
if (!argv) {
- ERROR(pakfire, "Could not allocate argv: %s\n", strerror(errno));
+ ERROR(pakfire, "Could not allocate argv: %m\n");
goto out;
}