Made pid_file an optional config parameter.
git-svn-id: https://svn.musicpd.org/mpd/trunk@4250 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
ffd580dd19
commit
9b06d2cd4a
@ -22,7 +22,8 @@ Read more about MPD at <\fBhttp://www.musicpd.org/\fP>.
|
|||||||
Output a brief help message.
|
Output a brief help message.
|
||||||
.TP
|
.TP
|
||||||
.BI --kill
|
.BI --kill
|
||||||
Kill the currently running mpd session.
|
Kill the currently running mpd session. The pid_file parameter must be
|
||||||
|
specified in the config file for this to work.
|
||||||
.TP
|
.TP
|
||||||
.BI --create-db
|
.BI --create-db
|
||||||
Force (re)creation of database and exit.
|
Force (re)creation of database and exit.
|
||||||
|
@ -43,10 +43,10 @@ This specifies where the log file should be located.
|
|||||||
.TP
|
.TP
|
||||||
.B error_file <file>
|
.B error_file <file>
|
||||||
This specifies where the error file should be located.
|
This specifies where the error file should be located.
|
||||||
|
.SH OPTIONAL PARAMETERS
|
||||||
.TP
|
.TP
|
||||||
.B pid_file <file>
|
.B pid_file <file>
|
||||||
This specifies the file to save mpd's process ID in.
|
This specifies the file to save mpd's process ID in.
|
||||||
.SH OPTIONAL PARAMETERS
|
|
||||||
.TP
|
.TP
|
||||||
.B state_file <file>
|
.B state_file <file>
|
||||||
This specifies if a state file is used and where it is located. The state of
|
This specifies if a state file is used and where it is located. The state of
|
||||||
|
45
src/main.c
45
src/main.c
@ -372,18 +372,20 @@ void startMainProcess() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void daemonize(Options * options) {
|
void daemonize(Options * options) {
|
||||||
FILE * fp;
|
FILE * fp = NULL;
|
||||||
ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 1);
|
ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 0);
|
||||||
|
|
||||||
/* do this before daemon'izing so we can fail gracefully if we can't
|
if (pidFileParam) {
|
||||||
* write to the pid file */
|
/* do this before daemon'izing so we can fail gracefully if we can't
|
||||||
DEBUG("opening pid file\n");
|
* write to the pid file */
|
||||||
fp = fopen(pidFileParam->value, "w+");
|
DEBUG("opening pid file\n");
|
||||||
if(!fp) {
|
fp = fopen(pidFileParam->value, "w+");
|
||||||
ERROR("could not open %s \"%s\" (at line %i) for writing: %s\n",
|
if(!fp) {
|
||||||
CONF_PID_FILE, pidFileParam->value,
|
ERROR("could not open %s \"%s\" (at line %i) for writing: %s\n",
|
||||||
pidFileParam->line, strerror(errno));
|
CONF_PID_FILE, pidFileParam->value,
|
||||||
exit(EXIT_FAILURE);
|
pidFileParam->line, strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(options->daemon) {
|
if(options->daemon) {
|
||||||
@ -418,10 +420,12 @@ void daemonize(Options * options) {
|
|||||||
DEBUG("daemonized!\n");
|
DEBUG("daemonized!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("writing pid file\n");
|
if (pidFileParam) {
|
||||||
fprintf(fp, "%lu\n", (unsigned long)getpid());
|
DEBUG("writing pid file\n");
|
||||||
fclose(fp);
|
fprintf(fp, "%lu\n", (unsigned long)getpid());
|
||||||
masterPid = getpid();
|
fclose(fp);
|
||||||
|
masterPid = getpid();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupLogOutput(Options * options, FILE * out, FILE * err) {
|
void setupLogOutput(Options * options, FILE * out, FILE * err) {
|
||||||
@ -461,7 +465,9 @@ void setupLogOutput(Options * options, FILE * out, FILE * err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cleanUpPidFile() {
|
void cleanUpPidFile() {
|
||||||
ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 1);
|
ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 0);
|
||||||
|
|
||||||
|
if (!pidFileParam) return;
|
||||||
|
|
||||||
DEBUG("cleaning up pid file\n");
|
DEBUG("cleaning up pid file\n");
|
||||||
|
|
||||||
@ -472,9 +478,14 @@ void killFromPidFile(char * cmd, int killOption) {
|
|||||||
/*char buf[32];
|
/*char buf[32];
|
||||||
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, 0);
|
||||||
int pid;
|
int pid;
|
||||||
|
|
||||||
|
if (!pidFileParam) {
|
||||||
|
ERROR("no pid_file specified in the config file\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
FILE * fp = fopen(pidFileParam->value,"r");
|
FILE * fp = fopen(pidFileParam->value,"r");
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
ERROR("unable to open %s \"%s\": %s\n",
|
ERROR("unable to open %s \"%s\": %s\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user