Bug 470004

Summary: tty logins stays in sessions list for user switching even if user has already logged out
Product: [Fedora] Fedora Reporter: Michal Hlavinka <mhlavink>
Component: upstartAssignee: Petr Lautrbach <plautrba>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: 12CC: cdahlin, clive.m.messer, eli, fedora, gandr, jreznik, kevin, kzak, lorenzo, ltinkl, ndbecker2, notting, plautrba, rdieter, smparrish, than, tim, tomek, ville.skytta
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Fixed In Version: upstart-0.3.11-4.fc12 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 572199 (view as bug list) Environment:
Last Closed: 2010-03-24 19:35:24 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Bug Depends On:    
Bug Blocks: 501306, 507684, 542138, 556731    
Description Flags
utmp patch
add utmp_clean_id and call it from post-stop stanza
set DEAD_PROCESS for died proccess with pid in utmp table none

Description Michal Hlavinka 2008-11-05 02:49:18 EST
Description of problem:
If user switches to terminal (Ctrl+Alt+Fx) use it and then exits, this terminal stays listed in sessions to switch to

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1.switch to terminal (Ctrl+Alt+F2)
2.enter username and password
4.kde->switch user
Actual results:
"user: TTY login (vt2)" is listed even if session has been already terminated

Expected results:
only active sessions are listed

Additional info:
if you repeat above steps, you can achieve "user: TTY login (vt2)" to be listed twice (three times, four...)
Comment 1 Rex Dieter 2008-11-05 08:55:13 EST

Interesting, I wonder by what method kde uses to determine users logged into tty's... either that's broken or console logins are.

"last" gives interesting results for me:
rdieter1 tty2 ... Wed nov 5 08:52   gone - no logout

except, I *did* logout.
Comment 2 Rex Dieter 2008-11-07 12:45:28 EST
OK, looks like tty logins never finish logging out.  For me, ALT-F2 goto console, login... do stuff... logout... stuck, no login: prompt

Now, who to blame for this? :)
Comment 3 Rex Dieter 2008-11-07 12:46:45 EST
bouncing over to util-linux-ng (owner of login), in hopes of some insight.
Comment 4 Rex Dieter 2008-11-25 12:50:35 EST
Interesting, I can't reproduce anymore, how about you?
Comment 5 Bug Zapper 2008-11-25 23:48:14 EST
This bug appears to have been reported against 'rawhide' during the Fedora 10 development cycle.
Changing version to '10'.

More information and reason for this action is here:
Comment 6 Michal Hlavinka 2008-11-26 04:29:26 EST
I'm in work now, where I have kde 4.1.3 packages from updates-testing and it doesn't work for me. Still the "same" problem. 

I think there is (maybe) one difference: If I try to switch user via "start"->Switch user and select tty console, it starts new session with kdm as if I select "start new session". If I try to switch via screen saver lock or via kdm, it "works" as usual. I don't know if this is new change or if it was working this way already.

I can test also on system updated without updates-testing today later if you want.
Comment 7 Rex Dieter 2009-01-30 09:57:39 EST
I take back comment #4, console logins are still not registerring logout, 'last' still reports only 'gone - no logout'
Comment 8 Karel Zak 2009-03-19 09:19:46 EDT
It seems that /sbin/init from upstart does not care about utmp at all.

(Note that mingetty(8) and login(1) can create a new utmp entry on systems
where init(8) is broken, but init(8) has to set the entry to DEAD_PROCESS
state when user logout and login process has exited).

See utmp man page:

  The first entries ever created result from init(8) processing inittab(5).
  Before an entry is processed, though, init(8) cleans up utmp by setting
  ut_type to DEAD_PROCESS, clearing ut_user, ut_host, and ut_time with null
  bytes for each record which ut_type is not DEAD_PROCESS or RUN_LVL and where
  no process with PID ut_pid exists. If no empty record with the needed ut_id
  can be found, init(8) creates a new one. It sets ut_id from the inittab,
  ut_pid and ut_time to the current values, and ut_type to INIT_PROCESS.

  mingetty(8) (or agetty(8)) locates the entry by the PID, changes ut_type to
  LOGIN_PRO- CESS, changes ut_time, sets ut_line, and waits for connection to be
  established. login(1), after a user has been authenticated, changes ut_type
  to USER_PROCESS, changes ut_time, and sets ut_host and ut_addr. Depending on
  mingetty(8) (or agetty(8)) and login(1), records may be located by ut_line
  instead of the preferable ut_pid.

  When init(8) finds that a process has exited, it locates its utmp entry by
  ut_pid, sets ut_type to DEAD_PROCESS, and clears ut_user, ut_host and ut_time
  with null bytes.

Reassignig to upstart.
Comment 9 Petr Lautrbach 2009-05-20 09:18:35 EDT
Created attachment 344797 [details]
utmp patch

It fixes problem with tty logins which stays in sessions list.

It adds new stanza - utmp - and writes utmp entries and wtmp log
as described in utmp(5).

Needs to add "utmp <id>" to /etc/event.d/tty<id>

Tested againts F10 and devel branch
Comment 10 Bill Nottingham 2009-05-20 10:31:55 EDT
I would greatly prefer to not change the job syntax if at all possible.
Comment 11 Casey Dahlin 2009-05-20 10:37:40 EDT
Historically /sbin/init in upstart hasn't directly altered utmp. The upstart runlevel command does the utmp editing by itself.

