diff options
| -rw-r--r-- | glusterfsd/src/glusterfsd.c | 47 | 
1 files changed, 26 insertions, 21 deletions
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 6211788be06..d2c15632111 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -159,7 +159,7 @@ gf_daemon (int *pipe_fd)  {          pid_t		pid = -1;          int             ret = -1; -        char            gf_daemon_buff[50] = {0,}; +        int             gf_daemon_buff = 0;          if (pipe (pipe_fd) < 0) {                  gf_log ("glusterfs", GF_LOG_ERROR, @@ -173,8 +173,10 @@ gf_daemon (int *pipe_fd)                  return -1;          } else if (pid != 0) {                  close (pipe_fd[1]); -                ret = read (pipe_fd[0], gf_daemon_buff, -                            sizeof (gf_daemon_buff)); +                ret = read (pipe_fd[0], &gf_daemon_buff, +                            sizeof (int)); +                close (pipe_fd[0]); +                  if (ret == -1) {                          gf_log ("glusterfs", GF_LOG_ERROR,                                  "read error on pipe- %s", strerror (errno)); @@ -184,12 +186,10 @@ gf_daemon (int *pipe_fd)                                  "end of file- %s", strerror (errno));                          return -1;                  } else { -                        if (!strncmp (gf_daemon_buff, "0", 1)) +                        if (gf_daemon_buff == 0)                                  exit (EXIT_SUCCESS); -                        else { -                                fprintf (stderr, "%s\n", gf_daemon_buff); +                        else                                  exit (EXIT_FAILURE); -                        }                  }          } @@ -1051,8 +1051,10 @@ main (int argc, char *argv[])  	int               xl_count = 0;  	uint8_t           process_mode = 0;          int               pipe_fd[2]; +        int               gf_success = 0; +        int               gf_failure = -1; -	utime = time (NULL); +        utime = time (NULL);  	ctx = CALLOC (1, sizeof (glusterfs_ctx_t));  	ERR_ABORT (ctx);  	process_mode = gf_get_process_mode (argv[0]); @@ -1216,11 +1218,12 @@ main (int argc, char *argv[])                                          "unable to open pid file %s, %s.",                                          cmd_args->pid_file,                                          strerror (errno)); -                                if (write (pipe_fd[1], strerror (errno), -                                           strlen (strerror (errno))) < 0) { +                                if (write (pipe_fd[1], &gf_failure,  +                                           sizeof (int)) < 0) {                                          gf_log ("glusterfs", GF_LOG_ERROR,                                                  "Write on pipe error");                                  } +                                  /* do cleanup and exit ?! */                                  return -1;                          } @@ -1231,11 +1234,12 @@ main (int argc, char *argv[])                                         "Is another instance of %s running?",                                          argv[0]);                                  fclose (ctx->pidfp); -                                if (write (pipe_fd[1], strerror (errno), -                                           strlen (strerror (errno))) < 0) { +                                if (write (pipe_fd[1], &gf_failure,  +                                           sizeof (int)) < 0) {                                          gf_log ("glusterfs", GF_LOG_ERROR,                                                  "Write on pipe error");                                  } +                                  return ret;                          }                          ret = ftruncate (fileno (ctx->pidfp), 0); @@ -1246,11 +1250,12 @@ main (int argc, char *argv[])                                          strerror (errno));                                  flock (fileno (ctx->pidfp), LOCK_UN);                                  fclose (ctx->pidfp); -                                if (write (pipe_fd[1], strerror (errno), -                                           strlen (strerror (errno))) < 0) { +                                if (write (pipe_fd[1], &gf_failure,  +                                           sizeof (int)) < 0) {                                          gf_log ("glusterfs", GF_LOG_ERROR,                                                  "Write on pipe error");                                  } +                                  return ret;                          } @@ -1285,14 +1290,14 @@ main (int argc, char *argv[])  		gf_log ("glusterfs", GF_LOG_ERROR,  			"translator initialization failed.  exiting");  		if (!cmd_args->no_daemon_mode && -                    (write (pipe_fd[1], strerror (errno), -                            strlen (strerror (errno))) < 0)) { +                    (write (pipe_fd[1], &gf_failure, sizeof (int)) < 0)) {  			gf_log ("glusterfs", GF_LOG_ERROR,                                  "Write on pipe failed,"                                  "daemonize problem.exiting: %s",                                   strerror (errno)); -                                 } -		return -1; +                } + +                return -1;  	}  	/* Send PARENT_UP notify to all the translators now */ @@ -1301,15 +1306,15 @@ main (int argc, char *argv[])  	gf_log ("glusterfs", GF_LOG_NORMAL, "Successfully started");  	if (!cmd_args->no_daemon_mode && -            (write (pipe_fd[1], "0", 2) < 0)) { +            (write (pipe_fd[1], &gf_success, sizeof (int)) < 0)) {  		gf_log ("glusterfs", GF_LOG_ERROR,                          "Write on pipe failed,"                          "daemonize problem.  exiting: %s",                           strerror (errno));  		return -1;  	} -	 -	event_dispatch (ctx->event_pool); + +        event_dispatch (ctx->event_pool);  	return 0;  }  | 
