summaryrefslogtreecommitdiffstats
path: root/glusterfsd
diff options
context:
space:
mode:
authorSanju Rakonde <srakonde@redhat.com>2017-11-07 17:24:24 +0530
committerAtin Mukherjee <amukherj@redhat.com>2017-11-12 06:38:25 +0000
commitcd249f4cb783f8d79e79468c455732669e835a4f (patch)
tree6709010ab77e14e72b5960fc09c2a5957355d2c6 /glusterfsd
parent230ccb3f8ff6d2c94474e2221d9e4e7b834e8fcf (diff)
glusterfsd: making parent process to write pidfile while forking
Issue: pid is written into glusterd.pid by child process instead of parent process while forking. Fix: After fork returns child pid to parent process, it falls under default case of switch statement, call glusterfs_pidfile_update() in default case instead of postfork label. Change-Id: I41b616c140592bf117601bc451dfd8b934a5b640 BUG: 1509340 Signed-off-by: Sanju Rakonde <srakonde@redhat.com>
Diffstat (limited to 'glusterfsd')
-rw-r--r--glusterfsd/src/glusterfsd.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
index bb85628c804..69383f87b17 100644
--- a/glusterfsd/src/glusterfsd.c
+++ b/glusterfsd/src/glusterfsd.c
@@ -2122,7 +2122,7 @@ glusterfs_pidfile_cleanup (glusterfs_ctx_t *ctx)
}
int
-glusterfs_pidfile_update (glusterfs_ctx_t *ctx)
+glusterfs_pidfile_update (glusterfs_ctx_t *ctx, pid_t pid)
{
cmd_args_t *cmd_args = NULL;
int ret = 0;
@@ -2148,7 +2148,7 @@ glusterfs_pidfile_update (glusterfs_ctx_t *ctx)
return ret;
}
- ret = fprintf (pidfp, "%d\n", getpid ());
+ ret = fprintf (pidfp, "%d\n", pid);
if (ret <= 0) {
gf_msg ("glusterfsd", GF_LOG_ERROR, errno, glusterfsd_msg_21,
cmd_args->pid_file);
@@ -2163,7 +2163,7 @@ glusterfs_pidfile_update (glusterfs_ctx_t *ctx)
}
gf_msg_debug ("glusterfsd", 0, "pidfile %s updated with pid %d",
- cmd_args->pid_file, getpid ());
+ cmd_args->pid_file, pid);
return 0;
}
@@ -2274,6 +2274,7 @@ daemonize (glusterfs_ctx_t *ctx)
cmd_args_t *cmd_args = NULL;
int cstatus = 0;
int err = 1;
+ int child_pid = 0;
cmd_args = &ctx->cmd_args;
@@ -2281,8 +2282,12 @@ daemonize (glusterfs_ctx_t *ctx)
if (ret)
goto out;
- if (cmd_args->no_daemon_mode)
+ if (cmd_args->no_daemon_mode) {
+ ret = glusterfs_pidfile_update (ctx, getpid());
+ if (ret)
+ goto out;
goto postfork;
+ }
if (cmd_args->debug_mode)
goto postfork;
@@ -2314,6 +2319,7 @@ daemonize (glusterfs_ctx_t *ctx)
default:
/* parent */
/* close write */
+ child_pid = ret;
sys_close (ctx->daemon_pipe[1]);
if (ctx->mnt_pid > 0) {
@@ -2332,14 +2338,15 @@ daemonize (glusterfs_ctx_t *ctx)
sys_read (ctx->daemon_pipe[0], (void *)&err, sizeof (err));
/* NOTE: Only the least significant 8 bits i.e (err & 255)
will be available to parent process on calling exit() */
- _exit (abs(err));
+ if (err)
+ _exit (abs(err));
+ ret = glusterfs_pidfile_update (ctx, child_pid);
+ if (ret)
+ _exit (1);
+ _exit (0);
}
postfork:
- ret = glusterfs_pidfile_update (ctx);
- if (ret)
- goto out;
-
ret = gf_log_inject_timer_event (ctx);
glusterfs_signals_setup (ctx);