slang-users mailing list

[2007 Date Index] [2007 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] need to send signals two times


=?UTF-8?Q?J=C3=B6rg?= Sommer <joerg@xxxxxxxxxxxx> wrote:
>run it with slsh /tmp/test.sl and hit ^C. At me, I have to hit a second
>time ^C to get the output â??got signal 2â??.

The problem is that the "signal" intrinsic established the signal in
such a way that system calls were restarted.  When the signal fired,
the handler implicitly set the signal disposition to interrupt the
system call.  This is why the second ^C caused the fopen to be
interrupted.  In any case, the latest version in the svn repository
corrects this behavior by setting the disposition to always interrupt
system calls.

Incidently, you might find it interesting to compare the slsh version
with the corresponding C version, which is appended below.  Thanks,
--John

#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

static int quit = 0;
static void sig_handler (int sig)
{
   (void) sig;
    quit++;
}

int main (int argc, char **argv)
{
   char *fifo_name = "/tmp/testfifo";
   FILE *fp;

   signal(SIGHUP, &sig_handler);
   signal(SIGINT, &sig_handler);
   signal(SIGQUIT, &sig_handler);

   if (mkfifo(fifo_name, 0600) != 0)
     {
	(void) fprintf (stderr, "Could not create FIFO\n");
	exit (1);
     }

   (void) fprintf (stdout, "before fopen\n");
   fp = fopen(fifo_name, "r");
   (void) fprintf (stdout, "after fopen\n");

   if (quit)
     (void) fprintf (stderr, "quit=%d, fp=%p\n", quit, (void*)fp);

   if (fp != NULL)
     (void) fclose (fp);

   (void) remove(fifo_name);
   return 0;
}



[2007 date index] [2007 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]