moved fd modifying stuff to log.c

master
Taiyu 9 years ago
parent c9d1eb1e02
commit f798e9bb0b

@ -6,7 +6,6 @@
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <ctype.h>
#include "stringop.h"
#include "layout.h"
@ -20,7 +19,7 @@ struct modifier_key {
uint32_t mod;
};
struct modifier_key modifiers[] = {
static struct modifier_key modifiers[] = {
{ XKB_MOD_NAME_SHIFT, WLC_BIT_MOD_SHIFT },
{ XKB_MOD_NAME_CAPS, WLC_BIT_MOD_CAPS },
{ XKB_MOD_NAME_CTRL, WLC_BIT_MOD_CTRL },
@ -44,14 +43,16 @@ static bool checkarg(int argc, char *name, enum expected_args type, int val) {
return true;
}
sway_log(L_ERROR, "Invalid %s command."
"(expected more then %d arguments, got %d", name, val, argc);
"(expected more then %d argument%s, got %d",
name, val, (char*[2]){"s", ""}[argc==1], argc);
break;
case EXPECTED_LESS_THEN:
if (argc < val) {
return true;
};
sway_log(L_ERROR, "Invalid %s command."
"(expected less then %d arguments, got %d", name, val, argc);
"(expected less then %d argument%s, got %d",
name, val, (char*[2]){"s", ""}[argc==1], argc);
break;
case EXPECTED_SAME_AS:
if (argc == val) {
@ -119,22 +120,6 @@ static bool cmd_exec_always(struct sway_config *config, int argc, char **argv) {
if (cleanup == false) {
signal(SIGCHLD, cmd_exec_cleanup);
cleanup = true;
/* Set it so filedescriptors are closed for executed programs */
int flag_out = fcntl(STDOUT_FILENO, F_GETFD);
int flag_in = fcntl(STDIN_FILENO, F_GETFD);
int flag_err = fcntl(STDERR_FILENO, F_GETFD);
if (flag_out != -1) {
flag_out |= FD_CLOEXEC;
fcntl(STDOUT_FILENO, F_SETFD, flag_out);
}
if (flag_in != -1) {
flag_in |= FD_CLOEXEC;
fcntl(STDIN_FILENO, F_SETFD, flag_in);
}
if (flag_err != -1) {
flag_err |= FD_CLOEXEC;
fcntl(STDERR_FILENO, F_SETFD, flag_err);
}
}
if (checkarg(argc, "exec_always", EXPECTED_MORE_THEN, 0) == false) {

@ -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) {

Loading…
Cancel
Save