core: make is_terminal_input() and friends inline
Then, rename them to exec_input_is_terminal() and so on.
This commit is contained in:
+11
-31
@@ -128,26 +128,6 @@ static int flag_fds(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool is_terminal_input(ExecInput i) {
|
||||
return IN_SET(i,
|
||||
EXEC_INPUT_TTY,
|
||||
EXEC_INPUT_TTY_FORCE,
|
||||
EXEC_INPUT_TTY_FAIL);
|
||||
}
|
||||
|
||||
static bool is_terminal_output(ExecOutput o) {
|
||||
return IN_SET(o,
|
||||
EXEC_OUTPUT_TTY,
|
||||
EXEC_OUTPUT_KMSG_AND_CONSOLE,
|
||||
EXEC_OUTPUT_JOURNAL_AND_CONSOLE);
|
||||
}
|
||||
|
||||
static bool is_kmsg_output(ExecOutput o) {
|
||||
return IN_SET(o,
|
||||
EXEC_OUTPUT_KMSG,
|
||||
EXEC_OUTPUT_KMSG_AND_CONSOLE);
|
||||
}
|
||||
|
||||
static int open_null_as(int flags, int nfd) {
|
||||
int fd;
|
||||
|
||||
@@ -252,8 +232,8 @@ static int connect_logger_as(
|
||||
context->syslog_priority,
|
||||
!!context->syslog_level_prefix,
|
||||
false,
|
||||
is_kmsg_output(output),
|
||||
is_terminal_output(output)) < 0)
|
||||
exec_output_is_kmsg(output),
|
||||
exec_output_is_terminal(output)) < 0)
|
||||
return -errno;
|
||||
|
||||
return move_fd(TAKE_FD(fd), nfd, false);
|
||||
@@ -325,7 +305,7 @@ static int fixup_input(
|
||||
|
||||
std_input = context->std_input;
|
||||
|
||||
if (is_terminal_input(std_input) && !apply_tty_stdin)
|
||||
if (exec_input_is_terminal(std_input) && !apply_tty_stdin)
|
||||
return EXEC_INPUT_NULL;
|
||||
|
||||
if (std_input == EXEC_INPUT_SOCKET && socket_fd < 0)
|
||||
@@ -531,7 +511,7 @@ static int setup_output(
|
||||
if (e == EXEC_OUTPUT_INHERIT &&
|
||||
o == EXEC_OUTPUT_INHERIT &&
|
||||
i == EXEC_INPUT_NULL &&
|
||||
!is_terminal_input(context->std_input) &&
|
||||
!exec_input_is_terminal(context->std_input) &&
|
||||
getppid() != 1)
|
||||
return fileno;
|
||||
|
||||
@@ -543,7 +523,7 @@ static int setup_output(
|
||||
|
||||
} else if (o == EXEC_OUTPUT_INHERIT) {
|
||||
/* If input got downgraded, inherit the original value */
|
||||
if (i == EXEC_INPUT_NULL && is_terminal_input(context->std_input))
|
||||
if (i == EXEC_INPUT_NULL && exec_input_is_terminal(context->std_input))
|
||||
return open_terminal_as(exec_context_tty_path(context), O_WRONLY, fileno);
|
||||
|
||||
/* If the input is connected to anything that's not a /dev/null or a data fd, inherit that... */
|
||||
@@ -564,7 +544,7 @@ static int setup_output(
|
||||
return open_null_as(O_WRONLY, fileno);
|
||||
|
||||
case EXEC_OUTPUT_TTY:
|
||||
if (is_terminal_input(i))
|
||||
if (exec_input_is_terminal(i))
|
||||
return RET_NERRNO(dup2(STDIN_FILENO, fileno));
|
||||
|
||||
return open_terminal_as(exec_context_tty_path(context), O_WRONLY, fileno);
|
||||
@@ -4880,8 +4860,8 @@ static void prepare_terminal(
|
||||
assert(p);
|
||||
|
||||
/* We only try to reset things if we there's the chance our stdout points to a TTY */
|
||||
if (!(is_terminal_output(context->std_output) ||
|
||||
(context->std_output == EXEC_OUTPUT_INHERIT && is_terminal_input(context->std_input)) ||
|
||||
if (!(exec_output_is_terminal(context->std_output) ||
|
||||
(context->std_output == EXEC_OUTPUT_INHERIT && exec_input_is_terminal(context->std_input)) ||
|
||||
context->std_output == EXEC_OUTPUT_NAMED_FD ||
|
||||
p->stdout_fd >= 0))
|
||||
return;
|
||||
@@ -4921,9 +4901,9 @@ static int setup_term_environment(const ExecContext *context, char ***env) {
|
||||
return 0;
|
||||
|
||||
/* Do we need $TERM at all? */
|
||||
if (!is_terminal_input(context->std_input) &&
|
||||
!is_terminal_output(context->std_output) &&
|
||||
!is_terminal_output(context->std_error) &&
|
||||
if (!exec_input_is_terminal(context->std_input) &&
|
||||
!exec_output_is_terminal(context->std_output) &&
|
||||
!exec_output_is_terminal(context->std_error) &&
|
||||
!context->tty_path)
|
||||
return 0;
|
||||
|
||||
|
||||
+5
-19
@@ -65,20 +65,6 @@
|
||||
#include "utmp-wtmp.h"
|
||||
#include "vpick.h"
|
||||
|
||||
static bool is_terminal_input(ExecInput i) {
|
||||
return IN_SET(i,
|
||||
EXEC_INPUT_TTY,
|
||||
EXEC_INPUT_TTY_FORCE,
|
||||
EXEC_INPUT_TTY_FAIL);
|
||||
}
|
||||
|
||||
static bool is_terminal_output(ExecOutput o) {
|
||||
return IN_SET(o,
|
||||
EXEC_OUTPUT_TTY,
|
||||
EXEC_OUTPUT_KMSG_AND_CONSOLE,
|
||||
EXEC_OUTPUT_JOURNAL_AND_CONSOLE);
|
||||
}
|
||||
|
||||
const char* exec_context_tty_path(const ExecContext *context) {
|
||||
assert(context);
|
||||
|
||||
@@ -151,8 +137,8 @@ void exec_context_tty_reset(const ExecContext *context, const ExecParameters *pa
|
||||
|
||||
if (parameters && parameters->stdout_fd >= 0 && isatty_safe(parameters->stdout_fd))
|
||||
fd = parameters->stdout_fd;
|
||||
else if (path && (context->tty_path || is_terminal_input(context->std_input) ||
|
||||
is_terminal_output(context->std_output) || is_terminal_output(context->std_error))) {
|
||||
else if (path && (context->tty_path || exec_input_is_terminal(context->std_input) ||
|
||||
exec_output_is_terminal(context->std_output) || exec_output_is_terminal(context->std_error))) {
|
||||
fd = _fd = open_terminal(path, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
return (void) log_debug_errno(fd, "Failed to open terminal '%s', ignoring: %m", path);
|
||||
@@ -1000,9 +986,9 @@ static bool exec_context_may_touch_tty(const ExecContext *ec) {
|
||||
return ec->tty_reset ||
|
||||
ec->tty_vhangup ||
|
||||
ec->tty_vt_disallocate ||
|
||||
is_terminal_input(ec->std_input) ||
|
||||
is_terminal_output(ec->std_output) ||
|
||||
is_terminal_output(ec->std_error);
|
||||
exec_input_is_terminal(ec->std_input) ||
|
||||
exec_output_is_terminal(ec->std_output) ||
|
||||
exec_output_is_terminal(ec->std_error);
|
||||
}
|
||||
|
||||
bool exec_context_may_touch_console(const ExecContext *ec) {
|
||||
|
||||
@@ -458,6 +458,26 @@ typedef struct ExecParameters {
|
||||
.pidref_transport_fd = -EBADF, \
|
||||
}
|
||||
|
||||
static inline bool exec_input_is_terminal(ExecInput i) {
|
||||
return IN_SET(i,
|
||||
EXEC_INPUT_TTY,
|
||||
EXEC_INPUT_TTY_FORCE,
|
||||
EXEC_INPUT_TTY_FAIL);
|
||||
}
|
||||
|
||||
static inline bool exec_output_is_terminal(ExecOutput o) {
|
||||
return IN_SET(o,
|
||||
EXEC_OUTPUT_TTY,
|
||||
EXEC_OUTPUT_KMSG_AND_CONSOLE,
|
||||
EXEC_OUTPUT_JOURNAL_AND_CONSOLE);
|
||||
}
|
||||
|
||||
static inline bool exec_output_is_kmsg(ExecOutput o) {
|
||||
return IN_SET(o,
|
||||
EXEC_OUTPUT_KMSG,
|
||||
EXEC_OUTPUT_KMSG_AND_CONSOLE);
|
||||
}
|
||||
|
||||
int exec_spawn(
|
||||
Unit *unit,
|
||||
ExecCommand *command,
|
||||
|
||||
Reference in New Issue
Block a user