supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* sv t getty
@ 2006-05-06 18:55 Alex Efros
  0 siblings, 0 replies; only message in thread
From: Alex Efros @ 2006-05-06 18:55 UTC (permalink / raw)


Hi!

As you know, bash can't be killed by TERM, it prefer HUP (or KILL). :)
So, command:
    sv t getty1
will work if user not logged in on tty1 (so it will restart "*getty"
process), and will not work if user is logged in on tty1 and running bash.

To work around this issue (and make 'sv t' logout user in this tty and
restart *getty) I make script /usr/local/bin/term-getty-service and
symlink'ed to it from /var/service/*getty*/control/t .

It's a little complex because I've to kill not only first bash executed by
getty/login, but also all nested bash's (which can be executed for example
by 'mc' or 'su').

--- /usr/local/bin/term-getty-service: ---
#!/bin/bash
bashs() { while [[ -n "$1" ]]; do pgrep -P $1 bash; bashs $(pgrep -P $1); shift; done; }
bashs="$( bashs $(<supervise/pid) )"
[[ -n "$bashs" ]] && kill -HUP $bashs
exit 1 # runsv must send TERM to getty if user don't logged in this console
---

The question is: is there exists more simple way for this task?
BTW, I suppose there a race condition in my script - if user spawn new
nested bash while this script will work between 'pgrep' and 'kill'.

-- 
			WBR, Alex.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-05-06 18:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-06 18:55 sv t getty Alex Efros

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).