/* * The trap builtin. */ int trapcmd(int argc __unused, char **argv) { char *action; int signo; int errors = 0; int i; while ((i = nextopt("l")) != '\0') { switch (i) { case 'l': printsignals(); return (0); } } argv = argptr; if (*argv == NULL) { for (signo = 0 ; signo < sys_nsig ; signo++) { if (signo < NSIG && trap[signo] != NULL) { out1str("trap -- "); out1qstr(trap[signo]); if (signo == 0) { out1str(" EXIT\n"); } else if (sys_signame[signo]) { out1fmt(" %s\n", sys_signame[signo]); } else { out1fmt(" %d\n", signo); } } } return 0; } action = NULL; if (*argv && sigstring_to_signum(*argv) == -1) { if (strcmp(*argv, "-") == 0) argv++; else { action = *argv; argv++; } } for (; *argv; argv++) { if ((signo = sigstring_to_signum(*argv)) == -1) { warning("bad signal %s", *argv); errors = 1; continue; } INTOFF; if (action) action = savestr(action); if (trap[signo]) ckfree(trap[signo]); trap[signo] = action; if (signo != 0) setsignal(signo); INTON; } return errors; }
static void nosig(const char *name) { warnx("unknown signal %s; valid signals:", name); printsignals(stderr); exit(1); }
static void nosig(char *name) { warnx("unknown signal %s; valid signals:", name); printsignals(stderr); exit(1); /* NOTREACHED */ }
/* * The trap builtin. */ int trapcmd(int argc, char **argv) { char *action; int signo; if (argc <= 1) { for (signo = 0 ; signo < _NSIG ; signo++) { if (trap[signo] != NULL) { if (signo == 0) { out1fmt("trap -- '%s' %s\n", trap[signo], "exit"); } else if (strsigname(signo)) { out1fmt("trap -- '%s' %s\n", trap[signo], strsigname(signo)); } else { out1fmt("trap -- '%s' %d\n", trap[signo], signo); } } } return 0; } action = NULL; if (*++argv && strcmp(*argv, "--") == 0) argv++; if (*argv && sigstring_to_signum(*argv) == -1) { if ((*argv)[0] != '-') { action = *argv; argv++; } else if ((*argv)[1] == '\0') { argv++; } else if ((*argv)[1] == 'l' && (*argv)[2] == '\0') { printsignals(); return 0; } else { error("bad option %s", *argv); } } while (*argv) { if ((signo = sigstring_to_signum(*argv)) == -1) error("bad signal %s", *argv); INTOFF; if (action) action = savestr(action); if (trap[signo]) ckfree(trap[signo]); trap[signo] = action; if (signo != 0) setsignal(signo); INTON; argv++; } return 0; }
static void nosig(const char *name) { warnx("unknown signal %s; valid signals:", name); printsignals(stderr); #ifdef SHELL error(NULL); #else exit(2); #endif }
void printpage(ISystem *pSystem) { printf("\033[2J\033[1;1H\n"); char Text[80]; int t = pSystem->Values.tloop; int t1 = pSystem->Values.tSleep; sprintf(Text, "Loop %08ld t: %04dms (%02d%%) Sleep was: %04dms", pSystem->Counter.MainLoops, t, (t*100)/250, t1 ); cout << Text << "\r\n"; sprintf(Text, "CAN Frames received:%08ld sent:%08ld", pSystem->Counter.CanFramesReceived, pSystem->Counter.CanFramesSent); cout << Text << "\r\n"; sprintf(Text, "BMZ Main %08ld bytes received", pSystem->BmaMain.Vds.BmzBytesReceived); cout << Text << "\r\n"; sprintf(Text, "BMZ Failover %08ld bytes received", pSystem->BmaFailover.Vds.BmzBytesReceived); cout << Text << "\r\n"; sprintf(Text, "VdS Frames received:%08ld errors:%08ld", pSystem->BmaMain.Vds.pVdsInput->getFrameReceiveCount(), pSystem->BmaMain.Vds.pVdsInput->getFrameErrorCount()); cout << Text << "\r\n"; printsignals(pSystem); /* Some important values */ cout << "\r\n"; cout << "Keys:'1'/'0'' Simulation. 'q' to close..." << "\r\n"; }
int main(int argc, char const *argv[]) { sigset_t s1,s2; //设置s1,s2信号集 sigemptyset(&s2); //将s2信号集清空 sigaddset(&s2,SIGINT); //设置信号到信号集 sigaddset(&s2,SIGQUIT); sigprocmask(SIG_BLOCK,&s2,NULL); //改变信号的堵塞状态 int c = 0; while(1) { sigpending(&s1); //获取系统未决信号集 printsignals(&s1); c++; if(c == 6) { sigdelset(&s2,SIGQUIT); //清除执行信号 sigprocmask(SIG_UNBLOCK,&s2,NULL); } sleep(1); } return 0; }
int trapcmd(int argc, char **argv) { char *action; char **ap; int signo; if (argc <= 1) { for (signo = 0 ; signo <= NSIG ; signo++) if (trap[signo] != NULL) { out1fmt("trap -- "); print_quoted(trap[signo]); out1fmt(" %s\n", (signo) ? sys_signame[signo] : "EXIT"); } return 0; } ap = argv + 1; action = NULL; if (strcmp(*ap, "--") == 0) if (*++ap == NULL) return 0; if (signame_to_signum(*ap) == -1) { if ((*ap)[0] == '-') { if ((*ap)[1] == '\0') ap++; else if ((*ap)[1] == 'l' && (*ap)[2] == '\0') { printsignals(); return 0; } else error("bad option %s\n", *ap); } else action = *ap++; } while (*ap) { if (is_number(*ap)) signo = number(*ap); else signo = signame_to_signum(*ap); if (signo < 0 || signo > NSIG) error("%s: bad trap", *ap); INTOFF; if (action) action = savestr(action); if (trap[signo]) ckfree(trap[signo]); trap[signo] = action; if (signo != 0) setsignal(signo, 0); INTON; ap++; } return 0; }
void nosig (char *name) { fprintf (stderr, _("%s: unknown signal %s; valid signals:\n"), progname, name); printsignals (stderr); }
int main (int argc, char *argv[]) { int errors, numsig, pid; char *ep, *arg, *p; int do_pid, do_kill, check_all; int *pids, *ip; progname = argv[0]; if ((p = strrchr(progname, '/')) != NULL) progname = p+1; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); numsig = SIGTERM; do_pid = (! strcmp (progname, "pid")); /* Yecch */ do_kill = 0; check_all = 0; /* loop through the arguments. actually, -a is the only option can be used with other options. `kill' is basically a one-option-at-most program. */ for (argc--, argv++; argc > 0; argc--, argv++) { arg = *argv; if (*arg != '-') { break; } if (! strcmp (arg, "--")) { argc--, argv++; break; } if (! strcmp (arg, "-v") || ! strcmp (arg, "-V") || ! strcmp (arg, "--version")) { printf(_("%s from %s\n"), progname, PACKAGE_STRING); return 0; } if (! strcmp (arg, "-a")) { check_all++; continue; } if (! strcmp (arg, "-l")) { if (argc < 2) { printsignals (stdout); return 0; } if (argc > 2) { return usage (1); } /* argc == 2, accept "kill -l $?" */ arg = argv[1]; if ((numsig = arg_to_signum (arg, 1)) < 0) { fprintf (stderr, _("%s: unknown signal %s\n"), progname, arg); return 1; } printsig (numsig); return 0; } if (! strcmp (arg, "-p")) { do_pid++; if (do_kill) return usage (1); continue; } if (! strcmp (arg, "-s")) { if (argc < 2) { return usage (1); } do_kill++; if (do_pid) return usage (1); argc--, argv++; arg = *argv; if ((numsig = arg_to_signum (arg, 0)) < 0) { nosig (arg); return 1; } continue; } if (! strcmp (arg, "-q")) { if (argc < 2) return usage (1); argc--, argv++; arg = *argv; #ifdef HAVE_SIGQUEUE sigdata.sival_int = strtol_or_err(arg, _("failed to parse sigval")); use_sigval = 1; #endif continue; } /* `arg' begins with a dash but is not a known option. so it's probably something like -HUP, or -1/-n try to deal with it. -n could be signal n, or pid -n (i.e. process group n). In case of doubt POSIX tells us to assume a signal. If a signal has been parsed, assume it's a pid, break */ if (do_kill) break; arg++; if ((numsig = arg_to_signum (arg, 0)) < 0) { return usage (1); } do_kill++; if (do_pid) return usage (1); continue; } if (! *argv) { return usage (1); } if (do_pid) { numsig = -1; } /* we're done with the options. the rest of the arguments should be process ids and names. kill them. */ for (errors = 0; (arg = *argv) != NULL; argv++) { pid = strtol (arg, &ep, 10); if (! *ep) errors += kill_verbose (arg, pid, numsig); else { pids = get_pids (arg, check_all); if (! pids) { errors++; fprintf (stderr, _("%s: can't find process \"%s\"\n"), progname, arg); continue; } for (ip = pids; *ip >= 0; ip++) errors += kill_verbose (arg, *ip, numsig); free (pids); } } return (errors); }
int main(int argc, char *argv[]) { int errors, numsig, pid; char *ep; setprogname(argv[0]); setlocale(LC_ALL, ""); if (argc < 2) usage(); numsig = SIGTERM; argc--, argv++; if (strcmp(*argv, "-l") == 0) { argc--, argv++; if (argc > 1) usage(); if (argc == 1) { if (isdigit((unsigned char)**argv) == 0) usage(); numsig = strtol(*argv, &ep, 10); if (*ep != '\0') { errx(EXIT_FAILURE, "illegal signal number: %s", *argv); /* NOTREACHED */ } if (numsig >= 128) numsig -= 128; if (numsig <= 0 || numsig >= NSIG) nosig(*argv); printf("%s\n", sys_signame[numsig]); exit(0); } printsignals(stdout); exit(0); } if (!strcmp(*argv, "-s")) { argc--, argv++; if (argc < 1) { warnx("option requires an argument -- s"); usage(); } if (strcmp(*argv, "0")) { if ((numsig = signame_to_signum(*argv)) < 0) nosig(*argv); } else numsig = 0; argc--, argv++; } else if (**argv == '-') { char *sn = *argv + 1; if (isalpha((unsigned char)*sn)) { if ((numsig = signame_to_signum(sn)) < 0) nosig(sn); } else if (isdigit((unsigned char)*sn)) { numsig = strtol(sn, &ep, 10); if (*ep) { errx(EXIT_FAILURE, "illegal signal number: %s", sn); /* NOTREACHED */ } if (numsig < 0 || numsig >= NSIG) nosig(sn); } else nosig(sn); argc--, argv++; } if (argc == 0) usage(); for (errors = 0; argc; argc--, argv++) { #ifdef SHELL extern int getjobpgrp(const char *); if (*argv[0] == '%') { pid = getjobpgrp(*argv); if (pid == 0) { warnx("illegal job id: %s", *argv); errors = 1; continue; } } else #endif { pid = strtol(*argv, &ep, 10); if (!**argv || *ep) { warnx("illegal process id: %s", *argv); errors = 1; continue; } } if (kill(pid, numsig) == -1) { warn("%s", *argv); errors = 1; } #ifdef SHELL /* Wakeup the process if it was suspended, so it can exit without an explicit 'fg'. */ if (numsig == SIGTERM || numsig == SIGHUP) kill(pid, SIGCONT); #endif } exit(errors); /* NOTREACHED */ }
int main(int argc, char *argv[]) { int errors, numsig, pid; char *ep; if (argc < 2) usage(); numsig = SIGTERM; argc--, argv++; if (!strcmp(*argv, "-l")) { argc--, argv++; if (argc > 1) usage(); if (argc == 1) { if (!isdigit(**argv)) usage(); numsig = strtol(*argv, &ep, 10); if (!**argv || *ep) errx(2, "illegal signal number: %s", *argv); if (numsig >= 128) numsig -= 128; if (numsig <= 0 || numsig >= sys_nsig) nosig(*argv); printf("%s\n", sys_signame[numsig]); return (0); } printsignals(stdout); return (0); } if (!strcmp(*argv, "-s")) { argc--, argv++; if (argc < 1) { warnx("option requires an argument -- s"); usage(); } if (strcmp(*argv, "0")) { if ((numsig = signame_to_signum(*argv)) < 0) nosig(*argv); } else numsig = 0; argc--, argv++; } else if (**argv == '-' && *(*argv + 1) != '-') { ++*argv; if (isalpha(**argv)) { if ((numsig = signame_to_signum(*argv)) < 0) nosig(*argv); } else if (isdigit(**argv)) { numsig = strtol(*argv, &ep, 10); if (!**argv || *ep) errx(2, "illegal signal number: %s", *argv); if (numsig < 0) nosig(*argv); } else nosig(*argv); argc--, argv++; } if (argc > 0 && strncmp(*argv, "--", 2) == 0) argc--, argv++; if (argc == 0) usage(); for (errors = 0; argc; argc--, argv++) { #ifdef SHELL if (**argv == '%') pid = getjobpgrp(*argv); else #endif { pid = strtol(*argv, &ep, 10); if (!**argv || *ep) errx(2, "illegal process id: %s", *argv); } if (kill(pid, numsig) == -1) { warn("%s", *argv); errors = 1; } } return (errors); }
int main(int argc, char *argv[]) { int errors, numsig, pid; char *ep; if (argc < 2) usage(); numsig = SIGTERM; argc--; argv++; if (!strcmp(*argv, "-l")) { argc--, argv++; if (argc > 1) usage(); if (argc == 1) { if (isdigit((unsigned char)**argv) == 0) usage(); numsig = strtol(*argv, &ep, 10); if (!*argv || *ep) errx(1, "illegal signal number: %s", *argv); if (numsig >= 128) numsig -= 128; if (numsig <= 0 || numsig >= NSIG) nosig(*argv); printf("%s\n", sys_signame[numsig]); exit(0); } printsignals(stdout); exit(0); } if (!strcmp(*argv, "-s")) { argc--, argv++; if (argc < 1) { warnx("option requires an argument -- s"); usage(); } if (strcmp(*argv, "0")) { if ((numsig = signame_to_signum(*argv)) < 0) nosig(*argv); } else numsig = 0; argc--, argv++; } else if (**argv == '-') { ++*argv; if (isalpha(**argv)) { if ((numsig = signame_to_signum(*argv)) < 0) nosig(*argv); } else if (isdigit(**argv)) { numsig = strtol(*argv, &ep, 10); if (!*argv || *ep) errx(1, "illegal signal number: %s", *argv); if (numsig <= 0 || numsig >= NSIG) nosig(*argv); } else nosig(*argv); argc--, argv++; } if (argc == 0) usage(); for (errors = 0; argc; argc--, argv++) { pid = strtol(*argv, &ep, 10); if (!*argv || *ep) { warnx("illegal process id: %s", *argv); errors = 1; } else if (kill(pid, numsig) == -1) { warn("%s", *argv); errors = 1; } } exit(errors); }
int trapcmd(int argc, char **argv) { char *action; char **ap; int signo; int errs = 0; int printonly = 0; ap = argv + 1; if (argc == 2 && strcmp(*ap, "-l") == 0) { printsignals(); return 0; } if (argc == 2 && strcmp(*ap, "-") == 0) { for (signo = 0; signo < NSIG; signo++) { if (trap[signo] == NULL) continue; INTOFF; ckfree(trap[signo]); trap[signo] = NULL; if (signo != 0) setsignal(signo, 0); INTON; } return 0; } if (argc >= 2 && strcmp(*ap, "-p") == 0) { printonly = 1; ap++; argc--; } if (argc > 1 && strcmp(*ap, "--") == 0) { argc--; ap++; } if (argc <= 1) { int count; if (printonly) { for (count = 0, signo = 0 ; signo < NSIG ; signo++) if (trap[signo] == NULL) { if (count == 0) out1str("trap -- -"); out1fmt(" %s", trap_signame(signo)); /* oh! unlucky 13 */ if (++count >= 13) { out1str("\n"); count = 0; } } if (count) out1str("\n"); } for (count = 0, signo = 0 ; signo < NSIG ; signo++) if (trap[signo] != NULL && trap[signo][0] == '\0') { if (count == 0) out1str("trap -- ''"); out1fmt(" %s", trap_signame(signo)); /* * the prefix is 10 bytes, with 4 byte * signal names (common) we have room in * the 70 bytes left on a normal line for * 70/(4+1) signals, that's 14, but to * allow for the occasional longer sig name * we output one less... */ if (++count >= 13) { out1str("\n"); count = 0; } } if (count) out1str("\n"); for (signo = 0 ; signo < NSIG ; signo++) if (trap[signo] != NULL && trap[signo][0] != '\0') { out1str("trap -- "); print_quoted(trap[signo]); out1fmt(" %s\n", trap_signame(signo)); } return 0; } action = NULL; if (!printonly && !is_number(*ap)) { if ((*ap)[0] == '-' && (*ap)[1] == '\0') ap++; /* reset to default */ else action = *ap++; /* can be '' for "ignore" */ argc--; } if (argc < 2) { /* there must be at least 1 condition */ out2str("Usage: trap [-l]\n" " trap -p [condition ...]\n" " trap action condition ...\n" " trap N condition ...\n"); return 2; } while (*ap) { signo = signame_to_signum(*ap); if (signo < 0 || signo >= NSIG) { /* This is not a fatal error, so sayeth posix */ outfmt(out2, "trap: '%s' bad condition\n", *ap); errs = 1; ap++; continue; } ap++; if (printonly) { out1str("trap -- "); if (trap[signo] == NULL) out1str("-"); else print_quoted(trap[signo]); out1fmt(" %s\n", trap_signame(signo)); continue; } INTOFF; if (action) action = savestr(action); if (trap[signo]) ckfree(trap[signo]); trap[signo] = action; if (signo != 0) setsignal(signo, 0); INTON; } return errs; }
int trapcmd(shinstance *psh, int argc, char **argv) { char *action; char **ap; int signo; #ifndef HAVE_SYS_SIGNAME init_sys_signame(); #endif if (argc <= 1) { for (signo = 0 ; signo <= NSIG ; signo++) if (psh->trap[signo] != NULL) { out1fmt(psh, "trap -- "); print_quoted(psh, psh->trap[signo]); out1fmt(psh, " %s\n", (signo) ? sys_signame[signo] : "EXIT"); } return 0; } ap = argv + 1; action = NULL; if (strcmp(*ap, "--") == 0) if (*++ap == NULL) return 0; if (signame_to_signum(psh, *ap) == -1) { if ((*ap)[0] == '-') { if ((*ap)[1] == '\0') ap++; else if ((*ap)[1] == 'l' && (*ap)[2] == '\0') { printsignals(psh); return 0; } else error(psh, "bad option %s\n", *ap); } else action = *ap++; } while (*ap) { if (is_number(*ap)) signo = number(psh, *ap); else signo = signame_to_signum(psh, *ap); if (signo < 0 || signo > NSIG) error(psh, "%s: bad trap", *ap); INTOFF; if (action) action = savestr(psh, action); if (psh->trap[signo]) ckfree(psh, psh->trap[signo]); psh->trap[signo] = action; if (signo != 0) setsignal(psh, signo, 0); INTON; ap++; } return 0; }