]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
monitord: close mainloop on exit if we opened it 1332/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 29 Nov 2016 04:42:47 +0000 (05:42 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 29 Nov 2016 07:38:20 +0000 (08:38 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/lxc_monitord.c
src/lxc/mainloop.c
src/lxc/monitor.c

index 2fbb3574fdb5a9e641948cffef713a64bfea921d..62e212112644a5251cd622a8e4928963feff499c 100644 (file)
@@ -348,6 +348,8 @@ int main(int argc, char *argv[])
        char logpath[PATH_MAX];
        sigset_t mask;
        char *lxcpath = argv[1];
+       bool mainloop_opened = false;
+       bool monitord_created = false;
 
        if (argc != 3) {
                fprintf(stderr,
@@ -395,10 +397,11 @@ int main(int argc, char *argv[])
                ERROR("Failed to create mainloop.");
                goto on_error;
        }
+       mainloop_opened = true;
 
-       if (lxc_monitord_create(&mon)) {
+       if (lxc_monitord_create(&mon))
                goto on_error;
-       }
+       monitord_created = true;
 
        /* sync with parent, we're ignoring the return from write
         * because regardless if it works or not, the following
@@ -425,14 +428,13 @@ int main(int argc, char *argv[])
                }
        }
 
-       lxc_mainloop_close(&mon.descr);
-       lxc_monitord_cleanup();
+on_signal:
        ret = EXIT_SUCCESS;
-
 on_error:
-       exit(ret);
+       if (monitord_created)
+               lxc_monitord_cleanup();
+       if (mainloop_opened)
+               lxc_mainloop_close(&mon.descr);
 
-on_signal:
-       lxc_monitord_cleanup();
-       exit(EXIT_SUCCESS);
+       exit(ret);
 }
index 85b3ab979b730a7908a10267b13c48d477bc2d5e..ab9c27dc04dbbf5699e29e81b02ff201e6167e00 100644 (file)
@@ -161,4 +161,3 @@ int lxc_mainloop_close(struct lxc_epoll_descr *descr)
 
        return close(descr->epfd);
 }
-
index 793fbde098d595d891cd120bfd0936b3c8734dce..dbded0500a3cdf64fe584aa802b80c4b13d7c777 100644 (file)
@@ -326,6 +326,7 @@ int lxc_monitord_spawn(const char *lxcpath)
        }
 
        if (pid2) {
+               DEBUG("Trying to sync with child process.");
                char c;
                /* Wait for daemon to create socket. */
                close(pipefd[1]);
@@ -340,6 +341,7 @@ int lxc_monitord_spawn(const char *lxcpath)
 
                close(pipefd[0]);
 
+               DEBUG("Sucessfully synced with child process.");
                exit(EXIT_SUCCESS);
        }