- use bb_msg_write_error in 3 places

- whitespace
This commit is contained in:
Bernhard Reutner-Fischer 2006-06-03 20:09:02 +00:00
parent c89982dcd7
commit b1312c9125

View File

@ -1,21 +1,9 @@
/* vi: set sw=4 ts=4: */
/* `time' utility to display resource usage of processes. /* `time' utility to display resource usage of processes.
Copyright (C) 1990, 91, 92, 93, 96 Free Software Foundation, Inc. Copyright (C) 1990, 91, 92, 93, 96 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
it under the terms of the GNU General Public License as published by */
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/* Originally written by David Keppel <pardo@cs.washington.edu>. /* Originally written by David Keppel <pardo@cs.washington.edu>.
Heavily modified by David MacKenzie <djm@gnu.ai.mit.edu>. Heavily modified by David MacKenzie <djm@gnu.ai.mit.edu>.
Heavily modified for busybox by Erik Andersen <andersen@codepoet.org> Heavily modified for busybox by Erik Andersen <andersen@codepoet.org>
@ -38,8 +26,7 @@
#include <sys/resource.h> #include <sys/resource.h>
/* Information on the resources used by a child process. */ /* Information on the resources used by a child process. */
typedef struct typedef struct {
{
int waitstatus; int waitstatus;
struct rusage ru; struct rusage ru;
struct timeval start, elapsed; /* Wallclock time of process. */ struct timeval start, elapsed; /* Wallclock time of process. */
@ -90,8 +77,7 @@ static const char *const long_format =
"\tSocket messages sent: %s\n" "\tSocket messages sent: %s\n"
"\tSocket messages received: %r\n" "\tSocket messages received: %r\n"
"\tSignals delivered: %k\n" "\tSignals delivered: %k\n"
"\tPage size (bytes): %Z\n" "\tPage size (bytes): %Z\n" "\tExit status: %x";
"\tExit status: %x";
/* Wait for and fill in data on child process PID. /* Wait for and fill in data on child process PID.
@ -106,16 +92,14 @@ static int resuse_end (pid_t pid, resource_t *resp)
/* Ignore signals, but don't ignore the children. When wait3 /* Ignore signals, but don't ignore the children. When wait3
returns the child process, set the time the command finished. */ returns the child process, set the time the command finished. */
while ((caught = wait3 (&status, 0, &resp->ru)) != pid) while ((caught = wait3(&status, 0, &resp->ru)) != pid) {
{
if (caught == -1) if (caught == -1)
return 0; return 0;
} }
gettimeofday(&resp->elapsed, (struct timezone *) 0); gettimeofday(&resp->elapsed, (struct timezone *) 0);
resp->elapsed.tv_sec -= resp->start.tv_sec; resp->elapsed.tv_sec -= resp->start.tv_sec;
if (resp->elapsed.tv_usec < resp->start.tv_usec) if (resp->elapsed.tv_usec < resp->start.tv_usec) {
{
/* Manually carry a one from the seconds field. */ /* Manually carry a one from the seconds field. */
resp->elapsed.tv_usec += 1000000; resp->elapsed.tv_usec += 1000000;
--resp->elapsed.tv_sec; --resp->elapsed.tv_sec;
@ -134,13 +118,12 @@ static void fprintargv (FILE *fp, char *const *argv, const char *filler)
av = argv; av = argv;
fputs(*av, fp); fputs(*av, fp);
while (*++av) while (*++av) {
{
fputs(filler, fp); fputs(filler, fp);
fputs(*av, fp); fputs(*av, fp);
} }
if (ferror(fp)) if (ferror(fp))
bb_error_msg_and_die("write error"); bb_error_msg_and_die(bb_msg_write_error);
} }
/* Return the number of kilobytes corresponding to a number of pages PAGES. /* Return the number of kilobytes corresponding to a number of pages PAGES.
@ -162,13 +145,10 @@ static unsigned long ptok (unsigned long pages)
ps = (long) getpagesize(); ps = (long) getpagesize();
/* Conversion. */ /* Conversion. */
if (pages > (LONG_MAX / ps)) if (pages > (LONG_MAX / ps)) { /* Could overflow. */
{ /* Could overflow. */
tmp = pages / 1024; /* Smaller first, */ tmp = pages / 1024; /* Smaller first, */
size = tmp * ps; /* then larger. */ size = tmp * ps; /* then larger. */
} } else { /* Could underflow. */
else
{ /* Could underflow. */
tmp = pages * ps; /* Larger first, */ tmp = pages * ps; /* Larger first, */
size = tmp / 1024; /* then smaller. */ size = tmp / 1024; /* then smaller. */
} }
@ -220,17 +200,21 @@ static unsigned long ptok (unsigned long pages)
COMMAND is the command and args that are being summarized. COMMAND is the command and args that are being summarized.
RESP is resource information on the command. */ RESP is resource information on the command. */
static void summarize (FILE *fp, const char *fmt, char **command, resource_t *resp) static void summarize(FILE * fp, const char *fmt, char **command,
resource_t * resp)
{ {
unsigned long r; /* Elapsed real milliseconds. */ unsigned long r; /* Elapsed real milliseconds. */
unsigned long v; /* Elapsed virtual (CPU) milliseconds. */ unsigned long v; /* Elapsed virtual (CPU) milliseconds. */
if (WIFSTOPPED(resp->waitstatus)) if (WIFSTOPPED(resp->waitstatus))
fprintf (fp, "Command stopped by signal %d\n", WSTOPSIG (resp->waitstatus)); fprintf(fp, "Command stopped by signal %d\n",
WSTOPSIG(resp->waitstatus));
else if (WIFSIGNALED(resp->waitstatus)) else if (WIFSIGNALED(resp->waitstatus))
fprintf (fp, "Command terminated by signal %d\n", WTERMSIG (resp->waitstatus)); fprintf(fp, "Command terminated by signal %d\n",
WTERMSIG(resp->waitstatus));
else if (WIFEXITED(resp->waitstatus) && WEXITSTATUS(resp->waitstatus)) else if (WIFEXITED(resp->waitstatus) && WEXITSTATUS(resp->waitstatus))
fprintf (fp, "Command exited with non-zero status %d\n", WEXITSTATUS (resp->waitstatus)); fprintf(fp, "Command exited with non-zero status %d\n",
WEXITSTATUS(resp->waitstatus));
/* Convert all times to milliseconds. Occasionally, one of these values /* Convert all times to milliseconds. Occasionally, one of these values
comes out as zero. Dividing by zero causes problems, so we first comes out as zero. Dividing by zero causes problems, so we first
@ -242,13 +226,10 @@ static void summarize (FILE *fp, const char *fmt, char **command, resource_t *re
v = resp->ru.ru_utime.tv_sec * 1000 + resp->ru.ru_utime.TV_MSEC + v = resp->ru.ru_utime.tv_sec * 1000 + resp->ru.ru_utime.TV_MSEC +
resp->ru.ru_stime.tv_sec * 1000 + resp->ru.ru_stime.TV_MSEC; resp->ru.ru_stime.tv_sec * 1000 + resp->ru.ru_stime.TV_MSEC;
while (*fmt) while (*fmt) {
{ switch (*fmt) {
switch (*fmt)
{
case '%': case '%':
switch (*++fmt) switch (*++fmt) {
{
case '%': /* Literal '%'. */ case '%': /* Literal '%'. */
putc('%', fp); putc('%', fp);
break; break;
@ -352,8 +333,7 @@ static void summarize (FILE *fp, const char *fmt, char **command, resource_t *re
break; break;
case 'e': /* Elapsed real time in seconds. */ case 'e': /* Elapsed real time in seconds. */
fprintf(fp, "%ld.%02ld", fprintf(fp, "%ld.%02ld",
resp->elapsed.tv_sec, resp->elapsed.tv_sec, resp->elapsed.tv_usec / 10000);
resp->elapsed.tv_usec / 10000);
break; break;
case 'k': /* Signals delivered. */ case 'k': /* Signals delivered. */
fprintf(fp, "%ld", resp->ru.ru_nsignals); fprintf(fp, "%ld", resp->ru.ru_nsignals);
@ -391,8 +371,7 @@ static void summarize (FILE *fp, const char *fmt, char **command, resource_t *re
break; break;
case '\\': /* Format escape. */ case '\\': /* Format escape. */
switch (*++fmt) switch (*++fmt) {
{
case 't': case 't':
putc('\t', fp); putc('\t', fp);
break; break;
@ -415,12 +394,12 @@ static void summarize (FILE *fp, const char *fmt, char **command, resource_t *re
} }
if (ferror(fp)) if (ferror(fp))
bb_error_msg_and_die("write error"); bb_error_msg_and_die(bb_msg_write_error);
} }
putc('\n', fp); putc('\n', fp);
if (ferror(fp)) if (ferror(fp))
bb_error_msg_and_die("write error"); bb_error_msg_and_die(bb_msg_write_error);
} }
/* Run command CMD and return statistics on it. /* Run command CMD and return statistics on it.
@ -434,8 +413,7 @@ static void run_command (char *const *cmd, resource_t *resp)
pid = fork(); /* Run CMD as child process. */ pid = fork(); /* Run CMD as child process. */
if (pid < 0) if (pid < 0)
bb_error_msg_and_die("cannot fork"); bb_error_msg_and_die("cannot fork");
else if (pid == 0) else if (pid == 0) { /* If child. */
{ /* If child. */
/* Don't cast execvp arguments; that causes errors on some systems, /* Don't cast execvp arguments; that causes errors on some systems,
versus merely warnings if the cast is left off. */ versus merely warnings if the cast is left off. */
execvp(cmd[0], cmd); execvp(cmd[0], cmd);