X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Ftty-ask-password-agent.c;h=655bfb9ff5b4667af2cd5cf37aaaafafa86c0cf0;hp=c3c5f7a8b6bce9c3443226de95972b699ca060dd;hb=50483512b901aa216bc12bbe12dc99c1963d79fb;hpb=0cf84693877f060254f04cf38120f52c2aa3059c diff --git a/src/tty-ask-password-agent.c b/src/tty-ask-password-agent.c index c3c5f7a8b..655bfb9ff 100644 --- a/src/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent.c @@ -83,7 +83,7 @@ static int ask_password_plymouth(const char *message, usec_t until, const char * sa.sa.sa_family = AF_UNIX; strncpy(sa.un.sun_path+1, "/org/freedesktop/plymouthd", sizeof(sa.un.sun_path)-1); if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) { - log_error("FIALED TO CONNECT: %m"); + log_error("FAILED TO CONNECT: %m"); r = -errno; goto finish; } @@ -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);