reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ServerProcess.hxx
Go to the documentation of this file.
1
2#if defined(HAVE_CONFIG_H)
3 #include "config.h"
4#endif
5
6#include <chrono>
7
8#include "rutil/Data.hxx"
9
10namespace resip
11{
12
14{
15public:
16 ServerProcess(std::chrono::milliseconds waitPeriod = std::chrono::milliseconds(50));
17 virtual ~ServerProcess();
18
19 void mainLoop();
20 void onSignal(int signo);
21
22protected:
23 /* Returns true when this build can perform POSIX process control:
24 fork(), setuid/setgid and PID file handling.
25
26 Windows has none of these, so there this logs a warning naming the
27 dependent settings and returns false. The caller then skips an
28 operation that cannot work on this platform rather than attempting it
29 and failing.
30
31 dependentSettings is only the label used in that warning, e.g.
32 "Daemonize" or "RunAsUser/RunAsGroup"; it is not inspected.
33
34 Call this only once the setting is known to be configured, so that no
35 warning is produced for settings the operator never set. */
36 bool checkPosixProcessControl(const Data& dependentSettings);
37
38 /* The main subclass can call installSignalHandler()
39 if it wants signals handled. */
41
42 /* The main subclass can call dropPrivileges()
43 if and when it wants to drop root privileges */
44 void dropPrivileges(const Data& runAsUser, const Data& runAsGroup);
45
46 /* If the PID file is specified, checks if we are already running
47 an instance of this binary */
48 bool isAlreadyRunning();
49
50 /* The main subclass can call daemonize() if and
51 when it wants to become a daemon */
52 void daemonize();
53
54 /* Filename of PID file, or empty string for no PID file */
55 void setPidFile(const Data& pidFile);
56
57 virtual void doWait();
58 virtual void onLoop();
59
60 virtual void onReload();
61
62private:
63 std::chrono::milliseconds mWaitPeriod;
64 Data mPidFile;
65 bool mFinished;
66 bool mReceivedHUP;
67};
68
69}
70
71/* ====================================================================
72 *
73 * Copyright (c) 2026, SIP Spectrum, Inc. https://www.sipspectrum.com
74 * Copyright (c) 2012 Daniel Pocock. All rights reserved.
75 *
76 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions
78 * are met:
79 *
80 * 1. Redistributions of source code must retain the above copyright
81 * notice, this list of conditions and the following disclaimer.
82 *
83 * 2. Redistributions in binary form must reproduce the above copyright
84 * notice, this list of conditions and the following disclaimer in
85 * the documentation and/or other materials provided with the
86 * distribution.
87 *
88 * 3. Neither the name of the author(s) nor the names of any contributors
89 * may be used to endorse or promote products derived from this software
90 * without specific prior written permission.
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
93 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
95 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
96 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
97 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
98 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
99 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
100 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
101 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
102 * SUCH DAMAGE.
103 *
104 * ====================================================================
105 *
106 */
107/*
108 * vi: set shiftwidth=3 expandtab:
109 */
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
void dropPrivileges(const Data &runAsUser, const Data &runAsGroup)
virtual void onReload()
void onSignal(int signo)
void setPidFile(const Data &pidFile)
bool checkPosixProcessControl(const Data &dependentSettings)
dcm! – add UnusedChecking(_enum) below;