Commit 47378d53 by Christian Brauner Committed by Stéphane Graber

monitord: close mainloop on exit if we opened it

parent 5267c49f
......@@ -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);
}
......@@ -161,4 +161,3 @@ int lxc_mainloop_close(struct lxc_epoll_descr *descr)
return close(descr->epfd);
}
......@@ -325,6 +325,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]);
......@@ -339,6 +340,7 @@ int lxc_monitord_spawn(const char *lxcpath)
close(pipefd[0]);
DEBUG("Sucessfully synced with child process.");
exit(EXIT_SUCCESS);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment