summaryrefslogtreecommitdiff
path: root/src/tty-ask-password-agent.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-02-17 16:29:04 +0100
committerLennart Poettering <lennart@poettering.net>2011-02-17 16:29:04 +0100
commitfc116c6a19877275eabb085cf03f0df23b17c0e9 (patch)
treef230c08a0ef01803a582141210798447bb8ce719 /src/tty-ask-password-agent.c
parent4ff21d85822b521ed6741ef88cb4aaa384539dec (diff)
util: beef up logic to find ctty name
Diffstat (limited to 'src/tty-ask-password-agent.c')
-rw-r--r--src/tty-ask-password-agent.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/tty-ask-password-agent.c b/src/tty-ask-password-agent.c
index 00496e7119..655bfb9ff5 100644
--- a/src/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent.c
@@ -353,13 +353,13 @@ finish:
static int wall_tty_block(void) {
char *p;
- const char *t;
- int fd;
+ int fd, r;
+ dev_t devnr;
- if (!(t = ttyname(STDIN_FILENO)))
- return -errno;
+ if ((r = get_ctty_devnr(&devnr)) < 0)
+ return -r;
- if (asprintf(&p, "/dev/.systemd/ask-password-block/%s", file_name_from_path(t)) < 0)
+ if (asprintf(&p, "/dev/.systemd/ask-password-block/%u:%u", major(devnr), minor(devnr)) < 0)
return -ENOMEM;
mkdir_parents(p, 0700);
@@ -375,8 +375,25 @@ static int wall_tty_block(void) {
}
static bool wall_tty_match(const char *path) {
- int fd;
+ int fd, k;
char *p;
+ struct stat st;
+
+ if (path_is_absolute(path))
+ k = lstat(path, &st);
+ else {
+ if (asprintf(&p, "/dev/%s", path) < 0)
+ return true;
+
+ k = lstat(p, &st);
+ free(p);
+ }
+
+ if (k < 0)
+ return true;
+
+ if (!S_ISCHR(st.st_mode))
+ return true;
/* We use named pipes to ensure that wall messages suggesting
* password entry are not printed over password prompts
@@ -386,7 +403,7 @@ static bool wall_tty_match(const char *path) {
* advantage that the block will automatically go away if the
* process dies. */
- if (asprintf(&p, "/dev/.systemd/ask-password-block/%s", file_name_from_path(path)) < 0)
+ if (asprintf(&p, "/dev/.systemd/ask-password-block/%u:%u", major(st.st_rdev), minor(st.st_rdev)) < 0)
return true;
fd = open(p, O_WRONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);