]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
prlimit: use exclusive_option()
authorSami Kerola <kerolasa@iki.fi>
Fri, 15 Jun 2012 21:40:49 +0000 (23:40 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sun, 17 Jun 2012 15:59:59 +0000 (17:59 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/prlimit.c

index 58e189c1f220d4945a2c3950ab4ca0634c2dd336..cd9a96c623e7f800781021cb0c79a6bf14390970 100644 (file)
@@ -34,6 +34,7 @@
 #include "strutils.h"
 #include "list.h"
 #include "closestream.h"
+#include "optutils.h"
 
 #ifndef RLIMIT_RTTIME
 # define RLIMIT_RTTIME 15
@@ -483,6 +484,12 @@ int main(int argc, char **argv)
                RAW_OPTION,
                NOHEADINGS_OPTION
        };
+       enum {
+               EXCL_NONE,
+               EXCL_COMMAND,
+               EXCL_PID
+       };
+       int excl_pcom = EXCL_NONE;
 
        static const struct option longopts[] = {
                { "pid",        required_argument, NULL, 'p' },
@@ -578,9 +585,7 @@ int main(int argc, char **argv)
                        break;
 
                case 'p':
-                       if (pid) /* we only work one pid at a time */
-                               errx(EXIT_FAILURE, _("only use one PID at a time"));
-
+                       exclusive_option(&excl_pcom, EXCL_PID + optind, _("--pid and --pid"));
                        pid = strtos32_or_err(optarg, _("invalid PID argument"));
                        break;
                case 'h':
@@ -611,9 +616,8 @@ int main(int argc, char **argv)
                }
        }
        if (argc > optind && pid)
-               errx(EXIT_FAILURE,
-                       _("--pid option and COMMAND are mutually exclusive"));
-
+               exclusive_option(&excl_pcom, EXCL_COMMAND,
+                                _("--pid and COMMAND"));
        if (!ncolumns) {
                /* default columns */
                columns[ncolumns++] = COL_RES;