aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-12-30 16:28:07 +0100
committerMax Kellermann <max@duempel.org>2008-12-30 16:28:07 +0100
commit671480814c643cd094978e4a0db76687fbddec4f (patch)
tree06d2b04e3d02047ad62025b748046b08624ff6ab /src/main.c
parentd99595c2143ef31d4bf3b2274d55100f39363be3 (diff)
downloadmpd-671480814c643cd094978e4a0db76687fbddec4f.tar.gz
mpd-671480814c643cd094978e4a0db76687fbddec4f.tar.xz
mpd-671480814c643cd094978e4a0db76687fbddec4f.zip
main: moved daemonize() to daemon.c
Diffstat (limited to '')
-rw-r--r--src/main.c60
1 files changed, 1 insertions, 59 deletions
diff --git a/src/main.c b/src/main.c
index 7ccbf1a05..c840240a3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -16,6 +16,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "daemon.h"
#include "client.h"
#include "idle.h"
#include "command.h"
@@ -135,65 +136,6 @@ static void openDB(Options * options, char *argv0)
}
}
-static void daemonize(Options * options)
-{
-#ifndef WIN32
- FILE *fp = NULL;
- ConfigParam *pidFileParam = parseConfigFilePath(CONF_PID_FILE, 0);
-
- if (pidFileParam) {
- /* do this before daemon'izing so we can fail gracefully if we can't
- * write to the pid file */
- g_debug("opening pid file");
- fp = fopen(pidFileParam->value, "w+");
- if (!fp) {
- g_error("could not open %s \"%s\" (at line %i) for writing: %s",
- CONF_PID_FILE, pidFileParam->value,
- pidFileParam->line, strerror(errno));
- }
- }
-
- if (options->daemon) {
- int pid;
-
- fflush(NULL);
- pid = fork();
- if (pid > 0)
- _exit(EXIT_SUCCESS);
- else if (pid < 0) {
- g_error("problems fork'ing for daemon!");
- }
-
- if (chdir("/") < 0) {
- g_error("problems changing to root directory");
- }
-
- if (setsid() < 0) {
- g_error("problems setsid'ing");
- }
-
- fflush(NULL);
- pid = fork();
- if (pid > 0)
- _exit(EXIT_SUCCESS);
- else if (pid < 0) {
- g_error("problems fork'ing for daemon!");
- }
-
- g_debug("daemonized!");
- }
-
- if (pidFileParam) {
- g_debug("writing pid file");
- fprintf(fp, "%lu\n", (unsigned long)getpid());
- fclose(fp);
- }
-#else
- /* no daemonization on WIN32 */
- (void)options;
-#endif
-}
-
static void cleanUpPidFile(void)
{
ConfigParam *pidFileParam = parseConfigFilePath(CONF_PID_FILE, 0);