Skip to content

Commit 7a7c893

Browse files
afazekashaircommander
authored andcommitted
log fds more permissive
Since #112 the anonymous pipes are supposed to be more permissive. Restoring the permissive state by default. Platforms which has a documented EINVAL usage for fchmod(2) indicates the fd in context is not supporting fchmod(2). In order to not have annoying logs in those cases the warning is omitted. Close #429 Signed-off-by: afazekas <[email protected]>
1 parent c26648e commit 7a7c893

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: src/conmon.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -236,25 +236,29 @@ int main(int argc, char *argv[])
236236
_pexit("Failed to unblock signals");
237237

238238
if (!logging_is_passthrough()) {
239+
/*
240+
* EINVAL indicates the type of file descriptor used is not supporting fchmod(2) on the given platform.
241+
* Only more unusual cases are logged.
242+
*/
239243
if (workerfd_stdin < 0)
240244
workerfd_stdin = dev_null_r;
241245
if (dup2(workerfd_stdin, STDIN_FILENO) < 0)
242246
_pexit("Failed to dup over stdin");
243-
if (workerfd_stdin != dev_null_r && isatty(workerfd_stdin) && fchmod(STDIN_FILENO, 0777) < 0)
247+
if (workerfd_stdin != dev_null_r && fchmod(STDIN_FILENO, 0777) < 0 && errno != EINVAL)
244248
nwarn("Failed to chmod stdin");
245249

246250
if (workerfd_stdout < 0)
247251
workerfd_stdout = dev_null_w;
248252
if (dup2(workerfd_stdout, STDOUT_FILENO) < 0)
249253
_pexit("Failed to dup over stdout");
250-
if (workerfd_stdout != dev_null_w && isatty(workerfd_stdout) && fchmod(STDOUT_FILENO, 0777) < 0)
254+
if (workerfd_stdout != dev_null_w && fchmod(STDOUT_FILENO, 0777) < 0 && errno != EINVAL)
251255
nwarn("Failed to chmod stdout");
252256

253257
if (workerfd_stderr < 0)
254258
workerfd_stderr = workerfd_stdout;
255259
if (dup2(workerfd_stderr, STDERR_FILENO) < 0)
256260
_pexit("Failed to dup over stderr");
257-
if (workerfd_stderr != dev_null_w && isatty(workerfd_stderr) && fchmod(STDERR_FILENO, 0777) < 0)
261+
if (workerfd_stderr != dev_null_w && fchmod(STDERR_FILENO, 0777) < 0 && errno != EINVAL)
258262
nwarn("Failed to chmod stderr");
259263
}
260264
/* If LISTEN_PID env is set, we need to set the LISTEN_PID

0 commit comments

Comments
 (0)