changeset 13691:e1aca0f20bff

2733 pgrep/pkill prints misleading error on missing option argument Reviewed by: Robert Mustacchi <rm@joyent.com> Reviewed by: Dan McDonald <danmcd@nexenta.com> Approved by: Richard Lowe <richlowe@richlowe.net>
author Eric Schrock <Eric.Schrock@delphix.com>
date Mon, 14 May 2012 12:05:00 -0700
parents db7ab359c5d7
children 05fa76d16740
files usr/src/cmd/pgrep/pgrep.c
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/pgrep/pgrep.c	Fri May 11 22:59:24 2012 +0100
+++ b/usr/src/cmd/pgrep/pgrep.c	Mon May 14 12:05:00 2012 -0700
@@ -22,8 +22,7 @@
  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
-
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
+/* Copyright (c) 2012 by Delphix. All rights reserved */
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -164,8 +163,8 @@
 	[-u euidlist] [-U uidlist] [-G gidlist] [-J projidlist]\n\
 	[-T taskidlist] [-t termlist] [-z zonelist] [-c ctidlist] [pattern]\n";
 
-static const char PGREP_OPTS[] = "flnovxc:d:D:u:U:G:P:g:s:t:z:J:T:";
-static const char PKILL_OPTS[] = "fnovxc:D:u:U:G:P:g:s:t:z:J:T:";
+static const char PGREP_OPTS[] = ":flnovxc:d:D:u:U:G:P:g:s:t:z:J:T:";
+static const char PKILL_OPTS[] = ":fnovxc:D:u:U:G:P:g:s:t:z:J:T:";
 
 static const char LSEP[] = ",\t ";	/* Argument list delimiter chars */
 
@@ -630,8 +629,13 @@
 	while (optind < argc) {
 		while ((c = getopt(argc, argv, optstr)) != (int)EOF) {
 
-			if (c == '?' || g_optdtab[c - 'A'].o_opts == 0) {
-				if (optopt != '?') {
+			if (c == ':' || c == '?' ||
+			    g_optdtab[c - 'A'].o_opts == 0) {
+				if (c == ':') {
+					uu_warn(
+					    gettext("missing argument -- %c\n"),
+					    optopt);
+				} else if (optopt != '?') {
 					uu_warn(
 					    gettext("illegal option -- %c\n"),
 					    optopt);