torture: beginning of a mdssvc RPC service test-suite
[garming/samba-autobuild/.git] / lib / util / become_daemon.h
1 /*
2    Unix SMB/CIFS implementation.
3    Samba utility functions
4    Copyright (C) Andrew Tridgell 1992-1998
5    Copyright (C) Jeremy Allison 2001-2002
6    Copyright (C) Simo Sorce 2001
7    Copyright (C) Jim McDonough (jmcd@us.ibm.com)  2003.
8    Copyright (C) James J Myers 2003
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 3 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #ifndef _BECOME_DAEMON_H
25 #define _BECOME_DAEMON_H
26
27 #include <stdbool.h>
28
29 /**
30  * @file become_daemon.h
31  *
32  * @brief Utilities for demonising
33  */
34
35 /**
36  * @brief Close the low 3 file descriptors and open /dev/null in their place
37  *
38  * @param[in] stdin_too Should stdin be closed?
39  * @param[in] stdout_too Should stdout be closed?
40  * @param[in] stderr_too Should stderr be closed?
41 **/
42 void close_low_fds(bool stdin_too, bool stdout_too, bool stderr_too);
43
44 /**
45  * @brief Become a daemon, optionally discarding the controlling terminal
46  *
47  * @param[in] do_fork Should the process fork?
48  * @param[in] no_session Don't start a new session
49  * @param[in] log_stdour Should stdout be closed?
50 **/
51 void become_daemon(bool do_fork, bool no_session, bool log_stdout);
52
53 /**
54  * @brief Exit daemon and log an error message at ERR level
55  *
56  * Optionally report failure to systemd if systemd integration is
57  * enabled.
58  *
59  * @param[in] msg Message to log, generated from error if NULL
60  * @param[in] error Errno of error that occurred
61 **/
62 void exit_daemon(const char *msg, int error);
63
64 /**
65  * @brief Log at ERR level that the daemon is ready to serve connections
66  *
67  * Optionally report status to systemd if systemd integration is enabled.
68  *
69  * @param[in] daemon Name of daemon to include it message
70 **/
71 void daemon_ready(const char *daemon);
72
73 /**
74  * @brief Log at ERR level the specified daemon status
75  *
76  * For example if it is not ready to serve connections and is waiting
77  * for some event to happen.
78  *
79  * Optionally report status to systemd if systemd integration is enabled.
80  *
81  * @param[in] daemon Name of daemon to include it message
82  * @param[in] msg Message to log
83 **/
84 void daemon_status(const char *daemon, const char *msg);
85
86 #endif /* _BECOME_DAEMON_H */