diff options
author | Taiyu <taiyu.len@gmail.com> | 2015-08-13 00:24:03 -0700 |
---|---|---|
committer | Taiyu <taiyu.len@gmail.com> | 2015-08-13 00:24:03 -0700 |
commit | f798e9bb0bc667d07283f32d1d83b6223d375a03 (patch) | |
tree | 962841ebe54827df9800a4550e9c2bbe105090e3 /sway/log.c | |
parent | c9d1eb1e028b64a612de80bd701cb0c795fd5b2d (diff) |
moved fd modifying stuff to log.c
Diffstat (limited to 'sway/log.c')
-rw-r--r-- | sway/log.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -2,6 +2,8 @@ #include <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> int colored = 1; int v = 0; @@ -15,6 +17,16 @@ const char *verbosity_colors[] = { void init_log(int verbosity) { v = verbosity; + /* set FD_CLOEXEC flag to prevent programs called with exec to write into + * logs */ + int i, flag; + int fd[] = { STDOUT_FILENO, STDIN_FILENO, STDERR_FILENO }; + for (i = 0; i < 3; ++i) { + flag = fcntl(fd[i], F_GETFD); + if (flag != -1) { + fcntl(fd[i], F_SETFD, flag | FD_CLOEXEC); + } + } } void sway_log_colors(int mode) { |