/************************************************************************ * This program is Copyright (C) 1986 by Jonathan Payne. JOVE is * * provided to you without charge, and with no warranty. You may give * * away copies of JOVE, including sources, provided that this notice is * * included in all the files. * ************************************************************************/ /*+++* * title: process.h * abstract: system dependent process control definitions for JOVE * author: T.R.Hageman, Groningen, The Netherlands. * created: july 1990 * modified: 10-Jan-91 add DUP2, HOLD_SIGS, and SETPGRP. * 28-Feb-92 add RESIGNAL, Posix support. * description: * "real" SYSV systems are assumed to have the sighold(2) and sigrelse(2) * system calls, and none of the capabilities mentioned below. * "hybrid" SYSV_BSD systems are assumed to have at least BSD_SIGS * and VFORK. "real" BSD systems are assumed to have all the * capabilities. If you have a systems that is somewhere in-between, * you'd best choose the system that comes closest and explicitly * define the missing capabilities. * (here, or in tune.h or in the Makefile) * * BSD_SIGS - BSD style signal handling, i.e., the * sigblock(2) and sigsetmask(2) system calls. * * BSD_WAIT - BSD-style or (non BSD4_2) , * and either wait2(2) or wait3(2) system call. * * DUP2 - if your system has dup2(2) system call. * * HOLD_SIGS - if your system can hold individual signals. * (implied by BSD and "real" SYSV systems) * * KILLPG - if your system has killpg(2) system call. * * RESIGNAL - if your system needs to re-establish caught signals. * * SETPGRP - if your system has setpgrp(2) system call. * * VFORK - if your system has vfork(2) system call. * * WAIT3 - if your system has wait3(2) system call. * * ALARM_1_SEC - minimum number of seconds that can be handled * reliably by alarm(2) -- 1 for BSD, 2 for most others. *---*/ #ifndef _PROCESS_H_ #define _PROCESS_H_ #ifndef TUNED # include "tune.h" #endif #ifdef Extern RCS_H(process, "$Id: process.h,v 14.32.0.9 1994/01/31 14:31:08 tom Exp tom $") #endif #ifndef Extern # define Extern extern #endif #include #ifndef TINY #ifndef _POSIX_SOURCE # ifndef _PID_T # ifndef __PID_T # undef pid_t # define pid_t int # endif # endif #endif #ifndef ALARM_T # define ALARM_T unsigned #endif #endif /* TINY */ #ifdef _POSIX_SOURCE # define HOLD_SIGS # define DUP2 # define SETPGRP # define BSD_WAIT # define ALARM_1_SEC 1 #else # ifdef BSD4_2 # define BSD_SIGS # define HOLD_SIGS # define SETPGRP # define VFORK # ifndef SYSV_BSD # define BSD_WAIT # define KILLPG # define WAIT3 # endif # define ALARM_1_SEC 1 # ifdef SYSV # define RESIGNAL # endif # else # ifdef SYSV # ifndef SCO_SYSV # define HOLD_SIGS # endif # define SETPGRP # endif # ifdef V7 # define DUP2 # endif # ifdef MINIX # define DUP2 # define ALARM_1_SEC 1 # endif # define RESIGNAL # endif /* BSD4_2 */ #endif /* _POSIX_SOURCE */ /* exceptions (sigh...) */ #if aiws # undef VFORK #endif #ifndef ALARM_1_SEC # if unix # define ALARM_1_SEC 2 # else # define ALARM_1_SEC 1 # endif #endif #if vms # define BSD_SIGS # define DUP2 # define HOLD_SIGS # define VFORK #endif #ifdef DOS # define DUP2 #endif /* Signal stuff */ #ifndef SIGCHLD # ifdef SIGCLD # define SIGCHLD SIGCLD /* Oh those UNIX flavours! */ # endif #endif #ifdef _POSIX_SOURCE Extern sigset_t SigMask; # define sighold(sig) (sigaddset(&SigMask, (sig)), \ sigprocmask(SIG_BLOCK, &SigMask, NULL)) # define sigrelse(sig) (sigdelset(&SigMask, (sig)), \ sigprocmask(SIG_SETMASK, &SigMask, NULL)) #else # ifdef BSD_SIGS Extern long SigMask; # ifndef sigmask # define sigmask(sig) (1L << ((sig) - 1)) # endif # define sighold(sig) sigblock(SigMask |= sigmask(sig)) # define sigrelse(sig) sigsetmask(SigMask &= ~sigmask(sig)) # endif /* BSD_SIGS */ #endif /* _POSIX_SOURCE */ /* Wait stuff */ #ifdef _POSIX_SOURCE # ifdef __convexc__ # undef __stdc__ /* to circumvent a bug in convex's */ # endif # include # ifdef __convexc__ /* oh, I hate this! */ # if (_ANSI_C_ == _ANSI_COMPLIANT_) # define __stdc__ 1 # endif # endif # define wait2(w, f) waitpid(-1, (w), (f)) # define WAIT_T int #else # ifdef BSD_WAIT # ifdef BSD4_2 # include # else # include # endif # ifndef WTERMSIG # define WTERMSIG(w) ((w).w_termsig) # endif # ifndef WEXITSTATUS # define WEXITSTATUS(w) ((w).w_retcode) # endif # define WAIT_T union wait # else # if unix # define WTERMSIG(w) ((w)&0177) # define WEXITSTATUS(w) ((short)(w)>>8) /* sign-extend! */ # endif # if vms # define WTERMSIG(w) ((w)&0) # define WEXITSTATUS(w) (w) # endif # define WIFEXITED(w) (WTERMSIG(w)==0) # define WIFSTOPPED(w) (WTERMSIG(w)==0177) # define WIFSIGNALED(w) ((unsigned)(WTERMSIG(w)-1)<(0177-1)) # define wait2(w, f) wait(w) # define WAIT_T int # endif /* BSD_WAIT */ #endif /* _POSIX_SOURCE */ #ifndef DUP2 /* {{this emulation fails if any file handle below `old' is available.}} */ # define dup2(new, old) (close(old), dup(new)) #endif #undef DUP2 #ifdef IPROCS # ifndef SETPGRP # define setpgrp(a,b) 0 # define killpg kill /* if we cannot set process group, surely we cannot kill it */ # else # ifndef KILLPG # define killpg(pid, sig) kill(-(pid),(sig)) # endif # endif #endif #ifndef VFORK # define vfork fork #endif #ifdef WAIT3 # define wait2(w, f) wait3((w), (f), NULL) #endif /* * The following definitions are used for protecting "critical" regions * that should not be disrupted by an alarm signal. (i.e., screen output * in redisplay.) Should be brace-balanced! */ #if unix || vms #ifndef HOLD_SIGS # define HOLD_ALARM \ { int old_time; \ if (old_time=UpdFreq) \ if ((old_time=alarm(0))==0) \ old_time=UpdFreq; # define RELSE_ALARM \ if (old_time) \ alarm(old_time); \ } #else # define HOLD_ALARM \ if (UpdFreq) \ sighold(SIGALRM); # define RELSE_ALARM \ if (UpdFreq) \ sigrelse(SIGALRM); #endif #else /* !(unix || vms) */ # define HOLD_ALARM ; # define RELSE_ALARM ; #endif /* unix || vms */ #ifdef IPROCS # ifdef PIPEPROCS struct header { int pid; int nbytes; }; /* (see "kbd.c" for an explanation of these) */ # define KBD_TOGGLE_SUSPEND_SIG SIGQUIT # define KBD_TIMEOUT_SIG SIGINT # define KBD_FATAL_ERROR_SIG SIGPIPE # define KBD_SUSPENDED (-10000) # endif /* PIPEPROCS */ #endif /* IPROCS */ #ifndef ENOENT # include #endif #ifndef ENOEXEC # define ENOEXEC 0xBAD #endif #ifndef NOT_JOVE /* don't include this in support programs */ #define kbd /* dummy, gets #undef'ed when a real one is present */ #ifdef IPROCS extern int NumProcs; # ifdef PIPEPROCS extern int kbd_pid; # else # if !vms extern long global_fd; # endif # endif /* iproc.c */ extern const char * pstate __(( Process *_(p) )); extern int pbufalivep __(( Buffer *_(b) )); # ifdef PIPEPROCS extern int proc_read __(( void_* _(buf), int _(size) )), # undef kbd kbd __(( int _(on) )); # endif # if vms # undef kbd extern int kbd __(( int _(on) )); # endif extern void pinit __(( void )), # ifdef IPARSE IprocWTerm __(( const char *_(bname), const char *_(command), data_obj *_(term_handler) )), # endif # ifdef PIPEPROCS kbd_kill __(( void )), kbd_timeout __(( void )), proc_error __(( const char *_(msg) )), read_proc __(( int _(pid), int _(nbytes) )), # else # if unix read_proc __(( int _(pty_fd) )), # endif # if vms restart_process_input __(( void )), # endif # endif kill_off __(( int _(pid), WAIT_T _(w) )), KillProcs __(( void )), # ifdef FIXED_MAPS PopPBs __(( void )), PushPBs __(( void )), # endif pbuftiedp __(( Buffer *_(b) )); #endif /* IPROCS */ /* proc.c */ extern Buffer *perr_buf; extern char *ShcomBuf; #ifndef NO_TRIV_PROTO extern int get_FL_info __(( char _(buf)[FILESIZE] )), # if unix dowait __(( int _(pid) )), # endif UnixToBuf __(( const char *_(bufname), int _(disp), int _(wsize), int _(clobber), const char *_(infile), ... )), ShellToBuf __(( const char *_(bufname), int _(disp), int _(wsize), int _(clobber), const char *_(infile), const char *_(command) )); extern void ErrFree __(( void )), set_wsize __(( int _(fraction) )), ParseAll __(( void )), read_pipe __(( const char *_(name), int _(fd), int _(disp) )); #endif /* NO_TRIV_PROTO */ extern void isprocbuf __(( const char *_(bufname) )); extern char *MakeName __(( const char *_(command) )); #ifdef PROC_WRAP extern char *chop __(( char *_(line), int _(start) )); #endif /* jove.c */ #if unix || vms typedef struct { short sig; sig_tp (*proc)__((int _(sig))); } Signal; extern Signal SigIntQuit[2]; /* A common set of signals */ # ifndef NO_TRIV_PROTO extern void SetSigs __(( const Signal *_(sigs), int _(num) )), GetSigs __(( Signal *_(sigs), int _(num) )); # endif #endif /* unix || vms */ #ifdef MAIL # ifndef NO_TRIV_PROTO extern int chkmail __(( int _(force) )); # endif #endif /* util.c */ #ifndef NO_TRIV_PROTO # if unix extern void pipeopen __(( int p[2] )), pipeclose __(( int p[2] )), exec_fail __(( const char *_(program) )); # endif # ifndef DOS extern void make_argv __(( char *_(argv)[], va_list _(ap) )); # endif #endif /* NO_TRIV_PROTO */ #endif /* NOT_JOVE */ /* unix process handling */ #ifndef NO_TRIV_PROTO extern int dup __(( int _(fd) )), # ifndef dup2 dup2 __(( int _(newfd), int _(orgfd) )), # endif #if unix pipe __(( int _(pfds)[2] )), execv __(( const char *_(command), char * const _(argv)[] )), execl __(( const char *_(command), const char *_(arg0), ... )), # ifndef killpg killpg __(( int _(pgid), int _(sig) )), # endif kill __(( pid_t _(pid), int _(sig) )), #endif /* unix */ putenv __(( const char *_(envstr) )); #if unix extern pid_t vfork __(( void )); #endif extern void #if (__GNUC__ == 1 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)) volatile #endif _exit __(( int _(status) )) #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) __attribute__((noreturn)) #endif ; #if 0 #ifdef _P_EXIT_RETURN_TYPE extern _P_EXIT_RETURN_TYPE #else extern void #endif #if (__GNUC__ == 1 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)) volatile #endif exit __(( int _(status) )) #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) __attribute__((noreturn)) #endif ; #endif extern ALARM_T alarm __(( unsigned _(seconds) )); #endif /* NO_TRIV_PROTO */ #endif /* _PROCESS_H_ */ #undef Extern /*====================================================================== * $Log: process.h,v $ * Revision 14.32.0.9 1994/01/31 14:31:08 tom * (vfork): Posix-ate prototype; (_exit): gcc 2.5.x noreturn attribute; * (exit): idem, but disabled due to conflicts w/ existing prototypes. * * Revision 14.32 1993/03/22 11:05:02 tom * *** empty log message *** * * Revision 14.31.0.1 1993/03/22 11:05:02 tom * add RESIGNAL to hybrid BSD/SysV that was lost somehow. * * Revision 14.31 1993/02/15 03:04:40 tom * replace TINY with NO_TRIV_PROTO for clarity of intent. * * Revision 14.30 1993/01/26 18:43:05 tom * cleanup whitespace. * * Revision 14.29 1992/12/29 13:06:03 tom * some portability changes. * * Revision 14.28 1992/10/24 01:24:22 tom * convert to "port{ansi,defs}.h" conventions; some portability shuffling. * * Revision 14.27 1992/09/22 15:23:11 tom * add `volatile' type qualifier to _exit(), exit() prototypes for Gnu C. * * Revision 14.26 1992/08/26 23:56:46 tom * some typographic changes; reTINYfied; add RCS directives. * */