Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Do not allow users to leave behind jobs after logout
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
foxtrott
n00b
n00b


Joined: 23 Oct 2003
Posts: 2

PostPosted: Wed Jan 07, 2004 7:40 pm    Post subject: Do not allow users to leave behind jobs after logout Reply with quote

Do not allow users to leave behind jobs after logout

Hi everybody.

Here is a little trick that solves a problem i've got.

1. Wy i did it:
I looked for a way to kill every background-job- that was created by an user, when the user is closing the shell. In common this is done by sending a SIGHUP to the job. But not every shell does this by default. E.g. for the bash you have to switch the option huponexit. But this did not satisfied me, because a user can enable or disable this option at will.
On a normal desktop-system this might be ok, but if you have an pc which is used by several users a day i do not want that every user leaves a running job after he/she lougged out. I want root to be the only one who can determine that a user can leave jobs or not.
Perhaps there is a simple way to do this with shell-builltins but i did not find one so did it described as followed.

To hide shopt is a bad idea because you can configure same cool things that are even useful for normal users.

2. So my way to solve this problem was this:
At first you have to create a file that will be executed at everey shell-lougout:
Code:

touch /etc/profile.logut
echo ´trap "source /etc/profile.logut" 0´ >> /etc/profile


All commands in this file will run at shell-logout (a got place to place a clear ).
Now i wrote this to /etc/profile.logout:
Code:

for pid in `jobs -p`; do
   kill -SIGHUP ${pid}
done


Then you have to set the permission of nohup to rwx------.
If you are using bash you have to hide the builtin disown. A way to do this is:
Code:

alias='echo "disown was disabled by root"'

for all non-root users. You can do this in your /etc/profile

Thats it, a very simple way. No user should be able to leave a job after he/she logged out.


Greets from Germany
Back to top
View user's profile Send private message
ebrostig
Bodhisattva
Bodhisattva


Joined: 20 Jul 2002
Posts: 3152
Location: Orlando, Fl

PostPosted: Wed Jan 07, 2004 9:07 pm    Post subject: Reply with quote

Great write-up!

Another great way of doing this is to use screen.

emerge screen
and then search the forum for some really good threads on how to use screen.

Erik
_________________
'Yes, Firefox is indeed greater than women. Can women block pops up for you? No. Can Firefox show you naked women? Yes.'
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum