LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-30-2007, 10:51 AM   #1
JudyL
LQ Newbie
 
Registered: Aug 2007
Location: Florida, USA
Distribution: Ubuntu
Posts: 29

Rep: Reputation: 15
notification of user login and logout


Hi all,

I'm new to Linux programming (but not programming in general having done Windows for over 20 years), so be gentle

I've got a program that is started on boot and runs until system shutdown. It is started via an Upstart script. This program needs to know when a user logs in so that it can display an icon on the taskbar, like the volume control, when a user logs in and then remove that icon when the desktop is shutdown when the user logs out.

Simple question - how to receive notifications / signals / events that a user has logged in and logged out? Basically, I need the Linux equivalent of the functionality of the Windows WinLogon notification package. I've searched but haven't found anything in the mass of items returned from Google. The answer is probably in there somewhere, but I haven't managed to find it yet.

Ubuntu 7.04

Thanks,
Judy

Last edited by JudyL; 08-30-2007 at 10:52 AM. Reason: misspelling in title
 
Old 08-30-2007, 01:03 PM   #2
cconstantine
Member
 
Registered: Dec 2005
Distribution: RedHat, Ubuntu
Posts: 101

Rep: Reputation: 15
This isn't a "great" solution, but perhaps some useful "how Un*xland works" ideas will get you started in a good direction.

You could tweak everyone's rc scripts. This would work if what you're doing is a feature. That is, if some user messes with the setup and this 'feature' stops working, it that a security problem, or a "well, duh, you broke it, don't complain" issue. If your user's default shell is Bash [other shells have similar files], you can add shell commands to their .bash_profile (exec'd when bash is starting as a *login* shell), and .bash_logout. Put the real shell scripts somewhere root owned, give everyone execute, but not read perms on the scripts. Then they can mess with the line in their rc scripts which executes the script but not see what's going on. In your 'controller' scripts, send a SIGUSR1 (or whatever signal your daemon expects).

Alternatively, I bet there's some module you can configure in with the PAM system. But I'm not much of a PAM hacker...

-c

Last edited by cconstantine; 08-30-2007 at 01:04 PM.
 
Old 08-30-2007, 01:39 PM   #3
JudyL
LQ Newbie
 
Registered: Aug 2007
Location: Florida, USA
Distribution: Ubuntu
Posts: 29

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by cconstantine View Post
This isn't a "great" solution, but perhaps some useful "how Un*xland works" ideas will get you started in a good direction.

You could tweak everyone's rc scripts. <snip>.

Alternatively, I bet there's some module you can configure in with the PAM system.

-c
That's an option since I do control the whole system. This will be an embedded system when I'm done but ... I'd rather something a little more elegant since some of our customers will eventually get the source for this thing and a single script or one module hack is much easier to document than changing every logon script.

Haven't looked at the PAM at all. I'll take a look-see.

Thanks for the thoughts!!
J
 
Old 08-30-2007, 02:13 PM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
/etc/profile is run by every single user at logon.

add a line in there:
/usr/bin/local/check_user

