Skip to content

Commit

Permalink
monitord: close mainloop on exit if we opened it
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Nov 29, 2016
1 parent 258e3e4 commit 5cc0f22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/lxc/lxc_monitord.c
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
1 change: 0 additions & 1 deletion src/lxc/mainloop.c
Expand Up @@ -161,4 +161,3 @@ int lxc_mainloop_close(struct lxc_epoll_descr *descr)

return close(descr->epfd);
}

2 changes: 2 additions & 0 deletions src/lxc/monitor.c
Expand Up @@ -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]);
Expand All @@ -340,6 +341,7 @@ int lxc_monitord_spawn(const char *lxcpath)

close(pipefd[0]);

DEBUG("Sucessfully synced with child process.");
exit(EXIT_SUCCESS);
}

Expand Down

0 comments on commit 5cc0f22

Please sign in to comment.