Fix deamon mode on macos

This commit is contained in:
Camille Scholtz
2025-01-30 21:36:23 +01:00
committed by Max Kellermann
parent 407db96d4a
commit e3cf9bb0a1
5 changed files with 62 additions and 0 deletions

38
src/apple/AppleMain.cxx Normal file
View File

@@ -0,0 +1,38 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
#include "Main.hxx"
#include "Instance.hxx"
#include "CommandLine.hxx"
#include "net/Init.hxx"
#include "config/Data.hxx"
static int service_argc;
static char **service_argv;
int apple_main(int argc, char *argv[])
{
service_argc = argc;
service_argv = argv;
#ifdef ENABLE_DAEMON
CommandLineOptions options;
ConfigData raw_config;
ParseCommandLine(argc, argv, options, raw_config);
if (options.daemon) {
// Fork before any Objective-C runtime initializations
pid_t pid = fork();
if (pid < 0)
throw MakeErrno("fork() failed");
if (pid > 0) {
// Parent process: exit immediately
_exit(0);
}
}
#endif
return mpd_main(argc, argv);
}