From f71c846a24fcefa19750967c081fbe1013364515 Mon Sep 17 00:00:00 2001 From: yuqing Date: Sun, 16 Aug 2015 10:50:21 +0800 Subject: [PATCH] resolve compile warning in mac book --- src/process_ctrl.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/process_ctrl.c b/src/process_ctrl.c index 048e2ea..cb69e13 100644 --- a/src/process_ctrl.c +++ b/src/process_ctrl.c @@ -126,8 +126,10 @@ int process_start(const char* pidFilename) { pid_t pid; int result; - char cmdline[MAX_PATH_SIZE], cmdfile[MAX_PATH_SIZE], argv0[MAX_PATH_SIZE]; - long cmdsz = sizeof cmdline; + char cmdline[MAX_PATH_SIZE]; + char cmdfile[MAX_PATH_SIZE]; + char argv0[MAX_PATH_SIZE]; + int64_t cmdsz; if ((result=get_pid_from_file(pidFilename, &pid)) != 0) { if (result == ENOENT) { @@ -140,14 +142,16 @@ int process_start(const char* pidFilename) return result; } } - cmdline[cmdsz-1] = argv0[cmdsz-1] = '\0'; + if (kill(pid, 0) == 0) { + cmdsz = sizeof(cmdline); + cmdline[cmdsz-1] = argv0[cmdsz-1] = '\0'; sprintf(cmdfile, "/proc/%d/cmdline", pid); if ((result=getFileContentEx(cmdfile, cmdline, 0, &cmdsz)) != 0) { fprintf(stderr, "read file %s failed. %d %s\n", cmdfile, errno, strerror(errno)); return result; } - cmdsz = sizeof argv0; + cmdsz = sizeof(argv0); sprintf(cmdfile, "/proc/%d/cmdline", getpid()); if ((result=getFileContentEx(cmdfile, argv0, 0, &cmdsz)) != 0) { fprintf(stderr, "read file %s failed. %d %s\n", cmdfile, errno, strerror(errno)); @@ -167,7 +171,6 @@ int process_start(const char* pidFilename) (int)pid, errno, strerror(errno)); return result; } - } int process_exist(const char *pidFilename)