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
This commit is contained in:
43
src/main.c
43
src/main.c
@@ -112,7 +112,7 @@ void parseOptions(int argc, char ** argv, Options * options) {
|
|||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else if(strcmp(argv[i],"--kill")==0) {
|
else if(strcmp(argv[i],"--kill")==0) {
|
||||||
options->kill = 1;
|
options->kill++;
|
||||||
argcLeft--;
|
argcLeft--;
|
||||||
}
|
}
|
||||||
else if(strcmp(argv[i],"--no-daemon")==0) {
|
else if(strcmp(argv[i],"--no-daemon")==0) {
|
||||||
@@ -384,7 +384,7 @@ void cleanUpPidFile() {
|
|||||||
unlink(pidFileParam->value);
|
unlink(pidFileParam->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void killMpdFromPidFile(char * cmd) {
|
void killMpdFromPidFile(char * cmd, int killOption) {
|
||||||
struct stat st_cmd;
|
struct stat st_cmd;
|
||||||
struct stat st_exe;
|
struct stat st_exe;
|
||||||
ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 1);
|
ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 1);
|
||||||
@@ -408,23 +408,34 @@ void killMpdFromPidFile(char * cmd) {
|
|||||||
memset(buf, 0, 32);
|
memset(buf, 0, 32);
|
||||||
snprintf(buf, 31, "/proc/%i/exe", pid);
|
snprintf(buf, 31, "/proc/%i/exe", pid);
|
||||||
|
|
||||||
if(stat(cmd, &st_cmd)) {
|
if(killOption == 1) {
|
||||||
ERROR("unable to stat file \"%s\"\n", cmd);
|
if(stat(cmd, &st_cmd)) {
|
||||||
exit(EXIT_FAILURE);
|
ERROR("unable to stat file \"%s\"\n", cmd);
|
||||||
}
|
ERROR("execute \"%s --kill -kill\" to kill pid %i\n",
|
||||||
if(stat(buf, &st_exe)) {
|
cmd, pid);
|
||||||
ERROR("unable to kill proccess %i (%s: %s)\n", pid, buf,
|
exit(EXIT_FAILURE);
|
||||||
strerror(errno));
|
}
|
||||||
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) {
|
if(kill(pid, SIGTERM)) {
|
||||||
ERROR("%s doesn't appear to be running as pid %i\n",
|
ERROR("unable to kill proccess %i: %s\n", pid, strerror(errno));
|
||||||
cmd, pid);
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
kill(pid, SIGTERM);
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,7 +450,7 @@ int main(int argc, char * argv[]) {
|
|||||||
|
|
||||||
parseOptions(argc, argv, &options);
|
parseOptions(argc, argv, &options);
|
||||||
|
|
||||||
if(options.kill) killMpdFromPidFile(argv[0]);
|
if(options.kill) killMpdFromPidFile(argv[0], options.kill);
|
||||||
|
|
||||||
initStats();
|
initStats();
|
||||||
initTagConfig();
|
initTagConfig();
|
||||||
|
Reference in New Issue
Block a user