public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/main] Cygwin: kill(1): Align list options to latest Linux kill(1)
@ 2023-03-15 21:10 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2023-03-15 21:10 UTC (permalink / raw)
  To: cygwin-cvs

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=915c6eb0266bf1e1b2b1a1c0a1f075ef6c364537

commit 915c6eb0266bf1e1b2b1a1c0a1f075ef6c364537
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Wed Mar 15 21:59:04 2023 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Mar 15 22:08:04 2023 +0100

    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>

Diff:
---
 winsup/utils/kill.cc | 105 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 91 insertions(+), 14 deletions(-)

diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc
index a430b353720b..fb45e4c9dcfa 100644
--- a/winsup/utils/kill.cc
+++ b/winsup/utils/kill.cc
@@ -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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-15 21:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-15 21:10 [newlib-cygwin/main] Cygwin: kill(1): Align list options to latest Linux kill(1) Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).