trap.c (199205) | trap.c (199641) |
---|---|
1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Kenneth Almquist. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 22 unchanged lines hidden (view full) --- 31 */ 32 33#ifndef lint 34#if 0 35static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95"; 36#endif 37#endif /* not lint */ 38#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Kenneth Almquist. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 22 unchanged lines hidden (view full) --- 31 */ 32 33#ifndef lint 34#if 0 35static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95"; 36#endif 37#endif /* not lint */ 38#include <sys/cdefs.h> |
39__FBSDID("$FreeBSD: head/bin/sh/trap.c 199205 2009-11-11 23:13:24Z jilles $"); | 39__FBSDID("$FreeBSD: head/bin/sh/trap.c 199641 2009-11-21 20:44:34Z jilles $"); |
40 41#include <signal.h> 42#include <unistd.h> 43#include <stdlib.h> 44 45#include "shell.h" 46#include "main.h" 47#include "nodes.h" /* for other headers */ --- 96 unchanged lines hidden (view full) --- 144/* 145 * The trap builtin. 146 */ 147int 148trapcmd(int argc, char **argv) 149{ 150 char *action; 151 int signo; | 40 41#include <signal.h> 42#include <unistd.h> 43#include <stdlib.h> 44 45#include "shell.h" 46#include "main.h" 47#include "nodes.h" /* for other headers */ --- 96 unchanged lines hidden (view full) --- 144/* 145 * The trap builtin. 146 */ 147int 148trapcmd(int argc, char **argv) 149{ 150 char *action; 151 int signo; |
152 int errors = 0; |
|
152 153 if (argc <= 1) { 154 for (signo = 0 ; signo < sys_nsig ; signo++) { 155 if (signo < NSIG && trap[signo] != NULL) { 156 out1str("trap -- "); 157 out1qstr(trap[signo]); 158 if (signo == 0) { 159 out1str(" exit\n"); --- 18 unchanged lines hidden (view full) --- 178 } else if ((*argv)[1] == 'l' && (*argv)[2] == '\0') { 179 printsignals(); 180 return 0; 181 } else { 182 error("bad option %s", *argv); 183 } 184 } 185 while (*argv) { | 153 154 if (argc <= 1) { 155 for (signo = 0 ; signo < sys_nsig ; signo++) { 156 if (signo < NSIG && trap[signo] != NULL) { 157 out1str("trap -- "); 158 out1qstr(trap[signo]); 159 if (signo == 0) { 160 out1str(" exit\n"); --- 18 unchanged lines hidden (view full) --- 179 } else if ((*argv)[1] == 'l' && (*argv)[2] == '\0') { 180 printsignals(); 181 return 0; 182 } else { 183 error("bad option %s", *argv); 184 } 185 } 186 while (*argv) { |
186 if ((signo = sigstring_to_signum(*argv)) == -1) 187 error("bad signal %s", *argv); | 187 if ((signo = sigstring_to_signum(*argv)) == -1) { 188 out2fmt_flush("trap: bad signal %s\n", *argv); 189 errors = 1; 190 } |
188 INTOFF; 189 if (action) 190 action = savestr(action); 191 if (trap[signo]) 192 ckfree(trap[signo]); 193 trap[signo] = action; 194 if (signo != 0) 195 setsignal(signo); 196 INTON; 197 argv++; 198 } | 191 INTOFF; 192 if (action) 193 action = savestr(action); 194 if (trap[signo]) 195 ckfree(trap[signo]); 196 trap[signo] = action; 197 if (signo != 0) 198 setsignal(signo); 199 INTON; 200 argv++; 201 } |
199 return 0; | 202 return errors; |
200} 201 202 203/* 204 * Clear traps on a fork. 205 */ 206void 207clear_traps(void) --- 292 unchanged lines hidden --- | 203} 204 205 206/* 207 * Clear traps on a fork. 208 */ 209void 210clear_traps(void) --- 292 unchanged lines hidden --- |