diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-10-21 14:10:52 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-10-21 14:15:21 +0200 |
commit | eda91cf080ec2ba0c17be3d63d77ff874b5bd24a (patch) | |
tree | dc13744189942aca1ee1a1ee0c4946255215d88e /src/tty-ask-password-agent | |
parent | ask-password-api: don't accidentally create a dir, when we don't want one (diff) | |
download | systemd-eda91cf080ec2ba0c17be3d63d77ff874b5bd24a.tar.xz systemd-eda91cf080ec2ba0c17be3d63d77ff874b5bd24a.zip |
tty-askpw-agent: modernize wall_tty_match() a bit
Diffstat (limited to 'src/tty-ask-password-agent')
-rw-r--r-- | src/tty-ask-password-agent/tty-ask-password-agent.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index ce0a598d87..8b83212755 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -21,6 +21,7 @@ #include "build.h" #include "conf-parser.h" #include "constants.h" +#include "devnum-util.h" #include "dirent-util.h" #include "exit-status.h" #include "fd-util.h" @@ -95,32 +96,29 @@ static bool wall_tty_match(const char *path, bool is_local, void *userdata) { struct stat st; if (lstat(path, &st) < 0) { - log_debug_errno(errno, "Failed to stat %s: %m", path); + log_debug_errno(errno, "Failed to stat TTY '%s', not restricting wall: %m", path); return true; } if (!S_ISCHR(st.st_mode)) { - log_debug("%s is not a character device.", path); + log_debug("TTY '%s' is not a character device, not restricting wall.", path); return true; } - /* We use named pipes to ensure that wall messages suggesting - * password entry are not printed over password prompts - * already shown. We use the fact here that opening a pipe in - * non-blocking mode for write-only will succeed only if - * there's some writer behind it. Using pipes has the - * advantage that the block will automatically go away if the - * process dies. */ + /* We use named pipes to ensure that wall messages suggesting password entry are not printed over + * password prompts already shown. We use the fact here that opening a pipe in non-blocking mode for + * write-only will succeed only if there's some writer behind it. Using pipes has the advantage that + * the block will automatically go away if the process dies. */ _cleanup_free_ char *p = NULL; - if (asprintf(&p, "/run/systemd/ask-password-block/%u:%u", major(st.st_rdev), minor(st.st_rdev)) < 0) { + if (asprintf(&p, "/run/systemd/ask-password-block/" DEVNUM_FORMAT_STR, DEVNUM_FORMAT_VAL(st.st_rdev)) < 0) { log_oom_debug(); return true; } _cleanup_close_ int fd = open(p, O_WRONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY); if (fd < 0) { - log_debug_errno(errno, "Failed to open the wall pipe: %m"); + log_debug_errno(errno, "Failed to open the wall pipe for TTY '%s', not restricting wall: %m", path); return 1; } |