diff --git a/src/lxc/lxc_monitord.c b/src/lxc/lxc_monitord.c index 2fbb3574fd..62e2121126 100644 --- a/src/lxc/lxc_monitord.c +++ b/src/lxc/lxc_monitord.c @@ -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); } diff --git a/src/lxc/mainloop.c b/src/lxc/mainloop.c index 85b3ab979b..ab9c27dc04 100644 --- a/src/lxc/mainloop.c +++ b/src/lxc/mainloop.c @@ -161,4 +161,3 @@ int lxc_mainloop_close(struct lxc_epoll_descr *descr) return close(descr->epfd); } - diff --git a/src/lxc/monitor.c b/src/lxc/monitor.c index 793fbde098..dbded0500a 100644 --- a/src/lxc/monitor.c +++ b/src/lxc/monitor.c @@ -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); }