]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
epoll: update timeout and retry at eintr
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Fri, 22 Jan 2016 19:00:16 +0000 (11:00 -0800)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Fri, 22 Jan 2016 19:11:11 +0000 (11:11 -0800)
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
lxcfs.c

diff --git a/lxcfs.c b/lxcfs.c
index 940034e0917117667992f76a1a6bebb6b675253a..95e36ce33b09c2b5bd1f75a2bc773186565581a9 100644 (file)
--- a/lxcfs.c
+++ b/lxcfs.c
@@ -863,10 +863,12 @@ static int cg_release(const char *path, struct fuse_file_info *fi)
 static bool wait_for_sock(int sock, int timeout)
 {
        struct epoll_event ev;
-       int epfd, ret;
+       int epfd, ret, now, starttime, deltatime, saved_errno;
 
-       epfd = epoll_create(1);
-       if (epfd < 0) {
+       if ((starttime = time(NULL)) < 0)
+               return false;
+
+       if ((epfd = epoll_create(1)) < 0) {
                fprintf(stderr, "Failed to create epoll socket: %m\n");
                return false;
        }
@@ -879,13 +881,25 @@ static bool wait_for_sock(int sock, int timeout)
                return false;
        }
 
-       ret = epoll_wait(epfd, &ev, 1, timeout);
-       close(epfd);
+again:
+       if ((now = time(NULL)) < 0) {
+               close(epfd);
+               return false;
+       }
 
-       if (ret == 0)
+       deltatime = (starttime + timeout) - now;
+       if (deltatime < 0) { // timeout
+               errno = 0;
                return false;
-       if (ret < 0) {
-               fprintf(stderr, "Failure during epoll_wait: %m\n");
+       }
+       ret = epoll_wait(epfd, &ev, 1, 1000*deltatime + 1);
+       if (ret < 0 && errno == EINTR)
+               goto again;
+       saved_errno = errno;
+       close(epfd);
+
+       if (ret <= 0) {
+               errno = saved_errno;
                return false;
        }
        return true;
@@ -1310,7 +1324,7 @@ loop:
        }
 
        // give the child 1 second to be done forking and
-       // write it's ack
+       // write its ack
        if (!wait_for_sock(cpipe[0], 1))
                goto again;
        ret = read(cpipe[0], &v, 1);