| 132 | } |
| 133 | |
| 134 | static 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 | |
| 169 | String DaemonCommand::GetDescription() const |
| 170 | { |