MCPcopy Create free account
hub / github.com/Icinga/icinga2 / CloseStdIO

Function CloseStdIO

lib/cli/daemoncommand.cpp:134–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134static void CloseStdIO(const String& stderrFile)
135{
136#ifndef _WIN32
137 int fdnull = open("/dev/null", O_RDWR);
138 if (fdnull >= 0) {
139 if (fdnull != 0)
140 dup2(fdnull, 0);
141
142 if (fdnull != 1)
143 dup2(fdnull, 1);
144
145 if (fdnull > 1)
146 close(fdnull);
147 }
148
149 const char *errPath = "/dev/null";
150
151 if (!stderrFile.IsEmpty())
152 errPath = stderrFile.CStr();
153
154 int fderr = open(errPath, O_WRONLY | O_APPEND);
155
156 if (fderr < 0 && errno == ENOENT)
157 fderr = open(errPath, O_CREAT | O_WRONLY | O_APPEND, 0600);
158
159 if (fderr >= 0) {
160 if (fderr != 2)
161 dup2(fderr, 2);
162
163 if (fderr > 2)
164 close(fderr);
165 }
166#endif
167}
168
169String DaemonCommand::GetDescription() const
170{

Callers 2

RunWorkerFunction · 0.85
RunMethod · 0.85

Calls 2

CStrMethod · 0.80
IsEmptyMethod · 0.45

Tested by

no test coverage detected