Skip to content

Commit

Permalink
log fds more permissive
Browse files Browse the repository at this point in the history
Since containers#112 the anonymous pipes are supposed to be
more permissive. Restoring the permissive state by default.
32816bd introduced the tty check
for FreeBSD, assuming it is needed there.

Close containers#429

Signed-off-by: afazekas <[email protected]>
  • Loading branch information
afazekas committed Jun 8, 2023
1 parent c26648e commit 563abab
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/conmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ static void disconnect_std_streams(int dev_null_r, int dev_null_w)

#define DEFAULT_UMASK 0022

#ifdef __FreeBSD__
#define ISATTY(x) isatty(x)
#else
#define ISATTY(x) true
#endif

int main(int argc, char *argv[])
{
setlocale(LC_ALL, "");
Expand Down Expand Up @@ -240,21 +246,21 @@ int main(int argc, char *argv[])
workerfd_stdin = dev_null_r;
if (dup2(workerfd_stdin, STDIN_FILENO) < 0)
_pexit("Failed to dup over stdin");
if (workerfd_stdin != dev_null_r && isatty(workerfd_stdin) && fchmod(STDIN_FILENO, 0777) < 0)
if (workerfd_stdin != dev_null_r && ISATTY(workerfd_stdin) && fchmod(STDIN_FILENO, 0777) < 0)
nwarn("Failed to chmod stdin");

if (workerfd_stdout < 0)
workerfd_stdout = dev_null_w;
if (dup2(workerfd_stdout, STDOUT_FILENO) < 0)
_pexit("Failed to dup over stdout");
if (workerfd_stdout != dev_null_w && isatty(workerfd_stdout) && fchmod(STDOUT_FILENO, 0777) < 0)
if (workerfd_stdout != dev_null_w && ISATTY(workerfd_stdout) && fchmod(STDOUT_FILENO, 0777) < 0)
nwarn("Failed to chmod stdout");

if (workerfd_stderr < 0)
workerfd_stderr = workerfd_stdout;
if (dup2(workerfd_stderr, STDERR_FILENO) < 0)
_pexit("Failed to dup over stderr");
if (workerfd_stderr != dev_null_w && isatty(workerfd_stderr) && fchmod(STDERR_FILENO, 0777) < 0)
if (workerfd_stderr != dev_null_w && ISATTY(workerfd_stderr) && fchmod(STDERR_FILENO, 0777) < 0)
nwarn("Failed to chmod stderr");
}
/* If LISTEN_PID env is set, we need to set the LISTEN_PID
Expand Down

0 comments on commit 563abab

Please sign in to comment.