Slackware This Forum is for the discussion of Slackware Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-19-2004, 09:35 PM
|
#1
|
LQ Guru
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852
|
"who" showing users that aren't logged on
I have found recently that "who" shows users that have already logged off. For instance, I was compiling some software, and was logged into 3 ttys on the machine, going back and forth to look at different files. After I logged off on tty 2 and 3, running "who" on tty 1 showed me still logged on 2 and 3. "ps" shows agetty running on those consoles (not bash).
Now, usually, this wouldn't be a problem. However, I made a script that turns the machine off if:
A. Nobody is logged on
and
B. No other computers are active on the LAN
The way it checks if anybody is logged on is to check the output of "who".
This worked fine for about a month. Recently however the machine stayed on, which is when I discovered the "who" problem.
So I need to figure out why "who" isn't updating properly. I imagine it is a problem with the utmp file, but I don't even know where to start looking.
It is also slightly random, some days it works fine, others it doesn't. Though lately, it doesn't work more than it does.
The machine runs Slackware 9.0, and I have not made any changes to the login progress.
|
|
|
09-19-2004, 10:17 PM
|
#2
|
Senior Member
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145
Rep:
|
Take a look at man who.
Maybe you can uso who -l and check if there's a tty in use.
|
|
|
09-19-2004, 10:25 PM
|
#3
|
LQ Guru
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852
Original Poster
|
That's the thing, it shows ttys in use when I know they aren't. I physically logged out of them myself.
I don't think it is a "who" problem really, but more of a problem with "utmp" which is what is supposed to keep track of logged on users.
|
|
|
09-19-2004, 11:50 PM
|
#4
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
You didn't by any chance background a process
on those tty's?
Cheers,
Tink
|
|
|
09-20-2004, 12:14 AM
|
#5
|
LQ Guru
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852
Original Poster
|
No, at least, nothing I initiated.
For example, as a test, I just logged in to the machine on tty 1 - 3. I let them sit there for about a minute, then logged out of each one separately. I didn't run any commands on the consoles except "logout".
I run "who" on tty1, and I get: 2 users logged into tty1 (the previous login, plus the current one) and one user on tty2. Nothing on tty3, which illustrates the randomness of it.
|
|
|
09-23-2004, 08:42 PM
|
#6
|
LQ Guru
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852
Original Poster
|
I still don't have a fix for this problem, unfortunately.
I have checked everything I can think of, but I have yet to turn up anything.
|
|
|
10-05-2004, 12:23 AM
|
#7
|
Member
Registered: Jun 2004
Location: Michigan, USA
Distribution: Ubuntu
Posts: 77
Rep:
|
I've been having the same problem. It is caused (at least in my situation) when a terminal emulator (gnome-terminal, rxvt) doesn't close down cleanly. I don't have a solution for this yet either, but the workaround I use is to not let those terminals update the utmp files.
That is calling rxvt with -ut, or modifying the gnome-terminal settings to disable it:
Edit Current Profile > Title and Command > Update login records
Each terminal program should have settings to disable this. That way they won't allocate a pts and (if you exit X before closing these terminals down) forget to deallocate it.
The only solution I can think of for this is to purge the utmp files somehow but I have no idea how that can be done.
|
|
|
10-05-2004, 01:54 PM
|
#8
|
Member
Registered: Jun 2004
Location: Michigan, USA
Distribution: Ubuntu
Posts: 77
Rep:
|
Thanks to masand and his work at http://masand.sourceforge.net I was able to write a program to purge users that are 'suck' in the system to invalid pts. I don't know if the solution will work for your problem (and I don't take any liability since this is the first release) but here is the code for a small utility that will purge the utmp file of users on invalid lines.
|
|
|
10-05-2004, 09:26 PM
|
#9
|
LQ Guru
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852
Original Poster
|
Glad to see somebody else got this problem worked out.
I have read over the source, but I don't know enough about utmp to figure out what is considered an "invalid" line. Exactly what is the criteria that will cause this program to purge a user?
|
|
|
10-05-2004, 11:27 PM
|
#10
|
Member
Registered: Jun 2004
Location: Michigan, USA
Distribution: Ubuntu
Posts: 77
Rep:
|
There are three conditions checked before a user is purged (marked as DEAD):
1. the user must be not currently marked as dead (still marked as alive on th system)
2. the user must have an entry in /etc/passwd (a valid user with a password)
3. the user must be on a line that doesn't exist.
The third condition simply means that the tty associated with the user login must still be active on the /dev filesystem. This only works for temporary lines given out (like pts in the case of gnome-terminal and rxvt), so if you have users stuck on a tty# this won't help them because even after a user with a tty# logs off the system, the /dev/tty# entry remains there.
If you want to test this I would recommend making a backup of your utmp file and running this to see if any users are purged or not, run `who` and `finger` afterward to see if the results are suitable, otherwise replace the utmp with the backup file.
Let me know, I may be able to tune this to your problem if it is no help.
|
|
|
10-05-2004, 11:30 PM
|
#11
|
Member
Registered: Jun 2004
Location: Michigan, USA
Distribution: Ubuntu
Posts: 77
Rep:
|
Also, if you are worried about this automatic scanning and purging feature, I could add a command line option that only purges active users on the tty specified or something similar.
|
|
|
10-05-2004, 11:44 PM
|
#12
|
LQ Guru
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852
Original Poster
|
Quote:
This only works for temporary lines given out (like pts in the case of gnome-terminal and rxvt), so if you have users stuck on a tty# this won't help them because even after a user with a tty# logs off the system, the /dev/tty# entry remains there.
|
Yes, unfortunately, I have the users on ttys.
My first thought would be to modify the "line_exists" function, so that instead of checking for the /dev/ files, it checks the currently running processes to see if agetty is running on the tty that utmp claims the user is logged on to. Because, obviously, if agetty is running on that tty, then nobody is logged on to it.
There is probably a much more elegant way to do it, but that was my first idea. I'll have to look into it more.
|
|
|
10-06-2004, 01:19 AM
|
#13
|
Member
Registered: Jun 2004
Location: Michigan, USA
Distribution: Ubuntu
Posts: 77
Rep:
|
That is good thinking, but as I was implementing it I was worried about people that may not use agetty or have agetty with a different process name, if they use the switch to kill based on the absence of agetty then it will remove everyone on all ttys.
I will dig a little further and see if there is another way to do that for ttys, but for now I implemented the -tty switch that lets you remove a specified user. The code is here, but be warned anyone that uses it, it will remove the user based on the tty you specify if it is valid (actually logged in) or not, so you could easily pick off logged in users with that switch.
|
|
|
10-06-2004, 01:23 AM
|
#14
|
Member
Registered: Jun 2004
Location: Michigan, USA
Distribution: Ubuntu
Posts: 77
Rep:
|
Oh yeah, and like always, I would recommend making a backup of your utmp file first for testing. I've never actually had it damage my utmp file, but better safe than sorry.
I should probably add a feature that stores backups automatically.
|
|
|
All times are GMT -5. The time now is 04:26 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|