diff options
author | Amar Tumballi <amar@gluster.com> | 2011-10-13 15:23:39 +0530 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2012-03-21 11:58:29 -0700 |
commit | abae8a2086e71aaf193b12df90ae3fe687117c28 (patch) | |
tree | 6509a232adf59474a2685f5ad8143a0d7d0d1932 /glusterfsd/src/glusterfsd.c | |
parent | c3bdb1d4c6c4491afdf1ba26bb0d6204270cc058 (diff) |
core: enable process to return the appropriate error code
Credit of this patch goes to Avati <avati@gluster.com> as I just did a
rebase to the lastest master.
Change-Id: I53b2adf90fd9808433bdc35b57dad0682bc90860
BUG: 762935
Signed-off-by: Amar Tumballi <amar@gluster.com>
Reviewed-on: http://review.gluster.com/579
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'glusterfsd/src/glusterfsd.c')
-rw-r--r-- | glusterfsd/src/glusterfsd.c | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 053a7c2461a..e3285658a99 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -387,7 +387,7 @@ err: xlator_destroy (master); } - return -1; + return 1; } @@ -865,6 +865,16 @@ reincarnate (int signum) return; } +void +emancipate (glusterfs_ctx_t *ctx, int ret) +{ + /* break free from the parent */ + if (ctx->daemon_pipe[1] != -1) { + write (ctx->daemon_pipe[1], (void *) &ret, sizeof (ret)); + close (ctx->daemon_pipe[1]); + ctx->daemon_pipe[1] = -1; + } +} static char * generate_uuid () @@ -1456,6 +1466,7 @@ daemonize (glusterfs_ctx_t *ctx) int ret = -1; cmd_args_t *cmd_args = NULL; int cstatus = 0; + int err = 0; cmd_args = &ctx->cmd_args; @@ -1469,15 +1480,36 @@ daemonize (glusterfs_ctx_t *ctx) if (cmd_args->debug_mode) goto postfork; + ret = pipe (ctx->daemon_pipe); + if (ret) { + /* If pipe() fails, retain daemon_pipe[] = {-1, -1} + and parent will just not wait for child status + */ + ctx->daemon_pipe[0] = -1; + ctx->daemon_pipe[1] = -1; + } + ret = os_daemon_return (0, 0); switch (ret) { case -1: + if (ctx->daemon_pipe[0] != -1) { + close (ctx->daemon_pipe[0]); + close (ctx->daemon_pipe[1]); + } + gf_log ("daemonize", GF_LOG_ERROR, "Daemonization failed: %s", strerror(errno)); goto out; case 0: + /* child */ + /* close read */ + close (ctx->daemon_pipe[0]); break; default: + /* parent */ + /* close write */ + close (ctx->daemon_pipe[1]); + if (ctx->mtab_pid > 0) { ret = waitpid (ctx->mtab_pid, &cstatus, 0); if (!(ret == ctx->mtab_pid && cstatus == 0)) { @@ -1486,7 +1518,10 @@ daemonize (glusterfs_ctx_t *ctx) exit (1); } } - _exit (0); + + err = 1; + read (ctx->daemon_pipe[0], (void *)&err, sizeof (err)); + _exit (err); } postfork: @@ -1568,7 +1603,8 @@ glusterfs_volumes_init (glusterfs_ctx_t *ctx) if (cmd_args->volfile_server) { ret = glusterfs_mgmt_init (ctx); - goto out; + /* return, do not emancipate() yet */ + return ret; } fp = get_volfp (ctx); @@ -1585,6 +1621,7 @@ glusterfs_volumes_init (glusterfs_ctx_t *ctx) goto out; out: + emancipate (ctx, ret); return ret; } |