lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LYNX-DEV Control-Z and SIGSTOP mysteries


From: John E. Davis
Subject: Re: LYNX-DEV Control-Z and SIGSTOP mysteries
Date: Sat, 17 May 1997 23:30:38 -0400

On Sat, 17 May 1997 19:53:27 -0500 (CDT), Klaus Weide <address@hidden> said:
>Here's one problem:  do something that invoke a child process which
>can be suspended with ^Z.  For example, I have a PRINTER: which displays
>the file with a shell command which invokes `less'.  While in less,
>I can suspend with ^Z.  When I fg, both processes come alive (less and
>lynx) and compete for the display and keyboard, which is a bit confusing
>to say the least...  This happens with curses, ncurses, and slang.

Is this on a linux system?  If so, the problem is that system on Linux
is broken.  

>I am experimenting with a LYSystem() wrapper to be used instead of
>system(), which changes signal(SIGTSTP,...) before calling system().
>This is of course only for unix - there already is something similar
>for VMS.  But there should be a better way than this - how do other
>programs which use system() deal with it?

They deal with it by using a system that works correctly.  My next
version of the slang library will include a replacement for system:

#define SLsignal signal

int SLsystem (char *cmd)
{
#ifdef SLANG_POSIX_SIGNALS
   pid_t pid;
   int status;
   struct sigaction ignore;
# ifdef SIGINT
   struct sigaction save_intr;
# endif
# ifdef SIGQUIT
   struct sigaction save_quit;
# endif
# ifdef SIGCHLD
   sigset_t child_mask, save_mask;
# endif

   if (cmd == NULL) return 1;
   
   ignore.sa_handler = SIG_IGN;
   sigemptyset (&ignore.sa_mask);
   ignore.sa_flags = 0;

# ifdef SIGINT
   if (-1 == sigaction (SIGINT, &ignore, &save_intr))
     return -1;
# endif
   
# ifdef SIGQUIT
   if (-1 == sigaction (SIGQUIT, &ignore, &save_quit))
     {
        (void) sigaction (SIGINT, &save_intr, NULL);
        return -1;
     }
# endif

# ifdef SIGCHLD
   sigemptyset (&child_mask);
   sigaddset (&child_mask, SIGCHLD);
   if (-1 == sigprocmask (SIG_BLOCK, &child_mask, &save_mask))
     {
#  ifdef SIGINT
        (void) sigaction (SIGINT, &save_intr, NULL);
#  endif
#  ifdef SIGQUIT
        (void) sigaction (SIGQUIT, &save_quit, NULL);
#  endif
        return -1;
     }
# endif
   

   pid = fork();

   if (pid == -1)
     status = -1;
   else if (pid == 0)
     {
        /* Child */
# ifdef SIGINT
        (void) sigaction (SIGINT, &save_intr, NULL);
# endif
# ifdef SIGQUIT
        (void) sigaction (SIGQUIT, &save_quit, NULL);
# endif
# ifdef SIGCHLD
        (void) sigprocmask (SIG_SETMASK, &save_mask, NULL);
# endif
        
        execl ("/bin/sh", "sh", "-c", cmd, NULL);
        _exit (127);
     }
   else
     {
        /* parent */
        while (-1 == waitpid (pid, &status, 0))
          {
# ifdef EINTR
             if (errno == EINTR)
               continue;
# endif
# ifdef ERESTARTSYS
             if (errno == ERESTARTSYS)
               continue;
# endif
             status = -1;
             break;
          }
     }
# ifdef SIGINT
   if (-1 == sigaction (SIGINT, &save_intr, NULL))
     status = -1;
# endif
# ifdef SIGQUIT
   if (-1 == sigaction (SIGQUIT, &save_quit, NULL))
     status = -1;
# endif
# ifdef SIGCHLD
   if (-1 == sigprocmask (SIG_SETMASK, &save_mask, NULL))
     status = -1;
# endif
   
   return status;

#else                                  /* No POSIX Signals */
# ifdef SIGINT
   void (*sint)(int);
# endif
# ifdef SIGQUIT
   void (*squit)(int);
# endif
   int status;
   
# ifdef SIGQUIT
   squit = SLsignal (SIGQUIT, SIG_IGN);
# endif
# ifdef SIGINT
   sint = SLsignal (SIGINT, SIG_IGN);
# endif
   ret = system (cmd);
# ifdef SIGINT
   SLsignal (SIGINT, sint);
# endif
# ifdef SIGQUIT
   SLsignal (SIGQUIT, squit);
# endif
   return status;
#endif                                 /* POSIX_SIGNALS */
}

;
; To UNSUBSCRIBE:  Send a mail message to address@hidden
;                  with "unsubscribe lynx-dev" (without the
;                  quotation marks) on a line by itself.
;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]