[comp.sys.att] getty control

jeff@polyof.UUCP (A1 jeff giordano ) (12/21/88)

This is a little utility i whipped up to control the getty
on ph0 of my UNIX-PC.  I have only one phone line and
wanted to have the machine available to some of my friends
at night.  I have been using this setup for about six months
without a hitch, so i think it is safe and stable.  None
of the programs run set uid so there should be no security
holes.  Enjoy!

INET: jeff@polyof.poly.edu
UUCP: ...!trixie!polyof!jeff


this is a sharfile remove everything above this line.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo README
sed -e 's/^X//' <<"EOFREADME" >README
XI only have one phone line, and wanted to be able to
Xto have data communication at night.  There seemed to
Xbe no preset way to do this so I made this up.  I have been using
Xstart_getty for about six months and have not had a problem yet.
X
XWhat I did was to set up another run level, level 3, that included
Xa getty for /dev/ph0.  However getty does not check the phoneline
Xto see if it is off-hook first.  This can lead to cut off phone
Xcalls.  So before changing the run level, I check the phone.
XIf it is off hook I sleep until it goes on-hook.  The telinit
Xcan then be done with out the fear of having phone
Xcalls cut off.  There was also another problem.  The phone manager
Xseemed to get in the way.  So instead of trying to deal with it
XI just kill it, and forget it.  If you want to keep it running
Xduring the daytime change stop_getty to restart it.
X
X
XInstructions:
X
X1) change your inittab to look like this:
X   (note the extra run levels)
X
Xis:2:initdefault:
Xrc::bootwait:/etc/rc > /dev/null 2>&1
X vid:23:respawn:/etc/getty window 9600
X ph0:3:respawn:/etc/getty ph0 1200
X:ph1:2:respawn:/etc/getty ph1 1200
X 000:23:respawn:/etc/getty tty000 9600
X
X2) add the following lines to your crontab
X   (put in any times that you like)
X
X  01 01 * * * /bin/su root -c "/usr/local/bin/start_getty > /dev/null"
X  01 06 * * * /bin/su root -c "/usr/local/bin/stop_getty > /dev/null"
X
X3) put start_getty, stop_getty, & phonetest into /usr/local/bin.
X
XNow every day at the specified time your computer will start and stop a getty.
X
XEnjoy this.  If you find any bugs mail me at:
XINET: jeff@polyof.poly.edu
XUUCP: ...!trixie!polyof!jeff
X
XI an NOT responsible for any problems or damage caused by these programs.
EOFREADME
echo start_getty
sed -e 's/^X//' <<"EOFstart_getty" >start_getty
X# Geoffrey Giordano
X# INET: jeff@polyof.poly.edu (128.238.10.100)
X# UUCP: ...!trixie!polyof!jeff
X# 
X# this shell script first kills off the phone manager (it gets in the way)
X# and removes all its lock files.  It also fixes /etc/inittab because the
X# phone manager likes to edit it.
X# it then makes sure that the phone line is clear
X# before starting the getty. 
X# on my system i have the getty for /dev/ph0
X# set to run at init level 3.  be sure to alter your /etc/inittab
X# to reflect that.
X#
X# i only wrote this. i am not responsible for an problems
X# or damage caused by its use.
X#
X# see if the phone manager is running, if yes kill it. if not forget it.
Xps -e | grep "ph" | \
X	while read PID TTY TIME COMMAND
Xdo
X	if [ "$COMMAND" = "ph" ]
X	then
X		if kill $PID 
X		then
X			rm /usr/spool/uucp/LTMP* /usr/spool/uucp/*.LCK
X			.phclr &
X			ed /etc/inittab << XXX
X				/ph0
X				s/^:/ /
X				w
X				q
XXXX
X		fi
X	fi
Xdone
X# check the phone line.  phonetest blocks until /dev/phx is free
X# then do a telinit
Xif /usr/local/bin/phonetest /dev/ph0
Xthen
X	if `telinit 3 2>/dev/null`
X	then
X		date
X		echo "getty started"
X		echo "\n\n"
X	else
X		date
X		echo "unable to start getty"
X		echo "\n\n"
X	fi
Xelse 
X	date
X	echo 'phone test failed'
Xfi
EOFstart_getty
echo stop_getty
sed -e 's/^X//' <<"EOFstop_getty" >stop_getty
X# Geoffrey Giordano
X# INET: jeff@polyof.poly.edu
X# UUCP: ...!trixie!polyof!jeff
X# 
X# this shell script resets the run level to 2.
X# 
X# i only wrote this. I am not responsible for any
X# problems or damage caused by the use of this program.
Xif `telinit 2 2>/dev/null`
Xthen
X	date
X	echo "getty stopped\n\n"
Xelse
X	date
X	echo "unable to stop getty \n\n"
Xfi
EOFstop_getty
echo phonetest.c
sed -e 's/^X//' <<"EOFphonetest.c" >phonetest.c
X/* Geoffrey Giordano
X * phonetest.c
X *
X * This is a little utility that checks the phoneline specified on
X * the commandline, for activity.  If the phone is off hook the
X * program goes to sleep until the phone goes back on hook.
X * It is useful for checking and waiting for the phone line
X * when starting a getty on the line. Used by start_getty.
X *
X * please feel free to distribute, mutilate, hack, etc
X * this code, but please give credit where credit is due.
X *
X * I only wrote this. I am not responsible for any problems
X * or damage caused by this program.  Please report any bugs
X * to: jeff@polyof.poly.edu (128.238.10.100) or
X * ...!trixie!polyof!jeff.
X *
X * enjoy
X */
X#include <fcntl.h>
X#include <sys/phone.h>
X#include <signal.h>
X
X#define SLEEPTIME 1500
X
Xhandler()
X{
X	/* do nothing just return, this will wake up the sleep */
X}
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X	int phone;
X	struct updata phonedata;
X
X	if (argc < 2) {
X		printf("Usage: %s /dev/phx\n where x is either 0 or 1\n", argv[0]);
X		exit(-1);
X	}
X	phone = open(argv[1], O_RDONLY);	/* open for voice */
X	if (phone < 0) {
X		printf("Error: %s cannot open %s\n", argv[0], argv[1]);
X		exit(-1);
X	}
X#ifdef DEBUG
X	printf("phone open\n");
X#endif
X	signal(SIGPHONE, handler);
X	ioctl(phone, PIOCGETP, &phonedata);
X	while (phonedata.c_linestatus != 0) {
X		sleep(SLEEPTIME);
X		ioctl(phone, PIOCGETP, &phonedata);
X	}
X	close(phone);
X}
EOFphonetest.c