From: Lennart Poettering Date: Fri, 3 Aug 2018 19:30:16 +0000 (+0200) Subject: core: when setting up PAM, try to get tty of STDIN_FILENO if not set explicitly X-Git-Tag: v240~829 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3cd24c1aa93b17420430ad6e413223dfd1b52355;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/core/execute.c b/src/core/execute.c index 67f6dbd600c..e2651024333 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)