aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2006-06-05 20:05:24 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2006-06-05 20:05:24 +0000
commit9b06d2cd4ac9e4e85c89f09de65b5772a8864a48 (patch)
treef93aa8c5f7682fdb4acba11da06090d3a312db73 /src/main.c
parentffd580dd1986dfd4b614f0a3fded4b173425de85 (diff)
downloadmpd-9b06d2cd4ac9e4e85c89f09de65b5772a8864a48.tar.gz
mpd-9b06d2cd4ac9e4e85c89f09de65b5772a8864a48.tar.xz
mpd-9b06d2cd4ac9e4e85c89f09de65b5772a8864a48.zip
Made pid_file an optional config parameter.
git-svn-id: https://svn.musicpd.org/mpd/trunk@4250 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/main.c b/src/main.c
index 2b76f8d9d..304cb5208 100644
--- a/src/main.c
+++ b/src/main.c
@@ -372,18 +372,20 @@ void startMainProcess() {
}
void daemonize(Options * options) {
- FILE * fp;
- ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 1);
+ FILE * fp = NULL;
+ ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 0);
- /* do this before daemon'izing so we can fail gracefully if we can't
- * write to the pid file */
- DEBUG("opening pid file\n");
- fp = fopen(pidFileParam->value, "w+");
- if(!fp) {
- ERROR("could not open %s \"%s\" (at line %i) for writing: %s\n",
- CONF_PID_FILE, pidFileParam->value,
- pidFileParam->line, strerror(errno));
- exit(EXIT_FAILURE);
+ if (pidFileParam) {
+ /* do this before daemon'izing so we can fail gracefully if we can't
+ * write to the pid file */
+ DEBUG("opening pid file\n");
+ fp = fopen(pidFileParam->value, "w+");
+ if(!fp) {
+ ERROR("could not open %s \"%s\" (at line %i) for writing: %s\n",
+ CONF_PID_FILE, pidFileParam->value,
+ pidFileParam->line, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
}
if(options->daemon) {
@@ -418,10 +420,12 @@ void daemonize(Options * options) {
DEBUG("daemonized!\n");
}
- DEBUG("writing pid file\n");
- fprintf(fp, "%lu\n", (unsigned long)getpid());
- fclose(fp);
- masterPid = getpid();
+ if (pidFileParam) {
+ DEBUG("writing pid file\n");
+ fprintf(fp, "%lu\n", (unsigned long)getpid());
+ fclose(fp);
+ masterPid = getpid();
+ }
}
void setupLogOutput(Options * options, FILE * out, FILE * err) {
@@ -461,7 +465,9 @@ void setupLogOutput(Options * options, FILE * out, FILE * err) {
}
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");
@@ -472,9 +478,14 @@ void killFromPidFile(char * cmd, int killOption) {
/*char buf[32];
struct stat st_cmd;
struct stat st_exe;*/
- ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 1);
+ ConfigParam * pidFileParam = parseConfigFilePath(CONF_PID_FILE, 0);
int pid;
+ if (!pidFileParam) {
+ ERROR("no pid_file specified in the config file\n");
+ exit(EXIT_FAILURE);
+ }
+
FILE * fp = fopen(pidFileParam->value,"r");
if(!fp) {
ERROR("unable to open %s \"%s\": %s\n",