From: Serge Hallyn Date: Thu, 11 Jun 2015 04:08:15 +0000 (-0500) Subject: daemonized start: exit children on failure, don't return X-Git-Tag: lxc-1.0.8~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87a00a69000dab45138abda503fe282bb5800568;p=thirdparty%2Flxc.git daemonized start: exit children on failure, don't return When starting a daemonized container, only the original parent thread should return to the caller. The first forked child immediately exits after forking, but the grandparent child was in some places returning on error - causing a second instance of the calling function. Signed-off-by: Serge Hallyn Acked-by: Tycho Andersen --- diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index c2c8b12d7..ec146eed4 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -613,19 +613,19 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv pid = fork(); if (pid < 0) { SYSERROR("Error doing dual-fork"); - return false; + exit(1); } if (pid != 0) exit(0); /* like daemon(), chdir to / and redirect 0,1,2 to /dev/null */ if (chdir("/")) { SYSERROR("Error chdir()ing to /."); - return false; + exit(1); } lxc_check_inherited(conf, -1); if (null_stdfds() < 0) { ERROR("failed to close fds"); - return false; + exit(1); } setsid(); } else { @@ -643,6 +643,8 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv if (pid_fp == NULL) { SYSERROR("Failed to create pidfile '%s' for '%s'", c->pidfile, c->name); + if (daemonize) + exit(1); return false; } @@ -650,6 +652,8 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv SYSERROR("Failed to write '%s'", c->pidfile); fclose(pid_fp); pid_fp = NULL; + if (daemonize) + exit(1); return false; }