On 09/12/2025 10:16, Corinna Vinschen wrote:
On Dec  6 11:56, Jon Turney wrote:
On 05/12/2025 19:41, Corinna Vinschen wrote:
+         fprintf (stderr, "Usage: %s [-] [group]\n",

Maybe '[-|-l]'?

The usage message is the same as used by the shadow-utils newgrp
on Linux.  It supports -l, but doesn't print it for some reason.

If you think we should do it better, I can change our usage output
and send a v2 patch, no worries.

I am ambivalent.

The most recent SUS text [1] actually redefines the behavior of '-' as "unspecified" so '-l' seems preferred.

(This seems to revolve around standardizing '-' to refer to stdin)

[1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/newgrp.html


+                  program_invocation_short_name);
+         return 1;
+       }
         new_child_env = true;
         --argc;
         ++argv;
@@ -165,8 +165,16 @@ main (int argc, const char **argv)
       }
     else
       {
-      gr = getgrnam (argv[1]);
-      if (!gr)
+      char *eptr;
+
+      if ((gr = getgrnam (argv[1])) != NULL)
+       /*valid*/;
+      else if (isdigit ((int) argv[1][0])
+              && (gid = strtoul (argv[1], &eptr, 10)) != ULONG_MAX
+              && *eptr == '\0'
+              && (gr = getgrgid (gid)) != NULL)

I spent a bit of time worrying how this handled edge cases like '' or '0',
but I think it's all good!

Thanks for checking!

No problem!

Reply via email to