aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/top/top.c
diff options
context:
space:
mode:
authorEitan Adler <eadler@FreeBSD.org>2018-08-22 10:07:15 +0000
committerEitan Adler <eadler@FreeBSD.org>2018-08-22 10:07:15 +0000
commit17be5f230a5fbca04c2e17de4cf554f0656a00b1 (patch)
tree158e901143ba74f5950cd5216e51320474edb706 /usr.bin/top/top.c
parent45a3e13ca81b685fa8b2996d83a6fbbbcba6d8be (diff)
downloadsrc-17be5f230a5fbca04c2e17de4cf554f0656a00b1.tar.gz
src-17be5f230a5fbca04c2e17de4cf554f0656a00b1.zip
top(1): Use warnx and errx instead of fprintf
This also makes make "-v" exit without error, since it isn't.
Notes
Notes: svn path=/head/; revision=338189
Diffstat (limited to 'usr.bin/top/top.c')
-rw-r--r--usr.bin/top/top.c64
1 files changed, 16 insertions, 48 deletions
diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c
index b76dbb54676d..2279479409b1 100644
--- a/usr.bin/top/top.c
+++ b/usr.bin/top/top.c
@@ -68,7 +68,6 @@ static int max_topn; /* maximum displayable processes */
/* miscellaneous things */
struct process_select ps;
-const char * myname = "top";
pid_t mypid;
/* pointers to display routines */
@@ -265,18 +264,6 @@ main(int argc, char *argv[])
setbuffer(stdout, stdoutbuf, Buffersize);
#endif
- if (argc > 0)
- {
- if ((myname = strrchr(argv[0], '/')) == 0)
- {
- myname = argv[0];
- }
- else
- {
- myname++;
- }
- }
-
mypid = getpid();
/* get our name */
@@ -323,9 +310,8 @@ main(int argc, char *argv[])
switch(i)
{
case 'v': /* show version number */
- fprintf(stderr, "%s: version FreeBSD\n", myname);
- exit(1);
- break;
+ errx(0, "version FreeBSD");
+ break;
case 'u': /* toggle uid/username display */
do_unames = !do_unames;
@@ -334,8 +320,7 @@ main(int argc, char *argv[])
case 'U': /* display only username's processes */
if ((ps.uid[0] = userid(optarg)) == -1)
{
- fprintf(stderr, "%s: unknown user\n", optarg);
- exit(1);
+ errx(1, "%s: unknown user\n", optarg);
}
break;
@@ -363,9 +348,7 @@ main(int argc, char *argv[])
case 'd': /* number of displays to show */
if ((i = atoiwi(optarg)) == Invalid || i == 0)
{
- fprintf(stderr,
- "%s: warning: display count should be positive -- option ignored\n",
- myname);
+ warnx("warning: display count should be positive -- option ignored");
warnings++;
}
else
@@ -395,9 +378,7 @@ main(int argc, char *argv[])
warnings++;
}
if (delay < 0) {
- fprintf(stderr,
- "%s: warning: seconds delay should be positive -- using default\n",
- myname);
+ warnx("warning: seconds delay should be positive -- using default");
delay = 2;
warnings++;
}
@@ -408,8 +389,7 @@ main(int argc, char *argv[])
errno = 0;
i = setpriority(PRIO_PROCESS, 0, PRIO_MIN);
if (i == -1 && errno != 0) {
- fprintf(stderr,
- "%s: warning: `-q' option failed (%m)\n", myname);
+ warnx("warning: `-q' option failed (%m)");
warnings++;
}
break;
@@ -420,11 +400,7 @@ main(int argc, char *argv[])
} else if (strcmp(optarg, "cpu") == 0) {
displaymode = DISP_CPU;
} else {
- fprintf(stderr,
- "%s: warning: `-m' option can only take args "
- "'io' or 'cpu'\n",
- myname);
- exit(1);
+ errx(1, "warning: `-m' option can only take args 'io' or 'cpu'");
}
break;
@@ -474,11 +450,9 @@ main(int argc, char *argv[])
break;
default:
- fprintf(stderr,
-"Usage: %s [-abCHIijnPqStuvwz] [-d count] [-m io | cpu] [-o field] [-p pid]\n"
-" [-s time] [-J jail] [-U username] [number]\n",
- myname);
- exit(1);
+ errx(1,
+"[-abCHIijnPqStuvwz] [-d count] [-m io | cpu] [-o field] [-p pid]\n"
+" [-s time] [-J jail] [-U username] [number]");
}
}
@@ -487,10 +461,8 @@ main(int argc, char *argv[])
{
if ((topn = atoiwi(av[optind])) == Invalid)
{
- fprintf(stderr,
- "%s: warning: process display count should be non-negative -- using default\n",
- myname);
- warnings++;
+ warnx("warning: process display count should be non-negative -- using default");
+ warnings++;
}
else
{
@@ -525,8 +497,7 @@ main(int argc, char *argv[])
{
const char * const *pp;
- fprintf(stderr, "%s: '%s' is not a recognized sorting order.\n",
- myname, order_name);
+ warnx("'%s' is not a recognized sorting order.", order_name);
fprintf(stderr, "\tTry one of these:");
pp = statics.order_names;
while (*pp != NULL)
@@ -547,17 +518,14 @@ main(int argc, char *argv[])
/* initialize display interface */
if ((max_topn = display_init(&statics)) == -1)
{
- fprintf(stderr, "%s: can't allocate sufficient memory\n", myname);
- exit(4);
+ errx(4, "can't allocate sufficient memory");
}
/* print warning if user requested more processes than we can display */
if (topn > max_topn)
{
- fprintf(stderr,
- "%s: warning: this terminal can only display %d processes.\n",
- myname, max_topn);
- warnings++;
+ warnx("warning: this terminal can only display %d processes.", max_topn);
+ warnings++;
}
/* adjust for topn == Infinity */