Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Nov 1999 15:42:52 -0800 (PST)
From:      Alfred Perlstein <bright@wintelcom.net>
To:        Seva "Semenov" <seva@mtelecom.ru>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: fcntl(0,F_SETFL,O_ASYNC) & signal(SIGIO,rkbd);  don't work in 3.X !!!!
Message-ID:  <Pine.BSF.4.21.9911231541040.4557-100000@fw.wintelcom.net>
In-Reply-To: <383B1755.F432A049@mtelecom.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 24 Nov 1999, Seva Semenov wrote:

> Why my little proggy can't get SIGIO in FreeBSD 3.3-RELEASE, 
> when i type my keyboard?
> 
> In 2.2.6-RELEASE it works right.
> 
> 
> #include <stdio.h>
> #include <fcntl.h>
> #include <string.h>
> #include <sys/types.h>
> #include <unistd.h>
> #include <err.h>
> #include <signal.h>
> #include <syslog.h>
> #include <errno.h>
> #include <err.h>
> 
> void
> rkbd(int sig)
> {
>       int i,j;
>       u_char b[1024],*c;
>       
>       syslog(LOG_DEBUG,"***** ");
> 
>       i=read(0,b,1024);
>       if(i<0)
>            syslog(LOG_DEBUG,"read failed due to %s",strerror(errno));
>       
>       else
>            if(!i)
>                 syslog(LOG_DEBUG,"read null bites");
>            else{
>                 b[i]='\0';
>                 puts("\n******");
>                 fputs(b,stdout);
>                 puts("******\n");
>                 fflush(stdout);
>            }
> }
> 
> int
> main(int argc,char **argv)
> {
>         if(fcntl(0,F_SETFL,O_ASYNC)==-1)
>             err(errno,NULL);
>         signal(SIGIO,rkbd);
>         for(;;){
>                 sleep(10);
>         }
> }

i'm not sure why the change happened, but here's a fix:

--- sigio.old.c Tue Nov 23 19:18:01 1999
+++ sigio.c     Tue Nov 23 19:19:21 1999
@@ -36,7 +36,14 @@
 int
 main(int argc,char **argv)
 {
+               int  arg;
+
+               arg = getpid();
+               
+               
         if(fcntl(0,F_SETFL,O_ASYNC)==-1)
+            err(errno,NULL);
+        if(fcntl(0,F_SETOWN,arg)==-1)
             err(errno,NULL);
         signal(SIGIO,rkbd);
         for(;;){

unless this is strictly a test program you should be using
the constants "STDIN_FILENO" afaik.

-Alfred



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.9911231541040.4557-100000>