From 3cd24c1aa93b17420430ad6e413223dfd1b52355 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 3 Aug 2018 21:30:16 +0200 Subject: [PATCH] core: when setting up PAM, try to get tty of STDIN_FILENO if not set explicitly When stdin/stdout/stderr is initialized from an fd, let's read the tty name of it if we can, and pass that to PAM. This makes sure that "machinectl shell" sessions have proper TTY fields initialized that "loginctl" then shows. --- src/core/execute.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/core/execute.c b/src/core/execute.c index 67f6dbd600..e265102433 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1158,6 +1158,16 @@ static int setup_pam( goto fail; } + if (!tty) { + _cleanup_free_ char *q = NULL; + + /* Hmm, so no TTY was explicitly passed, but an fd passed to us directly might be a TTY. Let's figure + * out if that's the case, and read the TTY off it. */ + + if (getttyname_malloc(STDIN_FILENO, &q) >= 0) + tty = strjoina("/dev/", q); + } + if (tty) { pam_code = pam_set_item(handle, PAM_TTY, tty); if (pam_code != PAM_SUCCESS)