[25876] in Athena Bugs

home help back first fref pref prev next nref lref last post

sun4 9.3.8: send_message

daemon@ATHENA.MIT.EDU (Jacob Morzinski)
Tue Jul 27 19:19:31 2004

Message-Id: <200407272318.i6RNIxqE000626@bart-savagewood.mit.edu>
To: bugs@mit.edu
Date: Tue, 27 Jul 2004 19:18:59 -0400
From: "Jacob Morzinski" <jmorzins@mit.edu>
cc: jmorzins@mit.edu
Errors-To: bugs-bounces@mit.edu


Hello,
Here's a long-winded suggestion about backgrounded send_messsage,
SIGTTOU/SIGTTIN, and the third-party-software launcher scripts.


We had someone come into the Sipb office and ask for help with
matlab -- he said that he couldn't run the program.  He was
ssh'ing into a machine that didn't have zephyr, and starting
matlab as "matlab&".  When he did this, his terminal showed him:

[1]  + Suspended (tty output)        matlab

It turns out that the matlab launcher script calls send_message, and
send_message noticed that zephyr wasn't working, so fell back to
trying to use the pager to display a message to the user.  But
because matlab was launched in the background, the shell wouldn't
let the pager draw on the terminal.

The user wasn't savvy enough to realize that "Suspended (tty output)"
meant that he needed to type "fg".  I don't really blame the user
for this... it requires a fair amount of Unix knowledge to make
this connection.


My request: could the send_message program be modified so that
it doesn't try to use a pager when in the background?


I looked into what it would take to do this.

When a process in the background tries to ioctl() the terminal, the
shell sends the process a SIGTTIN or SIGTTOU, and then stops the
process if it doesn't trap the signal.  So, send_message could do a
test to see it it is in the background by attemption to ioctl() the
terminal, and checking to see if it receives a SIGTTIN/SIGTTOU.
If it's background, it would be reasonable to just cat the message
to the screen, instead of paging it.

I don't know what langauge send_message is written in.  I can
provide a small perl script that detects whether it is backgrounded
and sets a variable if it is.  If send_message is a C program,
it would be necessary to use some ioctl call.  While researching the
signals, I ran Solaris truss on many of my test programs.  A variety
of calls trigger the SIGTTIN/SIGTTOU.  Some of the ones I saw were:

ioctl(1, TIOCGWINSZ, ...)
ioctl(3, TCGETA, ...)
ioctl(0, TCGETS, ...)
ioctl(2, TCSETSW, ...)


Here is the perl script.  It needs perl5 locker perl for Curses.pm.
If you run it in the foreground, it prints "$is_bg is 0".  If you
run it in the background, it prints "$is_bg is 1"

#!/afs/athena/contrib/perl5/p -w
use Curses;
my $is_bg = 0;
sub Handler { my ($sig) = shift ; $is_bg = 1; }
$SIG{'TTOU'} = \&Handler;
$SIG{'TTIN'} = \&Handler;
&initscr;
&endwin;
print STDERR "\$is_bg is $is_bg\n";


Thanks for listening.  I think it would give users a pleasant
experience, if the send_message didn't halt matlab just because the
user started matlab in the background.

Regards,
 -Jacob Morzinski

home help back first fref pref prev next nref lref last post