various: clean up isatty() handling
As per https://github.com/systemd/systemd/pull/30547#discussion_r1434371627
This commit is contained in:
@@ -670,12 +670,8 @@ static int chown_terminal(int fd, uid_t uid) {
|
||||
assert(fd >= 0);
|
||||
|
||||
/* Before we chown/chmod the TTY, let's ensure this is actually a tty */
|
||||
if (isatty(fd) < 1) {
|
||||
if (IN_SET(errno, EINVAL, ENOTTY))
|
||||
return 0; /* not a tty */
|
||||
|
||||
return -errno;
|
||||
}
|
||||
if (!isatty_safe(fd))
|
||||
return 0;
|
||||
|
||||
/* This might fail. What matters are the results. */
|
||||
r = fchmod_and_chown(fd, TTY_MODE, uid, GID_INVALID);
|
||||
|
||||
+1
-1
@@ -147,7 +147,7 @@ void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p)
|
||||
|
||||
const char *path = exec_context_tty_path(context);
|
||||
|
||||
if (p && p->stdin_fd >= 0 && isatty(p->stdin_fd))
|
||||
if (p && p->stdin_fd >= 0 && isatty_safe(p->stdin_fd))
|
||||
fd = p->stdin_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))) {
|
||||
|
||||
Reference in New Issue
Block a user