CommandLine: add option --systemd
This way, MPD can reliably detect whether it was started as systemd service, which is better than checking sd_booted(), which only checks whether systemd manages all services, but still MPD could be started manually.
This commit is contained in:
		| @@ -86,6 +86,9 @@ enum Option { | |||||||
| 	OPTION_KILL, | 	OPTION_KILL, | ||||||
| 	OPTION_NO_CONFIG, | 	OPTION_NO_CONFIG, | ||||||
| 	OPTION_NO_DAEMON, | 	OPTION_NO_DAEMON, | ||||||
|  | #ifdef __linux__ | ||||||
|  | 	OPTION_SYSTEMD, | ||||||
|  | #endif | ||||||
| 	OPTION_STDOUT, | 	OPTION_STDOUT, | ||||||
| 	OPTION_STDERR, | 	OPTION_STDERR, | ||||||
| 	OPTION_VERBOSE, | 	OPTION_VERBOSE, | ||||||
| @@ -98,6 +101,9 @@ static constexpr OptionDef option_defs[] = { | |||||||
| 	{"kill", "kill the currently running mpd session"}, | 	{"kill", "kill the currently running mpd session"}, | ||||||
| 	{"no-config", "don't read from config"}, | 	{"no-config", "don't read from config"}, | ||||||
| 	{"no-daemon", "don't detach from console"}, | 	{"no-daemon", "don't detach from console"}, | ||||||
|  | #ifdef __linux__ | ||||||
|  | 	{"systemd", "systemd service mode"}, | ||||||
|  | #endif | ||||||
| 	{"stdout", nullptr}, // hidden, compatibility with old versions | 	{"stdout", nullptr}, // hidden, compatibility with old versions | ||||||
| 	{"stderr", "print messages to stderr"}, | 	{"stderr", "print messages to stderr"}, | ||||||
| 	{"verbose", 'v', "verbose logging"}, | 	{"verbose", 'v', "verbose logging"}, | ||||||
| @@ -349,6 +355,13 @@ ParseCommandLine(int argc, char **argv, struct options &options, | |||||||
| 			options.daemon = false; | 			options.daemon = false; | ||||||
| 			break; | 			break; | ||||||
|  |  | ||||||
|  | #ifdef __linux__ | ||||||
|  | 		case OPTION_SYSTEMD: | ||||||
|  | 			options.daemon = false; | ||||||
|  | 			options.systemd = true; | ||||||
|  | 			break; | ||||||
|  | #endif | ||||||
|  |  | ||||||
| 		case OPTION_STDOUT: | 		case OPTION_STDOUT: | ||||||
| 		case OPTION_STDERR: | 		case OPTION_STDERR: | ||||||
| 			options.log_stderr = true; | 			options.log_stderr = true; | ||||||
|   | |||||||
| @@ -25,6 +25,11 @@ struct ConfigData; | |||||||
| struct options { | struct options { | ||||||
| 	bool kill = false; | 	bool kill = false; | ||||||
| 	bool daemon = true; | 	bool daemon = true; | ||||||
|  |  | ||||||
|  | #ifdef __linux__ | ||||||
|  | 	bool systemd = false; | ||||||
|  | #endif | ||||||
|  |  | ||||||
| 	bool log_stderr = false; | 	bool log_stderr = false; | ||||||
| 	bool verbose = false; | 	bool verbose = false; | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ After=network.target sound.target | |||||||
|  |  | ||||||
| [Service] | [Service] | ||||||
| Type=notify | Type=notify | ||||||
| ExecStart=@prefix@/bin/mpd --no-daemon | ExecStart=@prefix@/bin/mpd --systemd | ||||||
|  |  | ||||||
| # Create /run/mpd (if MPD is launched without the socket unit and is | # Create /run/mpd (if MPD is launched without the socket unit and is | ||||||
| # configured to bind listener sockets there). | # configured to bind listener sockets there). | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ After=network.target sound.target | |||||||
|  |  | ||||||
| [Service] | [Service] | ||||||
| Type=notify | Type=notify | ||||||
| ExecStart=@prefix@/bin/mpd --no-daemon | ExecStart=@prefix@/bin/mpd --systemd | ||||||
|  |  | ||||||
| # Create /run/user/$UID/mpd (if MPD is launched without the socket | # Create /run/user/$UID/mpd (if MPD is launched without the socket | ||||||
| # unit and is configured to bind listener sockets there). | # unit and is configured to bind listener sockets there). | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann