Restarts with interruptible syscalls
authorJagger <robert@swiecki.net>
Mon, 9 May 2016 21:11:18 +0000 (23:11 +0200)
committerJagger <robert@swiecki.net>
Mon, 9 May 2016 21:11:18 +0000 (23:11 +0200)
net.c
subproc.c

diff --git a/net.c b/net.c
index 4f8aebbf7689018cc571dfb5305feef59938e2b7..831079f1b5091fa0be281a059c521bac27e80b12 100644 (file)
--- a/net.c
+++ b/net.c
@@ -248,12 +248,12 @@ int netGetRecvSocket(const char *bindhost, int port)
                .sin6_scope_id = 0,
        };
        if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
-               close(sockfd);
+               TEMP_FAILURE_RETRY(close(sockfd));
                PLOG_E("bind(host:[%s], port:%d)", bindhost, port);
                return -1;
        }
        if (listen(sockfd, SOMAXCONN) == -1) {
-               close(sockfd);
+               TEMP_FAILURE_RETRY(close(sockfd));
                PLOG_E("listen(%d)", SOMAXCONN);
                return -1;
        }
@@ -269,7 +269,7 @@ int netAcceptConn(int listenfd)
 {
        struct sockaddr_in6 cli_addr;
        socklen_t socklen = sizeof(cli_addr);
-       int connfd = accept(listenfd, (struct sockaddr *)&cli_addr, &socklen);
+       int connfd = TEMP_FAILURE_RETRY(accept(listenfd, (struct sockaddr *)&cli_addr, &socklen));
        if (connfd == -1) {
                if (errno != EINTR) {
                        PLOG_E("accept(%d)", listenfd);
@@ -334,7 +334,7 @@ static bool netIfaceUp(const char *ifacename)
                return false;
        }
        defer {
-               close(sock);
+               TEMP_FAILURE_RETRY(close(sock));
        };
 
        struct ifreq ifr;
@@ -369,7 +369,7 @@ static bool netConfigureVs(struct nsjconf_t *nsjconf)
                return false;
        }
        defer {
-               close(sock);
+               TEMP_FAILURE_RETRY(close(sock));
        };
 
        if (inet_pton(AF_INET, nsjconf->iface_vs_ip, &addr) != 1) {
index d74343d5b034fa78fe6c814a1a7c12887f5c8ced..eb6958eaaf70a00352169183bb25ac362f44a464 100644 (file)
--- a/subproc.c
+++ b/subproc.c
@@ -121,7 +121,7 @@ static void subprocRemove(struct nsjconf_t *nsjconf, pid_t pid)
                if (p->pid == pid) {
                        LOG_D("Removing pid '%d' from the queue (IP:'%s', start time:'%u')", p->pid,
                              p->remote_txt, (unsigned int)p->start);
-                       close(p->pid_syscall_fd);
+                       TEMP_FAILURE_RETRY(close(p->pid_syscall_fd));
                        TAILQ_REMOVE(&nsjconf->pids, p, pointers);
                        free(p);
                        return;
@@ -318,13 +318,13 @@ void subprocRunChild(struct nsjconf_t *nsjconf, int fd_in, int fd_out, int fd_er
 
        pid_t pid = syscall(__NR_clone, (uintptr_t) flags, NULL, NULL, NULL, (uintptr_t) 0);
        if (pid == 0) {
-               close(sv[1]);
+               TEMP_FAILURE_RETRY(close(sv[1]));
                subprocNewProc(nsjconf, fd_in, fd_out, fd_err, sv[0]);
        }
        defer {
-               close(sv[1]);
+               TEMP_FAILURE_RETRY(close(sv[1]));
        }
-       close(sv[0]);
+       TEMP_FAILURE_RETRY(close(sv[0]));
        if (pid == -1) {
                PLOG_E("clone(flags=%#lx) failed. You probably need root privileges if your system "
                       "doesn't support CLONE_NEWUSER. Alternatively, you might want to recompile your "