diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2005-03-09 03:40:02 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2005-03-09 03:40:02 +0000 |
commit | 5f8bf2b4bbf5440be42344917289326db40583a5 (patch) | |
tree | 3a90f5f59be6ac21f5af3611ebf61e904af3d94e /src | |
parent | 70463a1dacd83c18314a3b8d4d3053c00c7b107c (diff) | |
download | mpd-5f8bf2b4bbf5440be42344917289326db40583a5.tar.gz mpd-5f8bf2b4bbf5440be42344917289326db40583a5.tar.xz mpd-5f8bf2b4bbf5440be42344917289326db40583a5.zip |
add ability to forcefully kill pid listed in pid file with '-kill -kill'
git-svn-id: https://svn.musicpd.org/mpd/trunk@3045 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/main.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c index 626bf36a2..d59eed57d 100644 --- a/src/main.c +++ b/src/main.c @@ -112,7 +112,7 @@ void parseOptions(int argc, char ** argv, Options * options) { exit(EXIT_SUCCESS); } else if(strcmp(argv[i],"--kill")==0) { - options->kill = 1; + options->kill++; argcLeft--; } else if(strcmp(argv[i],"--no-daemon")==0) { @@ -384,7 +384,7 @@ void cleanUpPidFile() { unlink(pidFileParam->value); } -void killMpdFromPidFile(char * cmd) { +void killMpdFromPidFile(char * cmd, int killOption) { struct stat st_cmd; struct stat st_exe; ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 1); @@ -408,23 +408,34 @@ void killMpdFromPidFile(char * cmd) { memset(buf, 0, 32); snprintf(buf, 31, "/proc/%i/exe", pid); - if(stat(cmd, &st_cmd)) { - ERROR("unable to stat file \"%s\"\n", cmd); - exit(EXIT_FAILURE); - } - if(stat(buf, &st_exe)) { - ERROR("unable to kill proccess %i (%s: %s)\n", pid, buf, - strerror(errno)); - exit(EXIT_FAILURE); + if(killOption == 1) { + if(stat(cmd, &st_cmd)) { + ERROR("unable to stat file \"%s\"\n", cmd); + ERROR("execute \"%s --kill -kill\" to kill pid %i\n", + cmd, pid); + exit(EXIT_FAILURE); + } + if(stat(buf, &st_exe)) { + ERROR("unable to kill proccess %i (%s: %s)\n", pid, buf, + strerror(errno)); + ERROR("execute \"%s --kill -kill\" to kill pid %i\n", + cmd, pid); + exit(EXIT_FAILURE); + } + + if(st_exe.st_dev != st_cmd.st_dev || st_exe.st_ino != st_cmd.st_ino) { + ERROR("%s doesn't appear to be running as pid %i\n", + cmd, pid); + ERROR("execute \"%s --kill -kill\" to kill pid %i\n", + cmd, pid); + exit(EXIT_FAILURE); + } } - if(st_exe.st_dev != st_cmd.st_dev || st_exe.st_ino != st_cmd.st_ino) { - ERROR("%s doesn't appear to be running as pid %i\n", - cmd, pid); + if(kill(pid, SIGTERM)) { + ERROR("unable to kill proccess %i: %s\n", pid, strerror(errno)); exit(EXIT_FAILURE); } - - kill(pid, SIGTERM); exit(EXIT_SUCCESS); } @@ -439,7 +450,7 @@ int main(int argc, char * argv[]) { parseOptions(argc, argv, &options); - if(options.kill) killMpdFromPidFile(argv[0]); + if(options.kill) killMpdFromPidFile(argv[0], options.kill); initStats(); initTagConfig(); |