Merge pull request #34044 from poettering/isatty-fixes

fixes around isatty() handling
This commit is contained in:
Yu Watanabe
2024-08-20 20:36:07 +09:00
committed by GitHub
21 changed files with 47 additions and 37 deletions
+3 -3
View File
@@ -8,6 +8,7 @@
#include "exec-util.h"
#include "log.h"
#include "process-util.h"
#include "terminal-util.h"
static pid_t agent_pid = 0;
@@ -17,9 +18,8 @@ int ask_password_agent_open(void) {
if (agent_pid > 0)
return 0;
/* We check STDIN here, not STDOUT, since this is about input,
* not output */
if (!isatty(STDIN_FILENO))
/* We check STDIN here, not STDOUT, since this is about input, not output */
if (!isatty_safe(STDIN_FILENO))
return 0;
if (!is_main_thread())
+2 -2
View File
@@ -988,14 +988,14 @@ int ask_password_auto(
if (FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED) &&
req && req->keyring &&
(FLAGS_SET(flags, ASK_PASSWORD_NO_TTY) || !isatty(STDIN_FILENO)) &&
(FLAGS_SET(flags, ASK_PASSWORD_NO_TTY) || !isatty_safe(STDIN_FILENO)) &&
FLAGS_SET(flags, ASK_PASSWORD_NO_AGENT)) {
r = ask_password_keyring(req, flags, ret);
if (r != -ENOKEY)
return r;
}
if (!FLAGS_SET(flags, ASK_PASSWORD_NO_TTY) && isatty(STDIN_FILENO))
if (!FLAGS_SET(flags, ASK_PASSWORD_NO_TTY) && isatty_safe(STDIN_FILENO))
return ask_password_tty(-EBADF, req, until, flags, NULL, ret);
if (!FLAGS_SET(flags, ASK_PASSWORD_NO_AGENT))
+2 -2
View File
@@ -555,8 +555,8 @@ int _fork_agent(const char *name, const int except[], size_t n_except, pid_t *re
/* In the child: */
stdout_is_tty = isatty(STDOUT_FILENO);
stderr_is_tty = isatty(STDERR_FILENO);
stdout_is_tty = isatty_safe(STDOUT_FILENO);
stderr_is_tty = isatty_safe(STDERR_FILENO);
if (!stdout_is_tty || !stderr_is_tty) {
int fd;
+1 -1
View File
@@ -2391,7 +2391,7 @@ int table_print(Table *t, FILE *f) {
if (t->width != 0 && t->width != SIZE_MAX)
table_effective_width = t->width;
else if (t->width == 0 ||
((pass > 0 || !any_soft) && (pager_have() || !isatty(STDOUT_FILENO))))
((pass > 0 || !any_soft) && (pager_have() || !isatty_safe(STDOUT_FILENO))))
table_effective_width = table_requested_width;
else
table_effective_width = MIN(table_requested_width, columns());
+2 -1
View File
@@ -14,6 +14,7 @@
#include "polkit-agent.h"
#include "process-util.h"
#include "stdio-util.h"
#include "terminal-util.h"
#include "time-util.h"
#if ENABLE_POLKIT
@@ -31,7 +32,7 @@ int polkit_agent_open(void) {
return 0;
/* We check STDIN here, not STDOUT, since this is about input, not output */
if (!isatty(STDIN_FILENO))
if (!isatty_safe(STDIN_FILENO))
return 0;
if (!is_main_thread())
+1 -1
View File
@@ -32,7 +32,7 @@ static int write_to_terminal(const char *tty, const char *message) {
return -errno;
if (!isatty_safe(fd))
return -errno;
return -ENOTTY;
return loop_write_full(fd, message, SIZE_MAX, TIMEOUT_USEC);
}