Hi,

> However, pgrep/pkill does not take a
> parameter to list how to use the command, so usage() should always
> exit with EXIT_USAGE.

in fact, there *is* such a command line parameter: pgrep -?. The problem
here is that the arbitrarily chosen "-?" and the behaviour of getopt(3)
upon encountering unknown commandline parameters overlap.

The "case '?'" is reached in both cases - having explicitly specified -?
or some other invalid character. However, getopt(3) sets optopt to the
character that it actually found in the input in case of an error, so
that's how we can make a decision. The exit(2) call in usage() never
needed a change.

New patch attached.


Regards,

Jan
#! /bin/sh /usr/share/dpatch/dpatch-run
## 55_pgrep_usage_exitcode.dpatch by  <[EMAIL PROTECTED]>
##
## DP: Distinguish between invalid commandline parameters and '-?'.

@DPATCH@
--- procps-3.2.7.orig/pgrep.c   2007-08-06 16:35:30.000000000 +0200
+++ procps-3.2.7/pgrep.c        2007-08-06 16:35:06.000000000 +0200
@@ -678,7 +678,7 @@
 //             case 'z':   // Solaris: match by zone ID
 //                     break;
                case '?':
-                       usage (opt);
+                       usage (optopt?optopt:opt);
                        break;
                }
        }

Attachment: signature.asc
Description: Digital signature

Reply via email to