Following that pattern, the right way is to create a helper.
Comment 12 Rex Dieter 2009-05-24 10:39:56 EDT
*** Bug 502362 has been marked as a duplicate of this bug. ***
Comment 13 Petr Lautrbach 2009-06-04 10:12:42 EDT
it folows upstart 0.5 roadmap https://lists.ubuntu.com/archives/upstart-devel/2007-October/000468.html: 

Finally init will maintain INIT_PROCESS and DEAD_PROCESS entries in utmp
for jobs that require it, through a "utmp id" stanza.  The general user
of this will the getty job, where such utmp entries are necessary for
correct behaviour.
Comment 14 Petr Lautrbach 2009-06-08 10:08:41 EDT
> Following that pattern, the right way is to create a helper.  

I can't imagine how this helper should work. Do you have any idea about that?

Anyway it has to be somehow handled by init. There should be set line with INIT_PROCESS and right pid (of new process) before running new getty (or another tty process).

> I would greatly prefer to not change the job syntax if at all possible.

It's a way how to tell init what id (representing terminal name suffix) use when writes to utmp line with INIT_PROCESS before exec to getty as long as we don't use inittab for that.
Comment 15 Petr Lautrbach 2009-06-17 12:16:08 EDT
what do you think about this:

create something called utmp-helper (compat/sysv/utmp-helper.c) with usage:

utmp-helper --id <terminal suffix> -- <command for what we need utmp handling>

utmp-helper will do fork(), in child it will save pid of new process, id and INIT_PROCESS to utmp table, call setsid() for controlling tty and execv() to <command for what we need utmp handling>, in parrent it will wait() until child terminates, then set DEAD_PROCESS into utmp table and log to wtmp log.

and then exec line in /etc/event.d/tty* will be changed to:
exec utmp-helper --id 1 -- /sbin/mingetty tty1
Comment 16 Petr Lautrbach 2009-06-18 08:39:06 EDT
looks like upstream will accept patch from Comment #9
Comment 17 Steven M. Parrish 2009-09-07 21:31:33 EDT
Has this patch made it into F10/F11/Rawhide?

Steven M. Parrish - KDE Triage Master
                  - PackageKit Triager
Fedora Bugzappers volunteer triage team
Comment 18 Rex Dieter 2009-09-08 08:31:26 EDT
Afaict, the patch has not been integrated, but I'd love to be wrong.
Comment 19 Ville Skyttä 2009-10-01 11:49:22 EDT
Unfortunately it seems you're not wrong, the problem persists with upstart-0.3.11-1.fc11.x86_64 on F-11, and looks like later versions don't have it either.
Comment 20 Ville Skyttä 2009-10-01 11:49:58 EDT
(In reply to comment #19)
> and looks like later versions don't have it either.

...where with "it" I mean a fix.
Comment 21 Casey Dahlin 2009-10-01 13:34:41 EDT
Upstream is not doing any more releases for 0.3.x. Since it doesn't look like we're advancing to the next version any time soon this should probably be rolled in by us.
Comment 22 Rex Dieter 2009-11-12 16:22:01 EST
confirmed issue remains in f12, rebasing.
Comment 23 Rex Dieter 2009-11-30 07:56:19 EST
*** Bug 542138 has been marked as a duplicate of this bug. ***
Comment 24 Petr Lautrbach 2009-12-04 10:58:33 EST
Created attachment 376109 [details]
add utmp_clean_id and call it from post-stop stanza

another helper suggestion:

call umtp_clean_id in post-stop stanza, eg for /etc/event.d/tty2:

post-stop exec /sbin/utmp_clean_id 2

utmp_clean_id is simple utility which cleans (sets type to DEAD_PROCESS and nulls other rows) lines with given id and type LOGIN_PROCESS or USER_PROCESS.

these patch is related to initscripts that provides /etc/event.d/tty*
Comment 25 Petr Lautrbach 2009-12-04 11:34:40 EST
http://koji.fedoraproject.org/koji/taskinfo?taskID=1849861  scratch build
Comment 26 Petr Lautrbach 2010-03-09 08:54:20 EST
Created attachment 398797 [details]
set DEAD_PROCESS for died proccess with pid in utmp table

(with this patch) init tries to find utmp entry for each tracked process which died. If entry is found, it sets type to DEAD_PROCESS and logs to wtmp log. 

mingetty takes care about setting INIT_PROCESS/LOGIN_PROCESS itself.

There is no need to change anything else like it was in previous patches.

koji scratch build is here http://koji.fedoraproject.org/koji/taskinfo?taskID=2041266
Comment 27 Fedora Update System 2010-03-10 06:50:04 EST
upstart-0.3.11-4.fc12 has been submitted as an update for Fedora 12.
Comment 28 Fedora Update System 2010-03-11 02:20:58 EST
upstart-0.3.11-4.fc12 has been pushed to the Fedora 12 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update upstart'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/upstart-0.3.11-4.fc12
Comment 29 Fedora Update System 2010-03-24 19:35:15 EDT
upstart-0.3.11-4.fc12 has been pushed to the Fedora 12 stable repository.  If problems still persist, please make note of it in this bug report.