🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #921

Re: Hey, what about SIGIO?

#921
From: Jonathan I. Kamens
Date: Fri, 28 Sep 1990 03:50
104 lines
3330 bytes
In article <16329@thorin.cs.unc.edu>, symon@aesop.cs.unc.edu (James Symon) writes:
|> Here are some little test programs I wrote using standard input (the
|> keyboard) to learn how to do signal trapping. I don't think you need
|> to mess with fcntl().

  Your program doesn't work for me unless I add the fcntl I mentioned in my
last message.  In particular, if I compile the program at the end of this
message without DO_ASYNC defined, then it doesn't detect input, but if I
compile it with DO_ASYNC defined, then it does.

  Just because it works without the fcntl on your system, doesn't mean you
should expect it to work that way on other systems.

  Note, too, that if you do the fcntl once on your tty and then forget to turn
it off, the next time you run a program that tries to use SIGIO, it'll work
even if it doesn't do the fcntl, since the FASYNC will stay in effect on the
tty line.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710

------------------------------------------------------------------

#include <stdio.h>
#include <signal.h>
#include <fcntl.h>

#ifdef DO_ASYNC
int ttyflags;
#endif

void
handler(signal)
int signal;
{
     printf("Got some input.\n");
}

void
inthandler(signal)
int signal;
{
     if (signal)
	  printf("Got an interrupt.\n");
     
#ifdef DO_ASYNC
     if (fcntl(fileno(stdin), F_SETFL, ttyflags & ~FASYNC) < 0) {
	  perror("Couldn't set tty flags");
	  exit(1);
     }
#endif

     exit(0);
}

main()
{
        extern void handler();
        int ndx, smask, oldmask;
        struct sigvec holder;
	
#ifdef DO_ASYNC
	if ((ttyflags = fcntl(fileno(stdin), F_GETFL, 0)) < 0) {
	     perror("Couldn't get tty flags");
	     exit(1);
	}

	if (fcntl(fileno(stdin), F_SETFL, ttyflags | FASYNC) < 0) {
	     perror("Couldn't set tty flags");
	     exit(1);
	}
#endif
	     
        holder.sv_handler = (int(*)()) handler;
        holder.sv_mask = 0;
        holder.sv_flags = 0;

        sigvec(SIGIO,&holder,0);

	holder.sv_handler = (int(*)()) inthandler;
	holder.sv_mask = 0;
	holder.sv_flags = 0;

	sigvec(SIGINT, &holder, 0);
	
        smask = sigmask(SIGIO);

        for(ndx=0; ndx < 4; ndx++)
                {
                oldmask = sigblock(smask);
                printf("smask = %x, oldmask = %x, wait, I'm working . . .\n",smask,oldmask);
                sleep(1);
                printf("Well? Hit return.\n");
                sigpause(oldmask);
                sigsetmask(oldmask);
                }

	inthandler(0); /* to turn off strange modes */
	
	exit(0);
}
Technical Details
Message-ID: <1990Sep28.035027.18086@athena.mit.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!usc!apple!snorkelwacker!bloom-beacon!athena.mit.edu!jik
References: <LUSH.90Sep26102017@athena0.EE.MsState.Edu> <16329@thorin.cs.unc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!know!zaphod.mps.ohio-state.edu!usc!apple!snorkelwacker!bloom-beacon!athena.mit.edu!jik
From: jik@athena.mit.edu (Jonathan I. Kamens)
Newsgroups: comp.unix.programmer
Subject: Re: Hey, what about SIGIO?
Message-ID: <1990Sep28.035027.18086@athena.mit.edu>
Date: 28 Sep 90 03:50:27 GMT
References: <LUSH.90Sep26102017@athena0.EE.MsState.Edu> <16329@thorin.cs.unc.edu>
Sender: daemon@athena.mit.edu (Mr Background)
Reply-To: jik@athena.mit.edu (Jonathan I. Kamens)
Distribution: comp
Organization: Massachusetts Institute of Technology
Lines: 104