/* * Set up curses, catch the appropriate signals, * and build the various windows. */ int init_display (void) { #ifdef HAVE_SIGACTION struct sigaction siga; #else # ifdef HAVE_SIGVEC struct sigvec sigv; # endif #endif if (initscr () == NULL) error (EXIT_FAILURE, 0, "Terminal type unset or lacking necessary features."); #ifdef HAVE_SIGACTION sigaction (SIGTSTP, (struct sigaction *) 0, &siga); sigaddset (&siga.sa_mask, SIGALRM); sigaction (SIGTSTP, &siga, (struct sigaction *) 0); #else /* !HAVE_SIGACTION */ # ifdef HAVE_SIGVEC sigvec (SIGTSTP, (struct sigvec *) 0, &sigv); sigv.sv_mask |= sigmask (SIGALRM); sigvec (SIGTSTP, &sigv, (struct sigvec *) 0); # endif /* HAVE_SIGVEC */ #endif /* HAVE_SIGACTION */ curses_initialized = 1; clear (); refresh (); noecho (); crmode (); signal (SIGINT, sig_sent); signal (SIGPIPE, sig_sent); /* curses takes care of ^Z */ my_win.x_nlines = LINES / 2; my_win.x_ncols = COLS; my_win.x_win = newwin (my_win.x_nlines, my_win.x_ncols, 0, 0); scrollok (my_win.x_win, FALSE); wclear (my_win.x_win); his_win.x_nlines = LINES / 2 - 1; his_win.x_ncols = COLS; his_win.x_win = newwin (his_win.x_nlines, his_win.x_ncols, my_win.x_nlines + 1, 0); scrollok (his_win.x_win, FALSE); wclear (his_win.x_win); line_win = newwin (1, COLS, my_win.x_nlines, 0); box (line_win, '-', '-'); wrefresh (line_win); /* let them know we are working on it */ current_state = "No connection yet"; return 0; }
int Dispatcher::waitFor( FdMask& rmaskret, FdMask& wmaskret, FdMask& emaskret, timeval* howlong ) { int nfound; #if defined(HAVE_BSD_SIGNALS) // ifdef SV_INTERRUPT /* BSD-style */ static struct sigvec sv, osv; #elif defined(HAVE_POSIX_SIGNALS) // #ifdef SA_NOCLDSTOP /* POSIX */ static struct sigaction sa, osa; #else /* System V-style */ void (*osig)(); #endif if (!_cqueue->isEmpty()) { #if defined(HAVE_BSD_SIGNALS) // #ifdef SV_INTERRUPT /* BSD-style */ sv.sv_handler = fxSIGVECHANDLER(&Dispatcher::sigCLD); sv.sv_flags = SV_INTERRUPT; sigvec(SIGCLD, &sv, &osv); #elif defined(HAVE_POSIX_SIGNALS) // #ifdef SA_NOCLDSTOP /* POSIX */ sa.sa_handler = fxSIGACTIONHANDLER(&Dispatcher::sigCLD); sa.sa_flags = SA_INTERRUPT; sigaction(SIGCLD, &sa, &osa); #else /* System V-style */ osig = (void (*)())signal(SIGCLD, fxSIGHANDLER(&Dispatcher::sigCLD)); #endif } do { rmaskret = *_rmask; wmaskret = *_wmask; emaskret = *_emask; howlong = calculateTimeout(howlong); //#if 0 && defined(hpux) // nfound = select( // _nfds, (int*)&rmaskret, (int*)&wmaskret, (int*)&emaskret, howlong // ); //#else nfound = select(_nfds, &rmaskret, &wmaskret, &emaskret, howlong); //#endif } while (nfound < 0 && !handleError()); if (!_cqueue->isEmpty()) { #if defined(HAVE_BSD_SIGNALS) // #ifdef SV_INTERRUPT /* BSD-style */ sigvec(SIGCLD, &osv, (struct sigvec*) 0); #elif defined(HAVE_POSIX_SIGNALS) // #ifdef SA_NOCLDSTOP /* POSIX */ sigaction(SIGCLD, &osa, (struct sigaction*) 0); #else /* System V-style */ (void) signal(SIGCLD, fxSIGHANDLER(osig)); #endif } return nfound; /* Timed out or input available */ }
/* * NOTE: This is not a complete imitation of sigaction; in particular it * expects that sap is never NULL and that osap is always NULL. */ int sigaction( int sig, struct sigaction *sap, struct sigaction *osap ) { if ( sap == NULL || osap != NULL ) { msg( LOG_ERR, "sigaction", "Bad args: sap = %p, osap = %p", sap, osap ) ; return( -1 ) ; } #ifndef NO_SIGVEC { struct sigvec sv ; sv.sv_handler = sap->sa_handler ; sv.sv_mask = sap->sa_mask ; sv.sv_flags = sap->sa_flags ; return( sigvec( sig, &sv, SIGVEC_NULL ) ) ; } #else /* NO_SIGVEC */ { sighandler_type new_handler ; new_handler = sa.sa_handler ; return( signal( sig, new_handler ) ? 0 : -1 ) ; } #endif /* ! NO_SIGVEC */ }
/* * Install a POSIX signal handler, allowing the invoker to set whether * the signal should be restartable or not */ sigfunc xsignal_restart(int sig, sigfunc func, int restartable) { #ifdef ultrix /* XXX: this is lame - how do we test sigvec vs. sigaction? */ struct sigvec vec, ovec; vec.sv_handler = func; sigemptyset(&vec.sv_mask); vec.sv_flags = 0; if (sigvec(sig, &vec, &ovec) < 0) return (SIG_ERR); return (ovec.sv_handler); #else /* ! ultrix */ struct sigaction act, oact; act.sa_handler = func; sigemptyset(&act.sa_mask); #if defined(SA_RESTART) /* 4.4BSD, Posix(?), SVR4 */ act.sa_flags = restartable ? SA_RESTART : 0; #elif defined(SA_INTERRUPT) /* SunOS 4.x */ act.sa_flags = restartable ? 0 : SA_INTERRUPT; #else #error "system must have SA_RESTART or SA_INTERRUPT" #endif if (sigaction(sig, &act, &oact) < 0) return (SIG_ERR); return (oact.sa_handler); #endif /* ! ultrix */ }
int PRE_EndPreempt() { struct itimerval itv; #if HAVE_SIGACTION && defined(SA_SIGINFO) struct sigaction action; #else struct sigvec vec; #endif if (lwp_cpptr == 0) return (LWP_EINIT); itv.it_value.tv_sec = itv.it_value.tv_usec = 0; #if HAVE_SIGACTION && defined(SA_SIGINFO) memset(&action, 0, sizeof(action)); action.sa_handler = SIG_DFL; if ((setitimer(ITIMER_REAL, &itv, NULL) == -1) || (sigaction(SIGALRM, &action, NULL) == -1)) return (LWP_ESYSTEM); #else memset(&vec, 0, sizeof(vec)); vec.sv_handler = SIG_DFL; vec.sv_mask = vec.sv_onstack = 0; if ((setitimer(ITIMER_REAL, &itv, (struct itimerval *)0) == -1) || (sigvec(SIGALRM, &vec, (struct sigvec *)0) == -1)) return (LWP_ESYSTEM); #endif return (LWP_SUCCESS); }
/* This is exactly like the traditional signal function, but turns on the SA_RESTART bit where possible. */ sighandler_t setsig (int sig, sighandler_t handler) { #ifdef HAVE_SIGACTION struct sigaction sa, osa; sigemptyset (&sa.sa_mask); sigemptyset (&osa.sa_mask); # ifdef SA_RESTART sa.sa_flags |= SA_RESTART; # endif sa.sa_handler = handler; if (sigaction (sig, &sa, &osa) < 0) return SIG_ERR; return osa.sa_handler; #else /* !HAVE_SIGACTION */ # ifdef HAVE_SIGVEC struct sigvec sv, osv; sigemptyset (&sv.sv_mask); sigemptyset (&osv.sv_mask); sv.sv_handler = handler; if (sigvec (sig, &sv, &osv) < 0) return SIG_ERR; return osv.sv_handler; # else /* !HAVE_SIGVEC */ return signal (sig, handler); # endif /* HAVE_SIGVEC */ #endif /* HAVE_SIGACTION */ }
void dfs_utils_init(char *n, char *dbname, char *logfile) { process_name = strdup(n); struct sigvec vec; // if (dbname && dfs_db_open(dbname)) { if (dbname) { if (dfs_db_open(dbname)) dfs_die("Can't open database: %s\n", dbname); if (dfs_use_pragmas) { dfs_db_do("PRAGMA synchronous=OFF;"); // very useful //dfs_db_do("PRAGMA locking_mode=EXCLUSIVE;"); // seems to do little } dfs_db_start(); } vec.sv_handler = dfs_stats; vec.sv_mask = 0; vec.sv_flags = 0; int res = sigvec(SIGINT, &vec, NULL); if (res) dfs_die("No set sigvec correctly: %d\n", res); }
static void _install_handler(int sig, sig_action_t *action) { sig_action_t act; int res; act.sa_handler = _sigsegv_handler; #ifdef HAVE_SIGACTION (void) sigemptyset(&act.sa_mask); #ifdef SA_RESETHAND act.sa_flags = action->sa_flags & ~SA_RESETHAND; #else act.sa_flags = action->sa_flags; #endif res = sigaction(sig, &act, (struct sigaction *) 0); #else #ifdef HAVE_SIGVEC act.sa_mask = 0; act.sa_flags = action->sa_flags & ~SV_RESETHAND; res = sigvec(sig, &act, (struct sigvec *) 0); #else action->sa_handler = (RETSIGTYPE (*)()) signal(sig, act.sa_handler); #endif #endif if (res < 0) exit(-1); }
/* wrapper to hide signal interface differrencies */ int joe_set_signal(int signum, sighandler_t handler) { int retval; #ifdef HAVE_SIGACTION struct sigaction sact; memset(&sact, 0, sizeof(sact)); sact.sa_handler = handler; #ifdef SA_INTERRUPT sact.sa_flags = SA_INTERRUPT; #endif retval = sigaction(signum, &sact, NULL); #elif defined(HAVE_SIGVEC) struct sigvec svec; memset(&svec, 0, sizeof(svec)); svec.sv_handler = handler; #ifdef HAVE_SV_INTERRUPT svec.sv_flags = SV_INTERRUPT; #endif retval = sigvec(signum, &svec, NULL); #else retval = (signal(signum, handler) != SIG_ERR) ? 0 : -1; #ifdef HAVE_SIGINTERRUPT siginterrupt(signum, 1); #endif #endif return(retval); }
int main(int argc, char *argv[]) { START(argc, argv, "vmem_create"); if (argc < 2 || argc > 3) FATAL("usage: %s directory", argv[0]); Vmp = vmem_create(argv[1], VMEM_MIN_POOL); if (Vmp == NULL) OUT("!vmem_create"); else { struct sigvec v = { 0 }; v.sv_handler = signal_handler; if (sigvec(SIGSEGV, &v, NULL) < 0) FATAL("!sigvec"); /* try to deref the opaque handle */ char x = *(char *)Vmp; OUT("x = %c", x); } FATAL("no signal received"); }
/*---------------------------------------------------------------------+ | init_sig_vec () | | ==================================================================== | | | | Function: Initialize the signal vector for ALL possible signals | | (as defined in /usr/include/sys/signal.h) except for | | the following signals which cannot be caught or ignored: | | | | o SIGKILL (9) | | o SIGSTOP (17) | | o SIGCONT (19) | | | | Returns: Nothing | | | +---------------------------------------------------------------------*/ void init_sig_vec() { char errmsg[256]; int i; #ifdef _LINUX_ static struct sigaction invec; for (i = 1; i <= SIGMAX; i++) { if ((i == SIGKILL) || (i == SIGSTOP) || ((i >= 32) && (i <= 34))) continue; invec.sa_handler = handler; //sigaction.sa_mask = 0; invec.sa_flags = 0; if (sigaction(i, &invec, NULL)) { sprintf(errmsg, "init_sig_vec: sigaction failed on signal (%d)", i); perror(errmsg); sys_error(errmsg, __LINE__); } } #else static struct sigvec invec; for (i = 1; i <= SIGMAX; i++) { /* Cannot catch or ignore the following signals */ #ifdef _IA64 /* SIGWAITING NOT supported, RESERVED */ if ((i == SIGKILL) || (i == SIGSTOP) || (i == SIGCONT) || (i == SIGWAITING)) continue; #else if ((i == SIGKILL) || (i == SIGSTOP) || (i == SIGCONT)) continue; #endif invec.sv_handler = handler; //invec.sv_mask = SA_NOMASK; #if defined _IA64 invec.sv_flags = 1; #else invec.sv_onstack = 1; #endif if (sigvec(i, &invec, NULL)) { sprintf(errmsg, "init_sig_vec: sigvec failed on signal (%d)", i); perror(errmsg); sys_error(errmsg, __LINE__); } } #endif //ifdef _LINUX_ }
void (* signal(int s, void (*a)()))() { struct sigvec osv; struct sigvec nsv; static int mask[NSIG]; static int flags[NSIG]; nsv.sv_handler = a; nsv.sv_mask = mask[s]; nsv.sv_flags = flags[s]; if (sigvec(s, &nsv, &osv) < 0) return (SIG_ERR); if (nsv.sv_mask != osv.sv_mask || nsv.sv_flags != osv.sv_flags) { mask[s] = nsv.sv_mask = osv.sv_mask; flags[s] = nsv.sv_flags = osv.sv_flags & ~SV_RESETHAND; if (sigvec(s, &nsv, (struct sigvec *)0) < 0) return (SIG_ERR); } return (osv.sv_handler); }
/* * Initialize an OS timer. The initialization steps are: * * create priority queue * install signal handler * * We also initialize the timer_block_mask if it has not been initialized yet. */ ostimer_s *__ostimer_init(timer_s *tp, enum timer_types type) { #ifndef NO_POSIX_SIGS struct sigaction sa ; #else struct sigvec sv ; #endif ostimer_s *otp ; struct timer_q *tqp ; /* * Find the corresponding ostimer */ if ( ( otp = ostimer_find( type ) ) == OSTIMER_NULL ) HANDLE_ERROR( tp->t_flags, OSTIMER_NULL, tp->t_errnop, TIMER_ENOTAVAILABLE, "TIMER __ostimer_init: requested timer type not available\n" ) ; /* * We use the value of ost_timerq to determine if the os_timer * has been initialized. */ tqp = &otp->ost_timerq ; if ( tqp->tq_handle ) return( otp ) ; tqp->tq_handle = pq_create( time_compare, tp->t_flags & TIMER_RETURN_ERROR ? PQ_RETURN_ERROR : PQ_NOFLAGS, &tqp->tq_errno ) ; if ( tqp->tq_handle == NULL ) { *tp->t_errnop = TIMER_ENOMEM ; return( OSTIMER_NULL ) ; } if ( ! timer_block_mask_set ) set_timer_block_mask() ; #ifndef NO_POSIX_SIGS sa.sa_handler = otp->ost_handler ; sa.sa_mask = timer_block_mask ; sa.sa_flags = 0 ; if ( sigaction( otp->ost_signal, &sa, SIGACTION_NULL ) == -1 ) #else sv.sv_handler = otp->ost_handler ; sv.sv_mask = timer_block_mask ; sv.sv_flags = 0 ; if ( sigvec( otp->ost_signal, &sv, SIGVEC_NULL ) == -1 ) #endif HANDLE_ERROR( tp->t_flags, OSTIMER_NULL, tp->t_errnop, TIMER_ESIGPROBLEM, "TIMER __ostimer_init: signal handler installation failed\n" ) ; return( otp ) ; }
int main() { struct sigvec mysigvec; mysigvec.sv_flags=0; mysigvec.sv_handler=myvechandler; sigvec(SIGALRM,&mysigvec,NULL); sigvec(SIGINT,&mysigvec,NULL); sigvec(SIGTERM,&mysigvec,NULL); sigvec(SIGTSTP,&mysigvec,NULL); // int i=1; // if (i==1) //{ // sleep(10); // } }
static void _save_handler(int sig, sig_action_t *action) { #ifdef HAVE_SIGACTION (void) sigaction(sig, (struct sigaction *) 0, action); #else #ifdef HAVE_SIGVEC (void) sigvec(sig, (struct sigvec *) 0, action); #else /* no flags for signal() */ #endif #endif }
static void _restore_handler(int sig, sig_action_t *action) { int res; #ifdef HAVE_SIGACTION res = sigaction(sig, action, (struct sigaction *) 0); #else #ifdef HAVE_SIGVEC res = sigvec(sig, action, (struct sigvec *) 0); #else res = signal(sig, action->sa_handler); #endif #endif if (res < 0) exit(-1); }
void signal_no_reset( int sig, RETSIGTYPE (*func)(int) ) { struct sigvec sv; int n; ZERO(sv); sv.sv_handler = func; n = sigvec(sig, &sv, (struct sigvec *)NULL); if (-1 == n) { perror("sigvec"); exit(1); } }
void (* signal(int sig, void (*a)(int)))(int) { int newsig; struct sigvec osv, sv; sv.sv_handler = a; sv.sv_mask = 0; #ifdef S5EMUL sv.sv_flags = SV_INTERRUPT|SV_RESETHAND; #else sv.sv_flags = 0; #endif if (sigvec(sig, &sv, &osv) < 0) return (BADSIG); return (osv.sv_handler); }
void os_non_restarting_signal(int sig, void (*handler)(int)) { /* Many systems have the SA_RESTART sigaction for specifying that a signal should restart system calls. These include SunOS5, AIX, BSDI, IRIX, FreeBSD, OSF1, Linux and HP-UX 10 (but *not* HP-UX 9). */ #ifdef SA_RESTART struct sigaction act; act.sa_handler = handler; sigemptyset(&(act.sa_mask)); act.sa_flags = 0; sigaction(sig, &act, NULL); #ifdef STAND_ALONE printf("Used sigaction() with flags = 0\n"); #endif /* SunOS4 and Ultrix default to non-interruptable signals, with SV_INTERRUPT for making them interruptable. This seems to be a dying fashion. */ #elif defined SV_INTERRUPT struct sigvec sv; sv.sv_handler = handler; sv.sv_flags = SV_INTERRUPT; sv.sv_mask = -1; sigvec(sig, &sv, NULL); #ifdef STAND_ALONE printf("Used sigvec() with flags = SV_INTERRUPT\n"); #endif /* If neither SA_RESTART nor SV_INTERRUPT is available we don't know how to set up a restarting signal, so just use the standard signal() function. */ #else signal(sig, handler); #ifdef STAND_ALONE printf("Used default signal()\n"); #endif #endif }
int PRE_InitPreempt(struct timeval *slice) { struct itimerval itv; #if HAVE_SIGACTION && defined(SA_SIGINFO) struct sigaction action; #else struct sigvec vec; #endif if (lwp_cpptr == 0) return (LWP_EINIT); if (slice == 0) { itv.it_interval.tv_sec = itv.it_value.tv_sec = DEFAULTSLICE; itv.it_interval.tv_usec = itv.it_value.tv_usec = 0; } else { itv.it_interval = itv.it_value = *slice; } #if HAVE_SIGACTION && defined(SA_SIGINFO) memset(&action, 0, sizeof(action)); action.sa_sigaction = AlarmHandler; action.sa_flags = SA_SIGINFO; if ((sigaction(SIGALRM, &action, NULL) == -1) || (setitimer(ITIMER_REAL, &itv, NULL) == -1)) return (LWP_ESYSTEM); #else memset(&vec, 0, sizeof(vec)); vec.sv_handler = AlarmHandler; vec.sv_mask = vec.sv_onstack = 0; if ((sigvec(SIGALRM, &vec, (struct sigvec *)0) == -1) || (setitimer(ITIMER_REAL, &itv, (struct itimerval *)0) == -1)) return (LWP_ESYSTEM); #endif return (LWP_SUCCESS); }
void signal_set_handler (int signo, RETSIGTYPE (*handler) ()) { #if defined(HAVE_SIGACTION) struct sigaction sa; memset ((char *) &sa, 0, sizeof (sa)); sigemptyset (&sa.sa_mask); sigaddset (&sa.sa_mask, signo); # ifdef SA_RESTART sa.sa_flags = SA_RESTART; # endif sa.sa_handler = handler; sigaction (signo, &sa, NULL); #elif defined(HAVE_SIGVEC) struct sigvec sv; memset (&sv, 0, sizeof (sv)); sv.sv_mask = SIGBLOCK; sv.sv_handler = handler; sigvec (signo, &sv, NULL); #else /* !HAVE_SIGVEC */ signal (signo, handler); #endif /* HAVE_SIGACTION */ }
int rmthost(char *host, uint_t blocksize) { struct sigvec sv; #ifdef __STDC__ if (print == (void (*)(const char *, ...))0) #else if (print == (void (*)())0) #endif print = rmtmsg; #ifdef __STDC__ if (Exit == (void (*)(int))0) #else if (Exit == (void (*)())0) #endif Exit = exit; if (rmtape >= 0 && rmtstate != TS_OPEN) { (void) close(rmtape); rmtape = -1; } if (rmtpeer_malloc) (void) free(rmtpeer_malloc); rmtpeer = rmtpeer_malloc = strdup(host); if (rmtpeer == (char *)0) return (0); ntrec = blocksize; sv.sa_flags = SA_RESTART; (void) sigemptyset(&sv.sa_mask); sv.sv_handler = rmtconnaborted; (void) sigvec(SIGPIPE, &sv, (struct sigvec *)0); rmtgetconn(); if (rmtape < 0) return (0); return (1); }
int sigaction(int sig, struct sigaction *sigact, struct sigaction *osigact) { return sigvec(sig, &(sigact->sv), &(osigact->sv)); }
int sigaction(int sig, struct sigaction *sigact, struct sigaction *osigact) { return sigvec(sig, sigact ? &sigact->sv : NULL, osigact ? &osigact->sv : NULL); }
_sigvec( int sig, const struct sigvec vec, struct sigvec ovec ) { sigvec( sig, vec, ovec ); }
int run_exec (const char *stin, const char *stout, const char *sterr, int flags) { int shin, shout, sherr; int mode_out, mode_err; int status; int rc = -1; int rerrno = 0; int pid, w; #ifdef POSIX_SIGNALS sigset_t sigset_mask, sigset_omask; struct sigaction act, iact, qact; #else #ifdef BSD_SIGNALS int mask; struct sigvec vec, ivec, qvec; #else RETSIGTYPE (*istat) (), (*qstat) (); #endif #endif if (trace) { cvs_outerr ( #ifdef SERVER_SUPPORT server_active ? "S" : #endif " ", 1); cvs_outerr (" -> system (", 0); run_print (stderr); cvs_outerr (")\n", 0); } if (noexec && (flags & RUN_REALLY) == 0) return 0; /* make sure that we are null terminated, since we didn't calloc */ run_add_arg (NULL); /* setup default file descriptor numbers */ shin = 0; shout = 1; sherr = 2; /* set the file modes for stdout and stderr */ mode_out = mode_err = O_WRONLY | O_CREAT; mode_out |= ((flags & RUN_STDOUT_APPEND) ? O_APPEND : O_TRUNC); mode_err |= ((flags & RUN_STDERR_APPEND) ? O_APPEND : O_TRUNC); if (stin && (shin = open (stin, O_RDONLY)) == -1) { rerrno = errno; error (0, errno, "cannot open %s for reading (prog %s)", stin, run_argv[0]); goto out0; } if (stout && (shout = open (stout, mode_out, 0666)) == -1) { rerrno = errno; error (0, errno, "cannot open %s for writing (prog %s)", stout, run_argv[0]); goto out1; } if (sterr && (flags & RUN_COMBINED) == 0) { if ((sherr = open (sterr, mode_err, 0666)) == -1) { rerrno = errno; error (0, errno, "cannot open %s for writing (prog %s)", sterr, run_argv[0]); goto out2; } } /* Make sure we don't flush this twice, once in the subprocess. */ cvs_flushout(); cvs_flusherr(); /* The output files, if any, are now created. Do the fork and dups. We use vfork not so much for a performance boost (the performance boost, if any, is modest on most modern unices), but for the sake of systems without a memory management unit, which find it difficult or impossible to implement fork at all (e.g. Amiga). The other solution is spawn (see windows-NT/run.c). */ #ifdef HAVE_VFORK pid = vfork (); #else pid = fork (); #endif if (pid == 0) { #ifdef SETXID_SUPPORT if (flags & RUN_UNSETXID) { (void) setgid (getgid ()); (void) setuid (getuid ()); } #endif if (shin != 0) { (void) dup2 (shin, 0); (void) close (shin); } if (shout != 1) { (void) dup2 (shout, 1); (void) close (shout); } if (flags & RUN_COMBINED) (void) dup2 (1, 2); else if (sherr != 2) { (void) dup2 (sherr, 2); (void) close (sherr); } #ifdef SETXID_SUPPORT /* ** This prevents a user from creating a privileged shell ** from the text editor when the SETXID_SUPPORT option is selected. */ if (!strcmp (run_argv[0], Editor) && setegid (getgid ())) { error (0, errno, "cannot set egid to gid"); _exit (127); } #endif /* dup'ing is done. try to run it now */ (void) execvp (run_argv[0], run_argv); error (0, errno, "cannot exec %s", run_argv[0]); _exit (127); } else if (pid == -1) { rerrno = errno; goto out; } /* the parent. Ignore some signals for now */ #ifdef POSIX_SIGNALS if (flags & RUN_SIGIGNORE) { act.sa_handler = SIG_IGN; (void) sigemptyset (&act.sa_mask); act.sa_flags = 0; (void) sigaction (SIGINT, &act, &iact); (void) sigaction (SIGQUIT, &act, &qact); } else { (void) sigemptyset (&sigset_mask); (void) sigaddset (&sigset_mask, SIGINT); (void) sigaddset (&sigset_mask, SIGQUIT); (void) sigprocmask (SIG_SETMASK, &sigset_mask, &sigset_omask); } #else #ifdef BSD_SIGNALS if (flags & RUN_SIGIGNORE) { memset (&vec, 0, sizeof vec); vec.sv_handler = SIG_IGN; (void) sigvec (SIGINT, &vec, &ivec); (void) sigvec (SIGQUIT, &vec, &qvec); } else mask = sigblock (sigmask (SIGINT) | sigmask (SIGQUIT)); #else istat = signal (SIGINT, SIG_IGN); qstat = signal (SIGQUIT, SIG_IGN); #endif #endif /* wait for our process to die and munge return status */ #ifdef POSIX_SIGNALS while ((w = waitpid (pid, &status, 0)) == -1 && errno == EINTR) ; #else while ((w = wait (&status)) != pid) { if (w == -1 && errno != EINTR) break; } #endif if (w == -1) { rc = -1; rerrno = errno; } #ifndef VMS /* status is return status */ else if (WIFEXITED (status)) rc = WEXITSTATUS (status); else if (WIFSIGNALED (status)) { if (WTERMSIG (status) == SIGPIPE) error (1, 0, "broken pipe"); rc = 2; } else rc = 1; #else /* VMS */ rc = WEXITSTATUS (status); #endif /* VMS */ /* restore the signals */ #ifdef POSIX_SIGNALS if (flags & RUN_SIGIGNORE) { (void) sigaction (SIGINT, &iact, NULL); (void) sigaction (SIGQUIT, &qact, NULL); } else (void) sigprocmask (SIG_SETMASK, &sigset_omask, NULL); #else #ifdef BSD_SIGNALS if (flags & RUN_SIGIGNORE) { (void) sigvec (SIGINT, &ivec, NULL); (void) sigvec (SIGQUIT, &qvec, NULL); } else (void) sigsetmask (mask); #else (void) signal (SIGINT, istat); (void) signal (SIGQUIT, qstat); #endif #endif /* cleanup the open file descriptors */ out: if (sterr) (void) close (sherr); else /* ensure things are received by the parent in the correct order * relative to the protocol pipe */ cvs_flusherr(); out2: if (stout) (void) close (shout); else /* ensure things are received by the parent in the correct order * relative to the protocol pipe */ cvs_flushout(); out1: if (stin) (void) close (shin); out0: if (rerrno) errno = rerrno; return rc; }
/* Set timeout value and setup signal handling */ int RFCNB_Set_Timeout(int seconds) { /* If we are on a Bezerkeley system, use sigvec, else sigaction */ #if ORIGINAL_SAMBA_CODE #ifndef SA_RESTART struct sigvec invec, outvec; #else struct sigaction inact, outact; #endif RFCNB_Timeout = seconds; if (RFCNB_Timeout > 0) { /* Set up handler to ignore but not restart */ #ifndef SA_RESTART invec.sv_handler = (void (*)()) rfcnb_alarm; invec.sv_mask = 0; invec.sv_flags = SV_INTERRUPT; if (sigvec(SIGALRM, &invec, &outvec) < 0) return (-1); #else /* !SA_RESTART */ inact.sa_handler = (void (*)()) rfcnb_alarm; #ifdef Solaris /* Solaris seems to have an array of vectors ... */ inact.sa_mask.__sigbits[0] = 0; inact.sa_mask.__sigbits[1] = 0; inact.sa_mask.__sigbits[2] = 0; inact.sa_mask.__sigbits[3] = 0; #else /* !Solaris */ inact.sa_mask = (sigset_t) 0; #endif /* Solaris */ inact.sa_flags = 0; /* Don't restart */ if (sigaction(SIGALRM, &inact, &outact) < 0) return (-1); #endif /* !SA_RESTART */ } #else /* !ORIGINAL_SAMBA_CODE ADAPTED SQUID CODE */ #if HAVE_SIGACTION struct sigaction inact, outact; #else struct sigvec invec, outvec; #endif RFCNB_Timeout = seconds; if (RFCNB_Timeout > 0) { /* Set up handler to ignore but not restart */ #if HAVE_SIGACTION inact.sa_handler = (void (*)()) rfcnb_alarm; sigemptyset(&inact.sa_mask); inact.sa_flags = 0; /* Don't restart */ if (sigaction(SIGALRM, &inact, &outact) < 0) return (-1); #else /* !HAVE_SIGACTION */ invec.sv_handler = (void (*)()) rfcnb_alarm; invec.sv_mask = 0; invec.sv_flags = SV_INTERRUPT; if (sigvec(SIGALRM, &invec, &outvec) < 0) return (-1); #endif /* !HAVE_SIGACTION */ } #endif /* !ORIGINAL_SAMBA_CODE ADAPTED SQUID CODE */ return (0); }