if (nsjconf->is_silent == false) {
return true;
}
- if ((fd_in = fd_out = fd_err = open("/dev/null", O_RDWR)) == -1) {
+ if (TEMP_FAILURE_RETRY(fd_in = fd_out = fd_err = open("/dev/null", O_RDWR)) == -1) {
PLOG_E("open('/dev/null', O_RDWR)");
return false;
}
}
/* Set stdin/stdout/stderr to the net */
- if (dup2(fd_in, STDIN_FILENO) == -1) {
+ if (TEMP_FAILURE_RETRY(dup2(fd_in, STDIN_FILENO)) == -1) {
PLOG_E("dup2(%d, STDIN_FILENO)", fd_in);
return false;
}
- if (dup2(fd_out, STDOUT_FILENO) == -1) {
+ if (TEMP_FAILURE_RETRY(dup2(fd_out, STDOUT_FILENO)) == -1) {
PLOG_E("dup2(%d, STDOUT_FILENO)", fd_out);
return false;
}
- if (dup2(fd_err, STDERR_FILENO) == -1) {
+ if (TEMP_FAILURE_RETRY(dup2(fd_err, STDERR_FILENO)) == -1) {
PLOG_E("dup2(%d, STDERR_FILENO)", fd_err);
return false;
}
if (logfile == NULL) {
logfile = "/proc/self/fd/2";
}
- log_fd = open(logfile, O_CREAT | O_RDWR | O_APPEND, 0640);
- if (log_fd == -1) {
+ if (TEMP_FAILURE_RETRY(log_fd = open(logfile, O_CREAT | O_RDWR | O_APPEND, 0640)) == -1) {
log_fd = STDERR_FILENO;
PLOG_E("Couldn't open logfile open('%s')", logfile);
return false;
}
if (mountNotIsDir(mpt->src) == true) {
- int fd = open(dst, O_CREAT | O_RDONLY, 0644);
+ int fd = TEMP_FAILURE_RETRY(open(dst, O_CREAT | O_RDONLY, 0644));
if (fd >= 0) {
- close(fd);
+ TEMP_FAILURE_RETRY(close(fd));
} else {
PLOG_W("open('%s', O_CREAT|O_RDONLY, 0700)", dst);
}
static bool mountRemountRO(struct mounts_t *mpt)
{
struct statvfs vfs;
- if (statvfs(mpt->dst, &vfs) == -1) {
+ if (TEMP_FAILURE_RETRY(statvfs(mpt->dst, &vfs)) == -1) {
PLOG_E("statvfs('%s')", mpt->dst);
return false;
}
#include "user.h"
#include "util.h"
-const char subprocDoneChar = 'D';
+static const char subprocDoneChar = 'D';
static int subprocNewProc(struct nsjconf_t *nsjconf, int fd_in, int fd_out, int fd_err, int pipefd)
{
char fname[PATH_MAX];
snprintf(fname, sizeof(fname), "/proc/%d/syscall", (int)pid);
- p->pid_syscall_fd = open(fname, O_RDONLY);
+ p->pid_syscall_fd = TEMP_FAILURE_RETRY(open(fname, O_RDONLY));
TAILQ_INSERT_HEAD(&nsjconf->pids, p, pointers);
}
LOG_W
- ("Syscall number: %d, Arguments: %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, SP: %#lx, PC: %#lx", sc,
- arg1, arg2, arg3, arg4, arg5, arg6, sp, pc);
+ ("PID: %d, Syscall number: %d, Arguments: %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, SP: %#lx, PC: %#lx",
+ (int)si->si_pid, sc, arg1, arg2, arg3, arg4, arg5, arg6, sp, pc);
}
int subprocReap(struct nsjconf_t *nsjconf)
ssize_t utilReadFromFile(const char *fname, void *buf, size_t len)
{
- int fd = open(fname, O_RDONLY);
+ int fd;
+ TEMP_FAILURE_RETRY(fd = open(fname, O_RDONLY));
if (fd == -1) {
LOG_E("open('%s', O_RDONLY)", fname);
return -1;
}
defer {
- close(fd);
+ TEMP_FAILURE_RETRY(close(fd));
}
return utilReadFromFd(fd, buf, len);
}
bool utilWriteBufToFile(char *filename, const void *buf, size_t len, int open_flags)
{
- int fd = open(filename, open_flags, 0644);
+ int fd;
+ TEMP_FAILURE_RETRY(fd = open(filename, open_flags, 0644));
if (fd == -1) {
PLOG_E("Couldn't open '%s' for R/O", filename);
return false;
}
defer {
- close(fd);
+ TEMP_FAILURE_RETRY(close(fd));
};
if (utilWriteToFd(fd, buf, len) == false) {