Panic Button

Clifford C. Skolnick ccs at lazlo.UUCP
Mon Feb 8 07:18:24 AEST 1988


     This was my answer to when some program locked up my shell on the
Unix-PC.  It is an answer to multiple gettys and ua, both of which I
dislike.  Any comments or suggestions are welcome.
						Cliff Skolnick

---------------------------------Cut Here------------------------------------
/*
Programmer: Clifford C. Skolnick (lazlo!ccs)
Date      : Feb 7, 1988


    One of the most annoying things I find with running a unix system with
only one terminal is the dreaded terminal lockup!  This can be easily
overcome on the Unix-PC with multiple gettys, but that is not without
problems of its own.  I've also seen people start multiple shells, but that
is a pain.
    My solution is "The Panic Button", or whatever you wish to call it.  What
is does it open a small window right next to the "W" icon and wait.  As soon
as that window is selected, it expands and runs a shell.  When you exit the
shell, it returns to its sleeping status.
    Upon logging out, the window is closed up never to be seen again.  It's
only there when you need it.
*/

#include <fcntl.h>
#include <signal.h>
#include <sys/window.h>
#include <sys/errno.h>

/* window stuctur and invoking windows fd are global */
struct uwdata utw;
int oldwd;

main(argc,argv,envp)
int argc;
char *argv[];
char *envp[];
{
    int shutoff(),awake();

    if (fork() != 0)		/* wake up invoking process */
	exit(0);

    oldwd=dup(0);		/* Save invoking window fd */

    signal (SIGINT, SIG_IGN);
    signal (SIGQUIT, SIG_IGN);
    signal (SIGHUP, shutoff);
    signal (SIGTERM, shutoff);

    setscreen();
    signal (SIGWIND, awake);  /* All set to wake up */

    ioctl(oldwd,WIOCSELECT);  /* Select old window */

    for (;;) {
	pause();  /* wait for an interupt */
    }
}

setscreen()
{
    int wd;
    struct utdata utd;

    if ((wd=open("/dev/window",O_RDWR))==-1)
	perror("pbutton: opening /dev/window");

    close(0); /* close all standard fd's and make them the new window */
    close(1);
    close(2);
    dup(wd);
    dup(wd);
    dup(wd);
    close (wd);

    utd.ut_num=WTXTLABEL;
    strcpy(utd.ut_text,"Panic Button");
    ioctl(1,WIOCSETTEXT,&utd);

    resetwin();
}


resetwin()
{
    ioctl(1,WIOCGETD,&utw);

    utw.uw_x=79*utw.uw_hs;
    utw.uw_y=0*utw.uw_vs;
    utw.uw_width=utw.uw_hs;
    utw.uw_height=utw.uw_vs*2;
    utw.uw_uflags=NBORDER;

    ioctl(1,WIOCSETD,&utw);
    write (1,"P",1);
}


int awake()
{
    static char msg[]="Panic button pressed!\n\n";
    int pid;

    ioctl(1,WIOCGETD,&utw);

    if (utw.uw_uflags&KBDWIN) {
	write (1,"\n\n",2);

	utw.uw_x=10*utw.uw_hs;
	utw.uw_y=6*utw.uw_vs;
	utw.uw_width=utw.uw_hs*60;
	utw.uw_height=utw.uw_vs*12;
	utw.uw_uflags=0;

	ioctl(1,WIOCSETD,&utw);

	write(1,msg,strlen(msg));

        if (fork() == 0 )
	    execl("/bin/ksh","ksh",0);
	else
	    wait (0);

	resetwin();

	ioctl(oldwd,WIOCSELECT);
    }

    signal (SIGWIND, awake);
}

int shutoff()
{
    close (0);
    close (1);
    close (2);
    close (oldwd);
    exit(0);
}
-- 
Clifford C. Skolnick    |     - Don't quote me, I'm dain bramaged -
Phone: (716) 427-8046   |                       /   !kodak!gizzmo!   \
PACKET: N1DPH at KA2BHB    |  ...!rutgers!rochester                      lazlo!ccs
BITNET: CCS6277 at RITVAXA |                       \!ritcv!ritcsh!sabin!/



More information about the Comp.sys.att mailing list