And then check_user "notifies" the daemon (that's what your login screen diddler is)
that such and such a pty or tty has logged in by sending a signal to the daemon.
There are signal semantics that allow extra information to be included with the signal.

Or you can use message queues. Or even a file with just a SIGUSR1 - a user defined signal to tell the screen diddler to read the file now, dammit.
 
Old 08-30-2007, 02:18 PM   #5
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Even better than all these suggestions, you decide:
Go to advanced linux programming and download chapter 5 on interprocess communication - what you want to do.
http://www.advancedlinuxprogramming.com/alp-folder
 
Old 08-30-2007, 02:43 PM   #6
JudyL
LQ Newbie
 
Registered: Aug 2007
Location: Florida, USA
Distribution: Ubuntu
Posts: 29

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jim mcnamara View Post
/etc/profile is run by every single user at logon.

add a line in there:
/usr/bin/local/check_user

And then check_user "notifies" the daemon (that's what your login screen diddler is)
that such and such a pty or tty has logged in by sending a signal to the daemon.
There are signal semantics that allow extra information to be included with the signal.

Or you can use message queues. Or even a file with just a SIGUSR1 - a user defined signal to tell the screen diddler to read the file now, dammit.
Adding something to the script run on every logon is perfect for the logon side of this. Is there something comparable for logout? I'm very weak on linux startup and shutdown procedures along with user login and logoff procedures, and where the info that controls the process comes from.

Re your other post about IPC: thanks for the pointer but I didn't really need it. I'm well-versed in that concept. Finding the linux equivalents for mutexes, critical sections and signals was simple compared to finding this equivalent. The communication itself is not my problem - it's finding something / somewhere to trigger the act of communication.

Thanks!
J

Last edited by JudyL; 08-30-2007 at 02:45 PM.
 
Old 08-30-2007, 03:10 PM   #7
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
There is no "logout" per se. And I do not see why you have to remove the icon. If the user's primary controlling terminal is no longer there the icon cannot show. Why?
Because the window (terminal) is gone as well.

I'm also very fuzzy as to why you can't have /etc/profile simply add the widget to the desktop in the first place. Why do you need an extra process out there to do that?

/etc/profile is only accesssed when a user logs into a terminal. I'm confused, but I think this may be a Windows thing getting ported to UNIX simply because that's the way it works in Windows.
 
Old 08-30-2007, 03:45 PM   #8
JudyL
LQ Newbie
 
Registered: Aug 2007
Location: Florida, USA
Distribution: Ubuntu
Posts: 29

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jim mcnamara View Post
There is no "logout" per se. And I do not see why you have to remove the icon. If the user's primary controlling terminal is no longer there the icon cannot show. Why?
Because the window (terminal) is gone as well.

I'm also very fuzzy as to why you can't have /etc/profile simply add the widget to the desktop in the first place. Why do you need an extra process out there to do that?

/etc/profile is only accesssed when a user logs into a terminal. I'm confused, but I think this may be a Windows thing getting ported to UNIX simply because that's the way it works in Windows.
Let me explain a bit about what it is. The system will be an embedded system - single board computer primarily used without user interface. The process creates a number of sockets that accept connections from the "real" GUI running across the network. The process then handles the commands sent across the net via the sockets and controls the custom hardware hanging off the SBC. Primary control is via the net. The system probably won't even have a monitor / mouse / keyboard but it might (in fact, it does when I'm the user testing some new function!). If a user happens to login directly on the the embedded system, the process notes that fact and displays the tray icon. This is a visual indicator to the user that the process initialized successfully. If the user clicks the tray icon, a logging window will appear detailing the actions taken by the process.

I don't want to create a file to contain the logging information, or use the existing Linux log files, because the system runs from compact flash only, and I don't want the extra write cycles to the CF. The process maintains a circular memory buffer containing the logging messages and thus avoids CF writes. In the final system, most built-in logging will be turned off for that reason.

The /etc/profile could add the tray icon widget but then there would need to be a second process that controls the widget and communicates with the initial process. Seems simpler to me to have only one process (except for the do-nothing-but-one-signal process launched by /etc/profile) do it all than writing a second process that has all the additional IPC passing the logging messages back and forth.

I was interested in logout so that the process could perform a neat cleanup of the potential logging window and the task bar widget. If there is no way to tell, I'll just validate the window before I do any communication with it and do the cleanup once the window is invalid.

Hope that explains the "why" well enough.
J
 
Old 08-31-2007, 10:26 AM   #9
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
You can't tell that a process has logged off very easily. That's correct.

You would have to poll.

The only way to do this, low-tech, is to go make all user processes on the system a subshell of /etc/profile. ie., exec a new shell for the user in /etc/profile. When the user exits that shell, /etc/profile will know and can act. sudo can be set up to do this as well. Avoid sudo unless all of your users are privileged by default, which is prolly a terrible idea all by itself.

For logouts, you cannot depend absolutely on looking for the absence of a pid, because another process could be using the same pid right now, pid values are assigned sequentially and rollover.
 
Old 08-31-2007, 10:47 AM   #10
JudyL
LQ Newbie
 
Registered: Aug 2007
Location: Florida, USA
Distribution: Ubuntu
Posts: 29

Original Poster
Rep: Reputation: 15
I had a thought about this last night after I was home from work, and I'd like to verify my assumption, if you know. Given that the tray icon widget is present in the taskbar, I assume that the window widget will receive a shutdown event of some sort as the user's desktop is being closed down during the logout process. If that assumption is correct, I'll just catch that notification and use it as my indicator that the user has logged out.

True assumption? If so, that solves my problem. /etc/profile for login and this for logout.

Judy
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
AntiVir Notification to User usaf_sp SUSE / openSUSE 2 11-04-2006 01:41 PM
Cannot Loin At Console But Can Log In Remotely incognito_kanchi Linux - Security 3 10-13-2006 02:14 PM
Force logout of user. Cannot erase user account. philippeP Linux - General 5 07-12-2006 11:22 AM
callback or notification from kernel to user space yhus Programming 5 09-18-2005 09:41 PM
KDE Logout Notification killing sound server. glenns530 Mandriva 1 11-25-2003 04:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration