#include "closestream.h"
#include "procutils.h"
#include "strutils.h"
+#include "ttyutils.h"
+#include "xalloc.h"
struct signv {
- char *name;
+ const char *name;
int val;
} sys_signame[] = {
/* POSIX signals */
{ "INT", SIGINT }, /* 2 */
{ "QUIT", SIGQUIT }, /* 3 */
{ "ILL", SIGILL }, /* 4 */
- { "ABRT", SIGABRT }, /* 6 */
- { "FPE", SIGFPE }, /* 8 */
- { "KILL", SIGKILL }, /* 9 */
- { "SEGV", SIGSEGV }, /* 11 */
- { "PIPE", SIGPIPE }, /* 13 */
- { "ALRM", SIGALRM }, /* 14 */
- { "TERM", SIGTERM }, /* 15 */
- { "USR1", SIGUSR1 }, /* 10 (arm,i386,m68k,ppc), 30 (alpha,sparc*), 16 (mips) */
- { "USR2", SIGUSR2 }, /* 12 (arm,i386,m68k,ppc), 31 (alpha,sparc*), 17 (mips) */
- { "CHLD", SIGCHLD }, /* 17 (arm,i386,m68k,ppc), 20 (alpha,sparc*), 18 (mips) */
- { "CONT", SIGCONT }, /* 18 (arm,i386,m68k,ppc), 19 (alpha,sparc*), 25 (mips) */
- { "STOP", SIGSTOP }, /* 19 (arm,i386,m68k,ppc), 17 (alpha,sparc*), 23 (mips) */
- { "TSTP", SIGTSTP }, /* 20 (arm,i386,m68k,ppc), 18 (alpha,sparc*), 24 (mips) */
- { "TTIN", SIGTTIN }, /* 21 (arm,i386,m68k,ppc,alpha,sparc*), 26 (mips) */
- { "TTOU", SIGTTOU }, /* 22 (arm,i386,m68k,ppc,alpha,sparc*), 27 (mips) */
- /* Miscellaneous other signals */
#ifdef SIGTRAP
{ "TRAP", SIGTRAP }, /* 5 */
#endif
+ { "ABRT", SIGABRT }, /* 6 */
#ifdef SIGIOT
{ "IOT", SIGIOT }, /* 6, same as SIGABRT */
#endif
#ifdef SIGBUS
{ "BUS", SIGBUS }, /* 7 (arm,i386,m68k,ppc), 10 (mips,alpha,sparc*) */
#endif
-#ifdef SIGSYS
- { "SYS", SIGSYS }, /* 12 (mips,alpha,sparc*) */
-#endif
+ { "FPE", SIGFPE }, /* 8 */
+ { "KILL", SIGKILL }, /* 9 */
+ { "USR1", SIGUSR1 }, /* 10 (arm,i386,m68k,ppc), 30 (alpha,sparc*), 16 (mips) */
+ { "SEGV", SIGSEGV }, /* 11 */
+ { "USR2", SIGUSR2 }, /* 12 (arm,i386,m68k,ppc), 31 (alpha,sparc*), 17 (mips) */
+ { "PIPE", SIGPIPE }, /* 13 */
+ { "ALRM", SIGALRM }, /* 14 */
+ { "TERM", SIGTERM }, /* 15 */
#ifdef SIGSTKFLT
{ "STKFLT", SIGSTKFLT }, /* 16 (arm,i386,m68k,ppc) */
#endif
-#ifdef SIGURG
- { "URG", SIGURG }, /* 23 (arm,i386,m68k,ppc), 16 (alpha,sparc*), 21 (mips) */
-#endif
-#ifdef SIGIO
- { "IO", SIGIO }, /* 29 (arm,i386,m68k,ppc), 23 (alpha,sparc*), 22 (mips) */
-#endif
-#ifdef SIGPOLL
- { "POLL", SIGPOLL }, /* same as SIGIO */
-#endif
+ { "CHLD", SIGCHLD }, /* 17 (arm,i386,m68k,ppc), 20 (alpha,sparc*), 18 (mips) */
#ifdef SIGCLD
{ "CLD", SIGCLD }, /* same as SIGCHLD (mips) */
+#endif
+ { "CONT", SIGCONT }, /* 18 (arm,i386,m68k,ppc), 19 (alpha,sparc*), 25 (mips) */
+ { "STOP", SIGSTOP }, /* 19 (arm,i386,m68k,ppc), 17 (alpha,sparc*), 23 (mips) */
+ { "TSTP", SIGTSTP }, /* 20 (arm,i386,m68k,ppc), 18 (alpha,sparc*), 24 (mips) */
+ { "TTIN", SIGTTIN }, /* 21 (arm,i386,m68k,ppc,alpha,sparc*), 26 (mips) */
+ { "TTOU", SIGTTOU }, /* 22 (arm,i386,m68k,ppc,alpha,sparc*), 27 (mips) */
+#ifdef SIGURG
+ { "URG", SIGURG }, /* 23 (arm,i386,m68k,ppc), 16 (alpha,sparc*), 21 (mips) */
#endif
#ifdef SIGXCPU
{ "XCPU", SIGXCPU }, /* 24 (arm,i386,m68k,ppc,alpha,sparc*), 30 (mips) */
#ifdef SIGPROF
{ "PROF", SIGPROF }, /* 27 (arm,i386,m68k,ppc,alpha,sparc*), 29 (mips) */
#endif
-#ifdef SIGPWR
- { "PWR", SIGPWR }, /* 30 (arm,i386,m68k,ppc), 29 (alpha,sparc*), 19 (mips) */
+#ifdef SIGWINCH
+ { "WINCH", SIGWINCH }, /* 28 (arm,i386,m68k,ppc,alpha,sparc*), 20 (mips) */
+#endif
+#ifdef SIGIO
+ { "IO", SIGIO }, /* 29 (arm,i386,m68k,ppc), 23 (alpha,sparc*), 22 (mips) */
+#endif
+#ifdef SIGPOLL
+ { "POLL", SIGPOLL }, /* same as SIGIO */
#endif
#ifdef SIGINFO
{ "INFO", SIGINFO }, /* 29 (alpha) */
#ifdef SIGLOST
{ "LOST", SIGLOST }, /* 29 (arm,i386,m68k,ppc,sparc*) */
#endif
-#ifdef SIGWINCH
- { "WINCH", SIGWINCH }, /* 28 (arm,i386,m68k,ppc,alpha,sparc*), 20 (mips) */
+#ifdef SIGPWR
+ { "PWR", SIGPWR }, /* 30 (arm,i386,m68k,ppc), 29 (alpha,sparc*), 19 (mips) */
#endif
#ifdef SIGUNUSED
{ "UNUSED", SIGUNUSED }, /* 31 (arm,i386,m68k,ppc) */
#endif
+#ifdef SIGSYS
+ { "SYS", SIGSYS }, /* 31 (mips,alpha,sparc*) */
+#endif
};
static int arg_to_signum (char *arg, int mask);
static void nosig (char *name);
static void printsig (int sig);
-static void printsignals (FILE *fp);
+static void printsignals (FILE *fp, int pretty);
static int usage (int status);
static int kill_verbose (char *procname, int pid, int sig);
}
if (! strcmp (arg, "-l") || ! strcmp (arg, "--list")) {
if (argc < 2) {
- printsignals (stdout);
+ printsignals (stdout, 0);
return EXIT_SUCCESS;
}
if (argc > 2) {
printsig (numsig);
return EXIT_SUCCESS;
}
+ if (! strcmp (arg, "-L") || ! strcmp (arg, "--table")) {
+ printsignals (stdout, 1);
+ return EXIT_SUCCESS;
+ }
if (! strcmp (arg, "-p") || ! strcmp (arg, "--pid")) {
do_pid++;
if (do_kill)
static void nosig (char *name)
{
warnx (_("unknown signal %s; valid signals:"), name);
- printsignals (stderr);
+ printsignals (stderr, 1);
}
static void printsig (int sig)
printf("%d\n", sig);
}
-static void printsignals (FILE *fp)
+#define FIELD_WIDTH 11
+static void pretty_print_signal(FILE *fp, size_t term_width, size_t *lpos,
+ int signum, const char *name)
{
- size_t n, lth, lpos = 0;
-
- for (n = 0; n < ARRAY_SIZE(sys_signame); n++) {
- lth = 1+strlen(sys_signame[n].name);
- if (lpos+lth > 72) {
+ if (term_width < (*lpos + FIELD_WIDTH)) {
fputc ('\n', fp);
- lpos = 0;
- } else if (lpos)
- fputc (' ', fp);
- lpos += lth;
- fputs (sys_signame[n].name, fp);
+ *lpos = 0;
+ }
+ *lpos += FIELD_WIDTH;
+ fprintf (fp, "%2d %-8s", signum, name);
+}
+
+static void printsignals (FILE *fp, int pretty)
+{
+ size_t n, lth, lpos = 0, width;
+
+ if (!pretty) {
+ for (n = 0; n < ARRAY_SIZE(sys_signame); n++) {
+ lth = 1+strlen(sys_signame[n].name);
+ if (lpos+lth > 72) {
+ fputc ('\n', fp);
+ lpos = 0;
+ } else if (lpos)
+ fputc (' ', fp);
+ lpos += lth;
+ fputs (sys_signame[n].name, fp);
+ }
+#ifdef SIGRTMIN
+ fputs (" RT<N> RTMIN+<N> RTMAX-<N>", fp);
+#endif
+ fputc ('\n', fp);
+ return;
}
+ /* pretty print */
+ width = get_terminal_width();
+ if (width == 0)
+ width = 72;
+ else
+ width -= 1;
+
+ for (n = 0; n < ARRAY_SIZE(sys_signame); n++)
+ pretty_print_signal(fp, width, &lpos,
+ sys_signame[n].val, sys_signame[n].name);
+
#ifdef SIGRTMIN
- fputs (" RT<N> RTMIN+<N> RTMAX-<N>", fp);
+ pretty_print_signal(fp, width, &lpos, SIGRTMIN, "RTMIN");
+ pretty_print_signal(fp, width, &lpos, SIGRTMAX, "RTMAX");
#endif
fputc ('\n', fp);
}
fputs(_(" -q, --queue <sig> use sigqueue(2) rather than kill(2)\n"), out);
fputs(_(" -p, --pid print pids without signaling them\n"), out);
fputs(_(" -l, --list <name> list signal names\n"), out);
+ fputs(_(" -L, --table list signal names and numbers\n"), out);
fputs(USAGE_SEPARATOR, out);
fputs(USAGE_HELP, out);
fputs(USAGE_VERSION, out);