summaryrefslogtreecommitdiff
path: root/usr/src/cmd
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2012-09-05 22:15:06 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2012-09-05 22:15:06 +0000
commit6d3ed4f3519d4776784e74ab84d9b0661d67f0ca (patch)
treeb5199a07ed244924a63e8f4edb2e54b3a6e36b58 /usr/src/cmd
parent68ecce0663a66abcf57fc279a66f98bbf6e8ab01 (diff)
downloadillumos-joyent-6d3ed4f3519d4776784e74ab84d9b0661d67f0ca.tar.gz
OS-1519 prstat -n option should accept 0
reviewed by Robert Mustacchi
Diffstat (limited to 'usr/src/cmd')
-rw-r--r--usr/src/cmd/prstat/prsort.c15
-rw-r--r--usr/src/cmd/prstat/prstat.c14
2 files changed, 21 insertions, 8 deletions
diff --git a/usr/src/cmd/prstat/prsort.c b/usr/src/cmd/prstat/prsort.c
index cf7c250fe1..39ea28d893 100644
--- a/usr/src/cmd/prstat/prsort.c
+++ b/usr/src/cmd/prstat/prsort.c
@@ -22,10 +22,9 @@
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ * Copyright 2012 Joyent, Inc. All rights reserved.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <libintl.h>
#include <stdlib.h>
#include <string.h>
@@ -38,10 +37,11 @@
void
list_alloc(list_t *list, int size)
{
- if (size > 0) {
- list->l_size = size;
+ list->l_size = size;
+ if (size > 0)
list->l_ptrs = Zalloc(sizeof (void *) * (size + 1));
- }
+ else
+ list->l_ptrs = NULL;
}
void
@@ -208,8 +208,11 @@ list_preinsert(list_t *list, void *ptr)
void
list_sort(list_t *list)
{
- (void) memset(list->l_ptrs, 0, sizeof (void *) * list->l_size);
list->l_used = 0;
+ if (list->l_size == 0)
+ return;
+
+ (void) memset(list->l_ptrs, 0, sizeof (void *) * list->l_size);
if (list->l_type == LT_LWPS) {
lwp_info_t *lwp = list->l_head;
diff --git a/usr/src/cmd/prstat/prstat.c b/usr/src/cmd/prstat/prstat.c
index ae02ee9cf8..e14538a57e 100644
--- a/usr/src/cmd/prstat/prstat.c
+++ b/usr/src/cmd/prstat/prstat.c
@@ -367,6 +367,9 @@ list_print(list_t *list)
double loadavg[3] = {0, 0, 0};
int i, lwpid;
+ if (list->l_size == 0)
+ return;
+
if (foreach_element(&set_tbl, &loadavg, psetloadavg) == 0) {
/*
* If processor sets aren't specified, we display system-wide
@@ -1150,7 +1153,10 @@ setmovecur()
return;
}
if (opts.o_outpmode & OPT_SPLIT) {
- n = opts.o_ntop + opts.o_nbottom + 2;
+ if (opts.o_ntop == 0)
+ n = opts.o_nbottom + 1;
+ else
+ n = opts.o_ntop + opts.o_nbottom + 2;
} else {
if (opts.o_outpmode & OPT_USERS)
n = opts.o_nbottom + 1;
@@ -1424,6 +1430,8 @@ main(int argc, char **argv)
opts.o_ntop = Atoi(p);
if (p = strtok(NULL, ","))
opts.o_nbottom = Atoi(p);
+ else if (opts.o_ntop == 0)
+ opts.o_nbottom = 5;
opts.o_outpmode &= ~OPT_FULLSCREEN;
break;
case 's':
@@ -1489,7 +1497,9 @@ main(int argc, char **argv)
if ((opts.o_outpmode & OPT_USERS) &&
!(opts.o_outpmode & OPT_SPLIT))
opts.o_nbottom = opts.o_ntop;
- if (opts.o_ntop == 0 || opts.o_nbottom == 0)
+ if (!(opts.o_outpmode & OPT_SPLIT) && opts.o_ntop == 0)
+ Die(gettext("invalid argument for -n\n"));
+ if (opts.o_nbottom == 0)
Die(gettext("invalid argument for -n\n"));
if (!(opts.o_outpmode & OPT_SPLIT) && (opts.o_outpmode & OPT_USERS) &&
((opts.o_outpmode & (OPT_PSINFO | OPT_MSACCT))))