Skip to content

Commit

Permalink
Linux 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.

Close containers#429
  • Loading branch information
afazekas committed Jun 7, 2023
1 parent c26648e commit 0f092d0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/conmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ static void disconnect_std_streams(int dev_null_r, int dev_null_w)

#define DEFAULT_UMASK 0022

#ifdef __linux__
/* Linux does not needs tty check*/
#define ISATTY(x) true
#else
#define ISATTY(x) isatty(x)
#endif

int main(int argc, char *argv[])
{
setlocale(LC_ALL, "");
Expand Down Expand Up @@ -240,21 +247,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 0f092d0

Please sign in to comment.