From 98193daa8c3cd285c347a91579e1cb11944b7fc0 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 5 Oct 2012 12:07:10 +0200 Subject: [PATCH] login: reuse DEAD_PROCESS utmp entries Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=858009 Signed-off-by: Karel Zak --- login-utils/login.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/login-utils/login.c b/login-utils/login.c index c0cc00a667..8ae5266f13 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -584,14 +584,22 @@ static void log_utmp(struct login_context *cxt) /* If we can't find a pre-existing entry by pid, try by line. * BSD network daemons may rely on this. */ - if (utp == NULL) { + if (utp == NULL && cxt->tty_name) { setutent(); ut.ut_type = LOGIN_PROCESS; - if (cxt->tty_name) - strncpy(ut.ut_line, cxt->tty_name, sizeof(ut.ut_line)); + strncpy(ut.ut_line, cxt->tty_name, sizeof(ut.ut_line)); utp = getutline(&ut); } + /* If we can't find a pre-existing entry by pid and line, try it by id. + * Very stupid telnetd deamons don't set up utmp at all (kzak) */ + if (utp == NULL && cxt->tty_number) { + setutent(); + ut.ut_type = DEAD_PROCESS; + strncpy(ut.ut_id, cxt->tty_number, sizeof(ut.ut_id)); + utp = getutid(&ut); + } + if (utp) memcpy(&ut, utp, sizeof(ut)); else -- 2.47.3