Cygwin: kill(1): Align list options to latest Linux kill(1)

- Don't print all RT signals, just the allowed patterns
- Add -L/--table option to print a table of signals with signal
  numbers

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2023-03-15 21:59:04 +01:00
parent 3dfb3217af
commit 915c6eb026
1 changed files with 91 additions and 14 deletions

View File

@ -26,24 +26,26 @@ static struct option longopts[] =
{"list", optional_argument, NULL, 'l'},
{"force", no_argument, NULL, 'f'},
{"signal", required_argument, NULL, 's'},
{"table", no_argument, NULL, 'L'},
{"winpid", no_argument, NULL, 'W'},
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0}
};
static char opts[] = "hl::fs:WV";
static char opts[] = "hl::fs:LWV";
static void __attribute__ ((__noreturn__))
usage (FILE *where = stderr)
{
fprintf (where , ""
"Usage: %1$s [-fW] [-signal] [-s signal] pid1 [pid2 ...]\n"
" %1$s -l [signal]\n"
" %1$s -l [signal] | -L\n"
"\n"
"Send signals to processes\n"
"\n"
" -f, --force force, using win32 interface if necessary\n"
" -l, --list print a list of signal names\n"
" -L, --table print a formatted table of signal names\n"
" -s, --signal send signal (use %1$s --list for a list)\n"
" -W, --winpid specified pids are windows PIDs, not Cygwin PIDs\n"
" (use with extreme caution!)\n"
@ -153,21 +155,90 @@ test_for_unknown_sig (int sig, const char *sigstr)
}
static void
listsig (const char *in_sig)
checksig (const char *in_sig)
{
int sig;
if (!in_sig)
for (sig = 1; sig < NSIG - 1; sig++)
printf ("%s%c", strsigno (sig) + 3, (sig < NSIG - 1) ? ' ' : '\n');
int sig = getsig (in_sig);
test_for_unknown_sig (sig, in_sig);
if (sig && atoi (in_sig) == sig)
puts (strsigno (sig) + 3);
else
printf ("%d\n", sig);
exit (0);
}
static void
listsig ()
{
int chars = 0;
for (int sig = 1; sig < SIGRTMIN; sig++)
{
sig = getsig (in_sig);
test_for_unknown_sig (sig, in_sig);
if (sig && atoi (in_sig) == sig)
puts (strsigno (sig) + 3);
else
printf ("%d\n", sig);
chars += printf ("%s ", strsigno (sig) + 3);
if (chars > 72)
{
puts ("");
chars = 0;
}
switch (sig)
{
case SIGABRT:
chars += printf ("%s ", "IOT");
break;
case SIGCHLD:
chars += printf ("%s ", "CLD");
break;
case SIGIO:
chars += printf ("%s ", "POLL");
break;
case SIGPWR:
chars += printf ("%s ", "LOST");
break;
}
if (chars > 70)
{
puts ("");
chars = 0;
}
}
fputs ("RT<N> RTMIN+<N> RTMAX-<N>\n", stdout);
exit (0);
}
static void
tablesig ()
{
int chars = 0;
for (int sig = 1; sig < SIGRTMIN; sig++)
{
chars += printf ("%2d %-7s ", sig, strsigno (sig) + 3);
if (chars > 70)
{
puts ("");
chars = 0;
}
switch (sig)
{
case SIGABRT:
chars += printf ("%2d %-7s ", sig, "IOT");
break;
case SIGCHLD:
chars += printf ("%2d %-7s ", sig, "CLD");
break;
case SIGIO:
chars += printf ("%2d %-7s ", sig, "POLL");
break;
case SIGPWR:
chars += printf ("%2d %-7s ", sig, "LOST");
break;
}
if (chars > 70)
{
puts ("");
chars = 0;
}
}
fputs ("32 RTMIN 64 RTMAX\n", stdout);
exit (0);
}
@ -278,7 +349,13 @@ main (int argc, char **argv)
}
if (argv[optind])
usage ();
listsig (optarg);
if (optarg)
checksig (optarg);
else
listsig ();
break;
case 'L':
tablesig ();
break;
case 'f':
force = 1;