]> git.pld-linux.org Git - packages/ash.git/blame - ash-kill.patch
- dropped pre-cvs changelog
[packages/ash.git] / ash-kill.patch
CommitLineData
cf7098dd
MM
1diff -urN netbsd-sh/jobs.c ash-0.3.7.orig/jobs.c
2--- netbsd-sh/jobs.c Tue May 23 12:03:19 2000
3+++ ash-0.3.7.orig/jobs.c Mon Apr 23 22:16:46 2001
4@@ -189,6 +193,94 @@
5
6 #if JOBS
7 int
8+killcmd(argc, argv)
9+ int argc;
10+ char **argv;
11+{
12+ extern char *signal_names[];
13+ int signo = -1;
14+ int list = 0;
15+ int i;
16+ pid_t pid;
17+ struct job *jp;
18+
19+ if (argc <= 1) {
20+ error(
21+"Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or\n"
22+"kill -l [exitstatus]"
23+ );
24+ }
25+
26+ if (*argv[1] == '-') {
27+ signo = decode_signal(argv[1]+1);
28+ if (signo < 0) {
29+ int c;
30+
31+ while ((c = nextopt("ls:")) != '\0')
32+ switch (c) {
33+ case 'l':
34+ list = 1;
35+ break;
36+ case 's':
37+ signo = decode_signal(optarg);
38+ break;
39+ default:
40+ error(
41+ "nextopt returned character code 0%o", c);
42+ }
43+ } else
44+ argptr++;
45+ }
46+
47+ if (!list && signo < 0)
48+ signo = SIGTERM;
49+
50+ if ((signo < 0 || !*argptr) ^ list) {
51+ error(
52+"Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or\n"
53+"kill -l [exitstatus]"
54+ );
55+ }
56+
57+ if (list) {
58+ if (!*argptr) {
59+ out1fmt("0\n");
60+ for (i = 1; i < NSIG; i++) {
61+ if (strncmp(signal_names[i], "SIGJUNK(", 8)
62+ == 0)
63+ continue;
64+ out1fmt("%s\n", signal_names[i] + 3);
65+ }
66+ return 0;
67+ }
68+ signo = atoi(*argptr);
69+ if (signo > 128)
70+ signo -= 128;
71+ if (0 < signo && signo < NSIG)
72+ out1fmt("%s\n", signal_names[signo] + 3);
73+ else
74+ error("invalid signal number or exit status: %s",
75+ *argptr);
76+ return 0;
77+ }
78+
79+ do {
80+ if (**argptr == '%') {
81+ jp = getjob(*argptr);
82+ if (jp->jobctl == 0)
83+ error("job %s not created under job control",
84+ *argptr);
85+ pid = -jp->ps[0].pid;
86+ } else
87+ pid = atoi(*argptr);
88+ if (kill(pid, signo) != 0)
89+ error("%s: %s", *argptr, strerror(errno));
90+ } while (*++argptr);
91+
92+ return 0;
93+}
94+
95+int
96 fgcmd(argc, argv)
97 int argc;
98 char **argv;
99
100diff -urN netbsd-sh/jobs.h ash-0.3.7.orig/jobs.h
101--- netbsd-sh/jobs.h Tue May 23 12:03:19 2000
102+++ ash-0.3.7.orig/jobs.h Mon Apr 23 22:16:46 2001
103@@ -80,6 +80,7 @@
104 extern int job_warning; /* user was warned about stopped jobs */
105
106 void setjobctl __P((int));
107+int killcmd __P((int, char **));
108 int fgcmd __P((int, char **));
109 int bgcmd __P((int, char **));
110 int jobscmd __P((int, char **));
111diff -urN netbsd-sh/builtins.def ash-0.3.7.orig/builtins.def
112--- netbsd-sh/builtins.def Mon Apr 10 13:02:58 2000
113+++ ash-0.3.7.orig/builtins.def Mon Apr 23 22:16:46 2001
114@@ -70,6 +71,7 @@
115 hashcmd hash
116 jobidcmd jobid
117 jobscmd jobs
118+killcmd -j kill
119 #linecmd line
120 localcmd local
121 #nlechocmd nlecho
122diff -urN netbsd-sh/mksignames.c ash-0.3.7.orig/mksignames.c
123--- netbsd-sh/mksignames.c Thu Jan 1 01:00:00 1970
124+++ ash-0.3.7.orig/mksignames.c Mon Apr 23 22:16:46 2001
125@@ -0,0 +1,400 @@
126+/* signames.c -- Create and write `signames.c', which contains an array of
127+ signal names. */
128+
129+/* Copyright (C) 1992 Free Software Foundation, Inc.
130+
131+ This file is part of GNU Bash, the Bourne Again SHell.
132+
133+ Bash is free software; you can redistribute it and/or modify it under
134+ the terms of the GNU General Public License as published by the Free
135+ Software Foundation; either version 2, or (at your option) any later
136+ version.
137+
138+ Bash is distributed in the hope that it will be useful, but WITHOUT ANY
139+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
140+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
141+ for more details.
142+
143+ You should have received a copy of the GNU General Public License along
144+ with Bash; see the file COPYING. If not, write to the Free Software
145+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
146+
147+#include <stdio.h>
148+#include <sys/types.h>
149+#include <signal.h>
150+#include <stdlib.h>
151+
152+#if !defined (NSIG)
153+# define NSIG 64
154+#endif
155+
156+char *signal_names[2 * NSIG];
157+
158+char *progname;
159+
160+#if defined (SIGRTMAX) || defined (SIGRTMIN)
161+# define RTLEN 14
162+# define RTLIM 256
163+#endif
164+
165+void
166+initialize_signames ()
167+{
168+ register int i;
169+#if defined (SIGRTMAX) || defined (SIGRTMIN)
170+ int rtmin, rtmax, rtcnt;
171+#endif
172+
173+ for (i = 1; i < sizeof(signal_names)/sizeof(signal_names[0]); i++)
174+ signal_names[i] = (char *)NULL;
175+
176+ /* `signal' 0 is what we do on exit. */
177+ signal_names[0] = "EXIT";
178+
179+ /* Place signal names which can be aliases for more common signal
180+ names first. This allows (for example) SIGABRT to overwrite SIGLOST. */
181+
182+ /* POSIX 1003.1b-1993 real time signals, but take care of incomplete
183+ implementations. Acoording to the standard, both, SIGRTMIN and
184+ SIGRTMAX must be defined, SIGRTMIN must be stricly less than
185+ SIGRTMAX, and the difference must be at least 7, that is, there
186+ must be at least eight distinct real time signals. */
187+
188+ /* The generated signal names are SIGRTMIN, SIGRTMIN+1, ...,
189+ SIGRTMIN+x, SIGRTMAX-x, ..., SIGRTMAX-1, SIGRTMAX. If the number
190+ of RT signals is odd, there is an extra SIGRTMIN+(x+1).
191+ These names are the ones used by ksh and /usr/xpg4/bin/sh on SunOS5. */
192+
193+#if defined (SIGRTMIN)
194+ rtmin = SIGRTMIN;
195+ signal_names[rtmin] = "SIGRTMIN";
196+#endif
197+
198+#if defined (SIGRTMAX)
199+ rtmax = SIGRTMAX;
200+ signal_names[rtmax] = "SIGRTMAX";
201+#endif
202+
203+#if defined (SIGRTMAX) && defined (SIGRTMIN)
204+ if (rtmax > rtmin)
205+ {
206+ rtcnt = (rtmax - rtmin - 1) / 2;
207+ /* croak if there are too many RT signals */
208+ if (rtcnt >= RTLIM/2)
209+ {
210+ rtcnt = RTLIM/2-1;
211+ fprintf(stderr, "%s: error: more than %i real time signals, fix `%s'\n",
212+ progname, RTLIM, progname);
213+ }
214+
215+ for (i = 1; i <= rtcnt; i++)
216+ {
217+ signal_names[rtmin+i] = (char *)malloc(RTLEN);
218+ sprintf (signal_names[rtmin+i], "SIGRTMIN+%d", i);
219+ signal_names[rtmax-i] = (char *)malloc(RTLEN);
220+ sprintf (signal_names[rtmax-i], "SIGRTMAX-%d", i);
221+ }
222+
223+ if (rtcnt < RTLIM/2-1 && rtcnt != (rtmax-rtmin)/2)
224+ {
225+ /* Need an extra RTMIN signal */
226+ signal_names[rtmin+rtcnt+1] = (char *)malloc(RTLEN);
227+ sprintf (signal_names[rtmin+rtcnt+1], "SIGRTMIN+%d", rtcnt+1);
228+ }
229+ }
230+#endif /* SIGRTMIN && SIGRTMAX */
231+
232+/* AIX */
233+#if defined (SIGLOST) /* resource lost (eg, record-lock lost) */
234+ signal_names[SIGLOST] = "SIGLOST";
235+#endif
236+
237+#if defined (SIGMSG) /* HFT input data pending */
238+ signal_names[SIGMSG] = "SIGMSG";
239+#endif
240+
241+#if defined (SIGDANGER) /* system crash imminent */
242+ signal_names[SIGDANGER] = "SIGDANGER";
243+#endif
244+
245+#if defined (SIGMIGRATE) /* migrate process to another CPU */
246+ signal_names[SIGMIGRATE] = "SIGMIGRATE";
247+#endif
248+
249+#if defined (SIGPRE) /* programming error */
250+ signal_names[SIGPRE] = "SIGPRE";
251+#endif
252+
253+#if defined (SIGVIRT) /* AIX virtual time alarm */
254+ signal_names[SIGVIRT] = "SIGVIRT";
255+#endif
256+
257+#if defined (SIGALRM1) /* m:n condition variables */
258+ signal_names[SIGALRM1] = "SIGALRM1";
259+#endif
260+
261+#if defined (SIGWAITING) /* m:n scheduling */
262+ signal_names[SIGWAITING] = "SIGWAITING";
263+#endif
264+
265+#if defined (SIGGRANT) /* HFT monitor mode granted */
266+ signal_names[SIGGRANT] = "SIGGRANT";
267+#endif
268+
269+#if defined (SIGKAP) /* keep alive poll from native keyboard */
270+ signal_names[SIGKAP] = "SIGKAP";
271+#endif
272+
273+#if defined (SIGRETRACT) /* HFT monitor mode retracted */
274+ signal_names[SIGRETRACT] = "SIGRETRACT";
275+#endif
276+
277+#if defined (SIGSOUND) /* HFT sound sequence has completed */
278+ signal_names[SIGSOUND] = "SIGSOUND";
279+#endif
280+
281+#if defined (SIGSAK) /* Secure Attention Key */
282+ signal_names[SIGSAK] = "SIGSAK";
283+#endif
284+
285+/* SunOS5 */
286+#if defined (SIGLWP) /* special signal used by thread library */
287+ signal_names[SIGLWP] = "SIGLWP";
288+#endif
289+
290+#if defined (SIGFREEZE) /* special signal used by CPR */
291+ signal_names[SIGFREEZE] = "SIGFREEZE";
292+#endif
293+
294+#if defined (SIGTHAW) /* special signal used by CPR */
295+ signal_names[SIGTHAW] = "SIGTHAW";
296+#endif
297+
298+#if defined (SIGCANCEL) /* thread cancellation signal used by libthread */
299+ signal_names[SIGCANCEL] = "SIGCANCEL";
300+#endif
301+
302+/* HP-UX */
303+#if defined (SIGDIL) /* DIL signal (?) */
304+ signal_names[SIGDIL] = "SIGDIL";
305+#endif
306+
307+/* System V */
308+#if defined (SIGCLD) /* Like SIGCHLD. */
309+ signal_names[SIGCLD] = "SIGCLD";
310+#endif
311+
312+#if defined (SIGPWR) /* power state indication */
313+ signal_names[SIGPWR] = "SIGPWR";
314+#endif
315+
316+#if defined (SIGPOLL) /* Pollable event (for streams) */
317+ signal_names[SIGPOLL] = "SIGPOLL";
318+#endif
319+
320+/* Unknown */
321+#if defined (SIGWINDOW)
322+ signal_names[SIGWINDOW] = "SIGWINDOW";
323+#endif
324+
325+/* Common */
326+#if defined (SIGHUP) /* hangup */
327+ signal_names[SIGHUP] = "SIGHUP";
328+#endif
329+
330+#if defined (SIGINT) /* interrupt */
331+ signal_names[SIGINT] = "SIGINT";
332+#endif
333+
334+#if defined (SIGQUIT) /* quit */
335+ signal_names[SIGQUIT] = "SIGQUIT";
336+#endif
337+
338+#if defined (SIGILL) /* illegal instruction (not reset when caught) */
339+ signal_names[SIGILL] = "SIGILL";
340+#endif
341+
342+#if defined (SIGTRAP) /* trace trap (not reset when caught) */
343+ signal_names[SIGTRAP] = "SIGTRAP";
344+#endif
345+
346+#if defined (SIGIOT) /* IOT instruction */
347+ signal_names[SIGIOT] = "SIGIOT";
348+#endif
349+
350+#if defined (SIGABRT) /* Cause current process to dump core. */
351+ signal_names[SIGABRT] = "SIGABRT";
352+#endif
353+
354+#if defined (SIGEMT) /* EMT instruction */
355+ signal_names[SIGEMT] = "SIGEMT";
356+#endif
357+
358+#if defined (SIGFPE) /* floating point exception */
359+ signal_names[SIGFPE] = "SIGFPE";
360+#endif
361+
362+#if defined (SIGKILL) /* kill (cannot be caught or ignored) */
363+ signal_names[SIGKILL] = "SIGKILL";
364+#endif
365+
366+#if defined (SIGBUS) /* bus error */
367+ signal_names[SIGBUS] = "SIGBUS";
368+#endif
369+
370+#if defined (SIGSEGV) /* segmentation violation */
371+ signal_names[SIGSEGV] = "SIGSEGV";
372+#endif
373+
374+#if defined (SIGSYS) /* bad argument to system call */
375+ signal_names[SIGSYS] = "SIGSYS";
376+#endif
377+
378+#if defined (SIGPIPE) /* write on a pipe with no one to read it */
379+ signal_names[SIGPIPE] = "SIGPIPE";
380+#endif
381+
382+#if defined (SIGALRM) /* alarm clock */
383+ signal_names[SIGALRM] = "SIGALRM";
384+#endif
385+
386+#if defined (SIGTERM) /* software termination signal from kill */
387+ signal_names[SIGTERM] = "SIGTERM";
388+#endif
389+
390+#if defined (SIGURG) /* urgent condition on IO channel */
391+ signal_names[SIGURG] = "SIGURG";
392+#endif
393+
394+#if defined (SIGSTOP) /* sendable stop signal not from tty */
395+ signal_names[SIGSTOP] = "SIGSTOP";
396+#endif
397+
398+#if defined (SIGTSTP) /* stop signal from tty */
399+ signal_names[SIGTSTP] = "SIGTSTP";
400+#endif
401+
402+#if defined (SIGCONT) /* continue a stopped process */
403+ signal_names[SIGCONT] = "SIGCONT";
404+#endif
405+
406+#if defined (SIGCHLD) /* to parent on child stop or exit */
407+ signal_names[SIGCHLD] = "SIGCHLD";
408+#endif
409+
410+#if defined (SIGTTIN) /* to readers pgrp upon background tty read */
411+ signal_names[SIGTTIN] = "SIGTTIN";
412+#endif
413+
414+#if defined (SIGTTOU) /* like TTIN for output if (tp->t_local&LTOSTOP) */
415+ signal_names[SIGTTOU] = "SIGTTOU";
416+#endif
417+
418+#if defined (SIGIO) /* input/output possible signal */
419+ signal_names[SIGIO] = "SIGIO";
420+#endif
421+
422+#if defined (SIGXCPU) /* exceeded CPU time limit */
423+ signal_names[SIGXCPU] = "SIGXCPU";
424+#endif
425+
426+#if defined (SIGXFSZ) /* exceeded file size limit */
427+ signal_names[SIGXFSZ] = "SIGXFSZ";
428+#endif
429+
430+#if defined (SIGVTALRM) /* virtual time alarm */
431+ signal_names[SIGVTALRM] = "SIGVTALRM";
432+#endif
433+
434+#if defined (SIGPROF) /* profiling time alarm */
435+ signal_names[SIGPROF] = "SIGPROF";
436+#endif
437+
438+#if defined (SIGWINCH) /* window changed */
439+ signal_names[SIGWINCH] = "SIGWINCH";
440+#endif
441+
442+/* 4.4 BSD */
443+#if defined (SIGINFO) && !defined (_SEQUENT_) /* information request */
444+ signal_names[SIGINFO] = "SIGINFO";
445+#endif
446+
447+#if defined (SIGUSR1) /* user defined signal 1 */
448+ signal_names[SIGUSR1] = "SIGUSR1";
449+#endif
450+
451+#if defined (SIGUSR2) /* user defined signal 2 */
452+ signal_names[SIGUSR2] = "SIGUSR2";
453+#endif
454+
455+#if defined (SIGKILLTHR) /* BeOS: Kill Thread */
456+ signal_names[SIGKILLTHR] = "SIGKILLTHR";
457+#endif
458+
459+ for (i = 0; i < NSIG; i++)
460+ if (signal_names[i] == (char *)NULL)
461+ {
462+ signal_names[i] = (char *)malloc (18);
463+ sprintf (signal_names[i], "SIGJUNK(%d)", i);
464+ }
465+
466+ signal_names[NSIG] = "DEBUG";
467+}
468+
469+void
470+write_signames (stream)
471+ FILE *stream;
472+{
473+ register int i;
474+
475+ fprintf (stream, "/* This file was automatically created by %s.\n",
476+ progname);
477+ fprintf (stream, " Do not edit. Edit support/mksignames.c instead. */\n\n");
478+ fprintf (stream, "#include <signal.h>\n\n");
479+ fprintf (stream,
480+ "/* A translation list so we can be polite to our users. */\n");
481+ fprintf (stream, "char *signal_names[NSIG + 2] = {\n");
482+
483+ for (i = 0; i <= NSIG; i++)
484+ fprintf (stream, " \"%s\",\n", signal_names[i]);
485+
486+ fprintf (stream, " (char *)0x0,\n");
487+ fprintf (stream, "};\n");
488+}
489+
490+int
491+main (argc, argv)
492+ int argc;
493+ char **argv;
494+{
495+ char *stream_name;
496+ FILE *stream;
497+
498+ progname = argv[0];
499+
500+ if (argc == 1)
501+ {
502+ stream_name = "signames.c";
503+ }
504+ else if (argc == 2)
505+ {
506+ stream_name = argv[1];
507+ }
508+ else
509+ {
510+ fprintf (stderr, "Usage: %s [output-file]\n", progname);
511+ exit (1);
512+ }
513+
514+ stream = fopen (stream_name, "w");
515+ if (!stream)
516+ {
517+ fprintf (stderr, "%s: %s: cannot open for writing\n",
518+ progname, stream_name);
519+ exit (2);
520+ }
521+
522+ initialize_signames ();
523+ write_signames (stream);
524+ exit (0);
525+}
526diff -urN netbsd-sh/trap.c ash-0.3.7.orig/trap.c
527--- netbsd-sh/trap.c Tue May 23 12:03:19 2000
528+++ ash-0.3.7.orig/trap.c Mon Apr 23 22:16:46 2001
529@@ -84,7 +88,7 @@
530 char gotsig[NSIG]; /* indicates specified signal received */
531 int pendingsigs; /* indicates some signal received */
532
533-static int getsigaction __P((int, sig_t *));
534+extern char *signal_names[];
535
536 /*
537 * The trap builtin.
538@@ -107,16 +111,20 @@
539 return 0;
540 }
541 ap = argv + 1;
542- if (is_number(*ap))
543+ if (argc == 2)
544 action = NULL;
545 else
546 action = *ap++;
547 while (*ap) {
548- if ((signo = number(*ap)) < 0 || signo > NSIG)
549+ if ((signo = decode_signal(*ap)) < 0)
550 error("%s: bad trap", *ap);
551 INTOFF;
552- if (action)
553- action = savestr(action);
554+ if (action) {
555+ if (action[0] == '-' && action[1] == '\0')
556+ action = NULL;
557+ else
558+ action = savestr(action);
559+ }
560 if (trap[signo])
561 ckfree(trap[signo]);
562 trap[signo] = action;
563@@ -157,13 +165,13 @@
564 * out what it should be set to.
565 */
566
567-long
568+void
569 setsignal(signo)
570 int signo;
571 {
572 int action;
573- sig_t sigact = SIG_DFL;
574 char *t;
575+ struct sigaction act;
576
577 if ((t = trap[signo]) == NULL)
578 action = S_DFL;
579@@ -206,15 +214,15 @@
580 /*
581 * current setting unknown
582 */
583- if (!getsigaction(signo, &sigact)) {
584+ if (sigaction(signo, 0, &act) == -1) {
585 /*
586 * Pretend it worked; maybe we should give a warning
587 * here, but other shells don't. We don't alter
588 * sigmode, so that we retry every time.
589 */
590- return 0;
591+ return;
592 }
593- if (sigact == SIG_IGN) {
594+ if (act.sa_handler == SIG_IGN) {
595 if (mflag && (signo == SIGTSTP ||
596 signo == SIGTTIN || signo == SIGTTOU)) {
597 *t = S_IGN; /* don't hard ignore these */
598@@ -225,31 +233,21 @@
599 }
600 }
601 if (*t == S_HARD_IGN || *t == action)
602- return 0;
603+ return;
604 switch (action) {
605- case S_DFL: sigact = SIG_DFL; break;
606- case S_CATCH: sigact = onsig; break;
607- case S_IGN: sigact = SIG_IGN; break;
608+ case S_CATCH:
609+ act.sa_handler = onsig;
610+ break;
611+ case S_IGN:
612+ act.sa_handler = SIG_IGN;
613+ break;
614+ default:
615+ act.sa_handler = SIG_DFL;
616 }
617 *t = action;
618- siginterrupt(signo, 1);
619- return (long)signal(signo, sigact);
620-}
621-
622-/*
623- * Return the current setting for sig w/o changing it.
624- */
625-static int
626-getsigaction(signo, sigact)
627- int signo;
628- sig_t *sigact;
629-{
630- struct sigaction sa;
631-
632- if (sigaction(signo, (struct sigaction *)0, &sa) == -1)
633- return 0;
634- *sigact = (sig_t) sa.sa_handler;
635- return 1;
636+ act.sa_flags = 0;
637+ sigemptyset(&act.sa_mask);
638+ sigaction(signo, &act, 0);
639 }
640
641 /*
642@@ -382,4 +384,18 @@
643 #endif
644 l2: _exit(status);
645 /* NOTREACHED */
646+}
647+
648+int decode_signal(const char *string)
649+{
650+ int signo;
651+
652+ if (is_number(string)) return atoi(string);
653+
654+ for (signo=0; signo < NSIG; signo++)
655+ if (strcasecmp(string, signal_names[signo]) == 0 ||
656+ strcasecmp(string, &(signal_names[signo])[3]) == 0)
657+ return signo;
658+
659+ return -1;
660 }
661diff -urN netbsd-sh/trap.h ash-0.3.7.orig/trap.h
662--- netbsd-sh/trap.h Tue May 23 12:03:19 2000
663+++ ash-0.3.7.orig/trap.h Mon Apr 23 22:16:46 2001
664@@ -42,9 +42,10 @@
665
666 int trapcmd __P((int, char **));
667 void clear_traps __P((void));
668-long setsignal __P((int));
669+void setsignal __P((int));
670 void ignoresig __P((int));
671 void onsig __P((int));
672 void dotrap __P((void));
673 void setinteractive __P((int));
674 void exitshell __P((int)) __attribute__((noreturn));
675+int decode_signal __P((const char *));
This page took 0.20574 seconds and 4 git commands to generate.