Cover interruptible syscalls with TEMP_FAILURE_RETRY
authorRobert Swiecki <swiecki@google.com>
Mon, 9 May 2016 13:16:26 +0000 (15:16 +0200)
committerRobert Swiecki <swiecki@google.com>
Mon, 9 May 2016 13:16:26 +0000 (15:16 +0200)
contain.c
log.c
mount.c
subproc.c
util.c

index fdff21ec8fe6fe6a128db6056217d15b56ae1673..295d11d119df73cf05270e65bb151a7c77355ca9 100644 (file)
--- a/contain.c
+++ b/contain.c
@@ -259,21 +259,21 @@ bool containSetupFD(struct nsjconf_t * nsjconf, int fd_in, int fd_out, int fd_er
                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;
        }
diff --git a/log.c b/log.c
index e6ca5b45e3168c2189a01a7d293048cd8e0b5249..4f50dd606bc89282b5d1ac3ac73aceb21fc22e7d 100644 (file)
--- a/log.c
+++ b/log.c
@@ -54,8 +54,7 @@ bool logInitLogFile(struct nsjconf_t *nsjconf, const char *logfile, bool is_verb
        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;
diff --git a/mount.c b/mount.c
index 29604591244de41848cd23d8f4e762eb7944d7e9..6ce9614e7dc87332bb806ba762dc972b73671ccc 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -81,9 +81,9 @@ static bool mountMount(struct nsjconf_t *nsjconf, struct mounts_t *mpt, const ch
        }
 
        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);
                }
@@ -105,7 +105,7 @@ static bool mountMount(struct nsjconf_t *nsjconf, struct mounts_t *mpt, const ch
 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;
        }
index 8d7799852367c313a1f04f42ac3226b7c4220c0f..d74343d5b034fa78fe6c814a1a7c12887f5c8ced 100644 (file)
--- a/subproc.c
+++ b/subproc.c
@@ -47,7 +47,7 @@
 #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)
 {
@@ -106,7 +106,7 @@ static void subprocAdd(struct nsjconf_t *nsjconf, pid_t pid, int sock)
 
        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);
 
@@ -190,8 +190,8 @@ static void subprocSeccompViolation(struct nsjconf_t *nsjconf, siginfo_t * si)
        }
 
        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)
diff --git a/util.c b/util.c
index 442dcaa7446e812cbce7a1cff866deddd83fac0b..ba9b76bde4f3b3fd28b2e7f16d00961edb8cc970 100644 (file)
--- a/util.c
+++ b/util.c
@@ -59,13 +59,14 @@ ssize_t utilReadFromFd(int fd, void *buf, size_t len)
 
 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);
 }
@@ -90,13 +91,14 @@ ssize_t utilWriteToFd(int fd, const void *buf, size_t 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) {