aboutsummaryrefslogtreecommitdiff
path: root/sway/log.c
diff options
context:
space:
mode:
authorTaiyu <taiyu.len@gmail.com>2015-08-13 00:24:03 -0700
committerTaiyu <taiyu.len@gmail.com>2015-08-13 00:24:03 -0700
commitf798e9bb0bc667d07283f32d1d83b6223d375a03 (patch)
tree962841ebe54827df9800a4550e9c2bbe105090e3 /sway/log.c
parentc9d1eb1e028b64a612de80bd701cb0c795fd5b2d (diff)
moved fd modifying stuff to log.c
Diffstat (limited to 'sway/log.c')
-rw-r--r--sway/log.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/sway/log.c b/sway/log.c
index 188461eb..b9048b34 100644
--- a/sway/log.c
+++ b/sway/log.c
@@ -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) {