Daemon.hxx 2.03 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2020 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14 15 16 17
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 19
 */

Max Kellermann's avatar
Max Kellermann committed
20 21
#ifndef MPD_DAEMON_HXX
#define MPD_DAEMON_HXX
22

23
class AllocatedPath;
24

25
#ifndef _WIN32
26
void
27
daemonize_init(const char *user, const char *group, AllocatedPath &&pidfile);
28 29
#else
static inline void
30
daemonize_init(const char *user, const char *group, AllocatedPath &&pidfile)
31 32
{ (void)user; (void)group; (void)pidfile; }
#endif
33

34
#ifndef _WIN32
35
void
36
daemonize_finish();
37 38
#else
static inline void
39
daemonize_finish()
40 41
{ /* nop */ }
#endif
42

43 44 45 46
/**
 * Kill the MPD which is currently running, pid determined from the
 * pid file.
 */
47
#ifndef _WIN32
48
[[noreturn]]
49
void
50
daemonize_kill();
51
#else
52
#include <stdexcept>
53
[[noreturn]]
54
static inline void
55
daemonize_kill()
56
{
57
	throw std::runtime_error("--kill is not available on WIN32");
58
}
59
#endif
60

61 62 63
/**
 * Close stdin (fd 0) and re-open it as /dev/null.
 */
64
#ifndef _WIN32
65
void
66
daemonize_close_stdin();
67 68
#else
static inline void
69
daemonize_close_stdin() {}
70
#endif
71

72 73 74
/**
 * Change to the configured Unix user.
 */
75
#ifndef _WIN32
76
void
77
daemonize_set_user();
78 79
#else
static inline void
80
daemonize_set_user()
81 82
{ /* nop */ }
#endif
83

84
#ifndef _WIN32
85
void
86
daemonize_begin(bool detach);
87 88
#else
static inline void
89
daemonize_begin(bool detach)
90 91
{ (void)detach; }
#endif
92

93
#ifndef _WIN32
94 95 96 97 98 99 100
void
daemonize_commit();
#else
static inline void
daemonize_commit() {}
#endif

101
#endif