/* * waitfg - block until FG job pid terminates or stops. */ void waitfg(pid_t pid) { int status; /* wait for FG job to stop (WUNTRACED) or terminate */ if (waitpid(pid, &status, WUNTRACED) < 0) unix_error("waitfg: waitpid error"); /* FG job has stopped. Change its state in jobs list */ if (WIFSTOPPED(status)) { sprintf(sbuf, "Job %d stopped by signal", pid); psignal(WSTOPSIG(status), sbuf); updatejob(jobs, pid, ST); } /* FG job has terminated. Remove it from job list */ else { /* check if job was terminated by an uncaught signal */ if (WIFSIGNALED(status)) { sprintf(sbuf, "Job %d terminated by signal", pid); psignal(WTERMSIG(status), sbuf); } deletejob(jobs, pid); if (verbose) printf("waitfg: job %d deleted\n", pid); } }
int main(int argc, char **argv) { sigset_t block, pending; int sig, flag; /* 设置信号的handler */ signal(MYSIGNAL, sig_handler); /* 屏蔽此信号 */ sigemptyset(&block); sigaddset(&block, MYSIGNAL); printf("block signal\n"); sigprocmask(SIG_BLOCK, &block, NULL); /* 发两次信号, 看信号将会被触发多少次 */ printf("---> send a signal --->\n"); kill(getpid(), MYSIGNAL); printf("---> send a signal --->\n"); kill(getpid(), MYSIGNAL); /* 检查当前的未决信号 */ flag = 0; sigpending(&pending); for (sig = 1; sig < NSIG; sig++) { if (sigismember(&pending, sig)) { flag = 1; psignal(sig, "this signal is pending"); } } if (flag == 0) { printf("no pending signal\n"); } /* 解除此信号的屏蔽, 未决信号将被递送 */ printf("unblock signal\n"); sigprocmask(SIG_UNBLOCK, &block, NULL); /* 再次检查未决信号 */ flag = 0; sigpending(&pending); for (sig = 1; sig < NSIG; sig++) { if (sigismember(&pending, sig)) { flag = 1; psignal(sig, "a pending signal"); } } if (flag == 0) { printf("no pending signal\n"); } return 0; }
void sigchld_handler(int sig) { pid_t pid; int status; struct job *p; if ((pid = waitpid(-1, &status, WUNTRACED)) > 0) { if (WIFEXITED(status)) { deletejob(pid); if (pid == forepid) { forepid = 0; setpgid(pid, pid); fprintf(stderr, "foreground job %d terminated normally with exit status=%d\n", pid, WEXITSTATUS(status)); siglongjmp(env, 1); } else fprintf(stderr, "job %d terminated normally with exit status=%d\n", pid, WEXITSTATUS(status)); } else if (WIFSTOPPED(status)) { p = selectjob(pid); p->state = 0; if (pid == forepid) { forepid = 0; setpgid(pid, pid); fprintf(stderr, "foreground job [%d] %d stopped by signal: Stopped\n", p->jid, pid); siglongjmp(env, 1); } else fprintf(stderr, "job [%d] %d stopped by signal: Stopped\n", p->jid, pid); } else if (WIFSIGNALED(status)) { deletejob(pid); if (pid == forepid) { forepid = 0; setpgid(pid, pid); fprintf(stderr, "foreground job %d terminated by ", pid); psignal(WTERMSIG(status), "signal"); siglongjmp(env, 1); } else fprintf(stderr, "job %d terminated by ", pid); psignal(WTERMSIG(status), "signal"); } } else if (errno != ECHILD) fprintf(stderr, "waitpid error: %s\n", strerror(errno)); printf("handler reaped pid=%d, ready to return right now.\n", pid); return; }
void fg_waitpid(pid_t pid) { int status; pid_t r_pid; struct job *p; if ((r_pid = waitpid(pid, &status, 0)) > 0) { printf("fg_waitpid in, forepid=%d, r_pid=%d\n", forepid, r_pid); forepid = 0; if (WIFEXITED(status)) { deletejob(r_pid); fprintf(stderr, "job %d terminated normally with exit status=%d\n", r_pid, WEXITSTATUS(status)); } else if (WIFSTOPPED(status)) { p = selectjob(r_pid); p->state = 0; fprintf(stderr, "job [%d] %d stopped by signal: Stopped\n", p->jid, r_pid); } else if (WIFSIGNALED(status)) { deletejob(r_pid); fprintf(stderr, "job %d terminated by ", r_pid); psignal(WTERMSIG(status), "signal"); } } else if (errno != ECHILD) fprintf(stderr, "waitpid error: %s\n", strerror(errno)); printf("foreground reaped pid=%d, ready to return\n", r_pid); return; }
void MySAR_signal_handler(int signal) { psignal(signal, "FATAL: MySAR Received Signal: "); if (signal==SIGINT || signal==SIGTERM) { // rollback last operation MySAR_db_rollback(); MySAR_free_mysql_statements(); if (!config->logfile.compressed) { // write last file position, prevent duplicationg records MySAR_update_config(record.stamp, "lastTimestamp"); MySAR_update_config_long(ftell(input), "lastLogOffset"); } // close db MySAR_db_shutdown(); // dont forget to remove the lock... MySAR_unlock_host(); exit(EXIT_FAILURE); } }
static int scheduler_signal_handler(int sig){ /*quit listening upon signal and do clean up.*/ psignal(sig, "scheduler"); if(sig!=15) print_backtrace(); quit_listen=1; return 1; }
/* * Place the event in the event queue and wakeup any waiting processes. */ static void aed_enqevent(adb_event_t *event) { int s; s = splvm(); #ifdef DIAGNOSTIC if (aed_sc->sc_evq_tail < 0 || aed_sc->sc_evq_tail >= AED_MAX_EVENTS) panic("adb: event queue tail is out of bounds"); if (aed_sc->sc_evq_len < 0 || aed_sc->sc_evq_len > AED_MAX_EVENTS) panic("adb: event queue len is out of bounds"); #endif if (aed_sc->sc_evq_len == AED_MAX_EVENTS) { splx(s); return; /* Oh, well... */ } aed_sc->sc_evq[(aed_sc->sc_evq_len + aed_sc->sc_evq_tail) % AED_MAX_EVENTS] = *event; aed_sc->sc_evq_len++; selnotify(&aed_sc->sc_selinfo, 0, 0); if (aed_sc->sc_ioproc) psignal(aed_sc->sc_ioproc, SIGIO); splx(s); }
int proc_apply_resource_actions(void * bsdinfo, __unused int type, int action) { proc_t p = (proc_t)bsdinfo; switch(action) { case PROC_POLICY_RSRCACT_THROTTLE: /* no need to do anything */ break; case PROC_POLICY_RSRCACT_SUSPEND: task_suspend(p->task); break; case PROC_POLICY_RSRCACT_TERMINATE: psignal(p, SIGKILL); break; case PROC_POLICY_RSRCACT_NOTIFY_KQ: /* not implemented */ break; case PROC_POLICY_RSRCACT_NOTIFY_EXC: panic("shouldn't be applying exception notification to process!"); break; } return(0); }
int power_intr(void *arg) { extern int kbd_reset; int status; status = (int8_t)_reg_read_1(LANDISK_BTNSTAT); if (status == -1) { return (0); } status = ~status; if (status & BTN_POWER_BIT) { #ifdef DEBUG printf("%s switched\n", sc->sc_dev.dv_xname); Debugger(); #endif _reg_write_1(LANDISK_PWRSW_INTCLR, 1); if (kbd_reset == 1) { kbd_reset = 0; psignal(initproc, SIGUSR1); } return (1); } return (0); }
int pledge_fail(struct proc *p, int error, uint64_t code) { char *codes = ""; int i; struct sigaction sa; /* Print first matching pledge */ for (i = 0; code && pledgenames[i].bits != 0; i++) if (pledgenames[i].bits & code) { codes = pledgenames[i].name; break; } printf("%s(%d): syscall %d \"%s\"\n", p->p_comm, p->p_pid, p->p_pledge_syscall, codes); #ifdef KTRACE if (KTRPOINT(p, KTR_PLEDGE)) ktrpledge(p, error, code, p->p_pledge_syscall); #endif /* Send uncatchable SIGABRT for coredump */ memset(&sa, 0, sizeof sa); sa.sa_handler = SIG_DFL; setsigvec(p, SIGABRT, &sa); psignal(p, SIGABRT); p->p_p->ps_pledge = 0; /* Disable all PLEDGE_ flags */ return (error); }
void sigchld_handler(int sig) { pid_t pid; int status; struct job *p; if ((pid = waitpid(-1, &status, WUNTRACED)) > 0) { if (pid == forepid) forepid = 0; if (WIFEXITED(status)) deletejob(pid); else if (WIFSTOPPED(status)) { p = selectjob(pid); p->state = 0; fprintf(stderr, "job [%d] %d stopped by signal: Stopped\n", p->jid, pid); } else if (WIFSIGNALED(status)) { deletejob(pid); fprintf(stderr, "job %d terminated by ", pid); psignal(WTERMSIG(status), "signal"); } } else if (errno != ECHILD) fprintf(stderr, "\nwaitpid error: %s\n", strerror(errno)); return; }
void pipeSigHandler( int signal ) { #ifdef psignal psignal( signal, "Signal Received : "); #else cout << "got pipe signal:" << signal << endl; #endif }
static void signal_handler(int sig) { #if defined(SIGPIPE) if (sig == (int) SIGPIPE) { psignal(sig, "Csound ignoring SIGPIPE"); return; } #endif psignal(sig, "\ncsound command"); if ((sig == (int) SIGINT || sig == (int) SIGTERM)) { if(_csound) csoundStop(_csound); _result = -1; return; } exit(1); }
static TACommandVerdict psignal_cmd(TAThread thread,TAInputStream stream) { int sig = readInt ( & stream ); char * s = readString( & stream ); char * fileForStderr = readString( & stream ); FILE * stderrAsFile; FILE * oldStderr; // psignal( sig, s ); stderrAsFile = fopen( fileForStderr, "w" ); assertion( stderrAsFile != NULL, "psignal_cmd : stderrAsFile is NULL\n" ); oldStderr = stderr; stderr = stderrAsFile; // ta_debug_printf( "psignal_cmd : sig is %d\n" , sig ); fflush( stdout ); // ta_debug_printf( "psignal_cmd : s is \"%s\"\n", s ); fflush( stdout ); // ta_debug_printf( "psignal_cmd : fileForStderr is \"%s\"\n", fileForStderr ); fflush( stdout ); START_TARGET_OPERATION( thread ); // ta_debug_printf( "psignal_cmd : before psignal\n" ); fflush( stdout ); psignal( sig, s ); // ta_debug_printf( "psignal_cmd : after psignal\n" ); fflush( stdout ); END_TARGET_OPERATION( thread ); stderr = oldStderr; // ta_debug_printf( "psignal_cmd : 1\n" ); fflush( stdout ); fclose( stderrAsFile ); // ta_debug_printf( "psignal_cmd : 2\n" ); fflush( stdout ); writeString( thread, "Ok" ); // ta_debug_printf( "psignal_cmd : 3\n" ); fflush( stdout ); sendResponse( thread ); // ta_debug_printf( "psignal_cmd : return\n" ); fflush( stdout ); return taDefaultVerdict; }
void proftimer_trampoline(void *v) { struct process *pr = v; psignal(pr->ps_mainproc, SIGPROF); }
int main(){ char *cmd = (char *)"/opt/vpnserver execsvc"; sigset_t mask; int sig; if(!(fp = (FILE *)popen(cmd, "re"))){ printf("popen failed\n"); exit(-1); }else{ signal(SIGINT, quit); signal(SIGTERM, quit); sigfillset(&mask); sigwait(&mask, &sig); psignal(sig, ""); printf("Caught signal, closing\n"); pclose((FILE *)fp); } }
int Mono_Posix_Syscall_psignal (int sig, const char* s) { errno = 0; psignal (sig, s); return errno == 0 ? 0 : -1; }
static int enforce_rlimit_fsize(struct vnode *vp, struct uio *uio, int ioflag) { struct lwp *l = curlwp; off_t testoff; if (uio->uio_rw != UIO_WRITE || vp->v_type != VREG) return 0; KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE); if (ioflag & IO_APPEND) testoff = vp->v_size; else testoff = uio->uio_offset; if (testoff + uio->uio_resid > l->l_proc->p_rlimit[RLIMIT_FSIZE].rlim_cur) { mutex_enter(proc_lock); psignal(l->l_proc, SIGXFSZ); mutex_exit(proc_lock); return EFBIG; } return 0; }
int main(void) { sigset_t base_mask, waiting_mask, oldmask; int sig; /* 阻塞使用者的中斷. */ sigemptyset (&base_mask); sigaddset (&base_mask, SIGQUIT); sigaddset (&base_mask, SIGINT); if (sigprocmask (SIG_BLOCK, &base_mask, &oldmask)<0 ) err_exit("SIG_BLOCK error"); printf(" I have blocked SIGQUIT and SIGINT, and\n you can try " "to send these two signals and wait for my reply.\n"); sleep(10); /* 過一會兒後,檢視是否有懸掛訊號. */ printf("Let me see if there is any pending signal.\n"); sigpending (&waiting_mask); for ( sig=1;sig<NSIG;sig++) if (sigismember (&waiting_mask, sig)){ psignal(sig,"There is a pending signal" ); /* 對該訊號做出回應... */ } /* 還原訊號屏蔽,這將放開SIGINT和SIGTSTP */ if (sigprocmask(SIG_SETMASK,&oldmask,NULL)<0) err_exit("SIG_SETMASK error"); /* 若果有訊號,下面的程式碼不會執行 */ printf("Ther is no suspending signal. BYE!\n"); exit(EXIT_SUCCESS); }
void fg_waitpid(pid_t pid) { int status; pid_t r_pid = 0; struct job *p = NULL; if ((r_pid = waitpid(pid, &status, 0)) > 0) { forepid = 0; if (WIFEXITED(status)) deletejob(r_pid); else if (WIFSTOPPED(status)) { p = selectjob(r_pid); p->state = 0; fprintf(stderr, "job [%d] %d stopped by signal: Stopped\n", p->jid, r_pid); } else if (WIFSIGNALED(status)) { deletejob(r_pid); fprintf(stderr, "job %d terminated by ", r_pid); psignal(WTERMSIG(status), "signal"); } } else if (errno != ECHILD) fprintf(stderr, "waitpid error: %s\n", strerror(errno)); return; }
static int sd_callback2(proc_t p, void * args) { struct sd_iterargs * sd = (struct sd_iterargs *)args; int signo = sd->signo; int setsdstate = sd->setsdstate; int countproc = sd->countproc; proc_lock(p); p->p_shutdownstate = setsdstate; if (p->p_stat != SZOMB) { proc_unlock(p); if (countproc != 0) { proc_list_lock(); p->p_listflag |= P_LIST_EXITCOUNT; proc_shutdown_exitcount++; proc_list_unlock(); } psignal(p, signo); if (countproc != 0) sd->activecount++; } else proc_unlock(p); return(PROC_RETURNED); }
void virttimer_trampoline(void *v) { struct process *pr = v; psignal(pr->ps_mainproc, SIGVTALRM); }
/* * Send the specified signal to * all processes with 'tp' as its * controlling teletype. * Called by tty.c for quits and * interrupts. */ signal(tp, sig) { register struct proc *p; for(p = &proc[0]; p < &proc[NPROC]; p++) if(p->p_ttyp == tp) psignal(p, sig); }
/* * Interrupt procedure. * Just call a user level interrupt routine. */ void spigintr(int unit) { struct spigot_softc *ss = (struct spigot_softc *)&spigot_softc[unit]; if(ss->p && ss->signal_num) psignal(ss->p, ss->signal_num); }
main ( ) { int i ; char *s; for ( i = 1; i < 10; i++ ) psignal ( i, "error" ) ; }
void sigintHandler(int sigNum) { if (fd > 0) { close(fd); } psignal(sigNum, ""); exit(0); }
int sys_nosys(struct lwp *l, const void *v, register_t *retval) { mutex_enter(proc_lock); psignal(l->l_proc, SIGSYS); mutex_exit(proc_lock); return ENOSYS; }
void handler(int signal ) { psignal(signal, "exiting"); /* If we don't clean up upon interrupt, umount thinks there's a ref * and doesn't remove us from mtab (EINPROGRESS). The lustre client * does successfully unmount and the mount is actually gone, but the * mtab entry remains. So this just makes mtab happier. */ llapi_hsm_copytool_fini(&ctdata); exit(1); }
void osi_StopListener(void) { struct proc *p; soclose(rx_socket); p = pfind(rxk_ListenerPid); if (p) psignal(p, SIGUSR1); }
static void bppsoftintr(void *cookie) { struct bpp_softc *sc = cookie; mutex_enter(proc_lock); if (sc->sc_asyncproc) psignal(sc->sc_asyncproc, SIGIO); mutex_exit(proc_lock); }