- use bb_msg_write_error in 3 places
- whitespace
This commit is contained in:
@@ -1,21 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* `time' utility to display resource usage of processes.
|
||||
Copyright (C) 1990, 91, 92, 93, 96 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
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. */
|
||||
|
||||
Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
/* Originally written by David Keppel <pardo@cs.washington.edu>.
|
||||
Heavily modified by David MacKenzie <djm@gnu.ai.mit.edu>.
|
||||
Heavily modified for busybox by Erik Andersen <andersen@codepoet.org>
|
||||
@@ -38,8 +26,7 @@
|
||||
#include <sys/resource.h>
|
||||
|
||||
/* Information on the resources used by a child process. */
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
int waitstatus;
|
||||
struct rusage ru;
|
||||
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 received: %r\n"
|
||||
"\tSignals delivered: %k\n"
|
||||
"\tPage size (bytes): %Z\n"
|
||||
"\tExit status: %x";
|
||||
"\tPage size (bytes): %Z\n" "\tExit status: %x";
|
||||
|
||||
|
||||
/* 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
|
||||
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)
|
||||
return 0;
|
||||
}
|
||||
|
||||
gettimeofday(&resp->elapsed, (struct timezone *) 0);
|
||||
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. */
|
||||
resp->elapsed.tv_usec += 1000000;
|
||||
--resp->elapsed.tv_sec;
|
||||
@@ -134,13 +118,12 @@ static void fprintargv (FILE *fp, char *const *argv, const char *filler)
|
||||
|
||||
av = argv;
|
||||
fputs(*av, fp);
|
||||
while (*++av)
|
||||
{
|
||||
while (*++av) {
|
||||
fputs(filler, fp);
|
||||
fputs(*av, 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.
|
||||
@@ -162,13 +145,10 @@ static unsigned long ptok (unsigned long pages)
|
||||
ps = (long) getpagesize();
|
||||
|
||||
/* Conversion. */
|
||||
if (pages > (LONG_MAX / ps))
|
||||
{ /* Could overflow. */
|
||||
if (pages > (LONG_MAX / ps)) { /* Could overflow. */
|
||||
tmp = pages / 1024; /* Smaller first, */
|
||||
size = tmp * ps; /* then larger. */
|
||||
}
|
||||
else
|
||||
{ /* Could underflow. */
|
||||
} else { /* Could underflow. */
|
||||
tmp = pages * ps; /* Larger first, */
|
||||
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.
|
||||
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 v; /* Elapsed virtual (CPU) milliseconds. */
|
||||
|
||||
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))
|
||||
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))
|
||||
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
|
||||
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 +
|
||||
resp->ru.ru_stime.tv_sec * 1000 + resp->ru.ru_stime.TV_MSEC;
|
||||
|
||||
while (*fmt)
|
||||
{
|
||||
switch (*fmt)
|
||||
{
|
||||
while (*fmt) {
|
||||
switch (*fmt) {
|
||||
case '%':
|
||||
switch (*++fmt)
|
||||
{
|
||||
switch (*++fmt) {
|
||||
case '%': /* Literal '%'. */
|
||||
putc('%', fp);
|
||||
break;
|
||||
@@ -352,8 +333,7 @@ static void summarize (FILE *fp, const char *fmt, char **command, resource_t *re
|
||||
break;
|
||||
case 'e': /* Elapsed real time in seconds. */
|
||||
fprintf(fp, "%ld.%02ld",
|
||||
resp->elapsed.tv_sec,
|
||||
resp->elapsed.tv_usec / 10000);
|
||||
resp->elapsed.tv_sec, resp->elapsed.tv_usec / 10000);
|
||||
break;
|
||||
case 'k': /* Signals delivered. */
|
||||
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;
|
||||
|
||||
case '\\': /* Format escape. */
|
||||
switch (*++fmt)
|
||||
{
|
||||
switch (*++fmt) {
|
||||
case 't':
|
||||
putc('\t', fp);
|
||||
break;
|
||||
@@ -415,12 +394,12 @@ static void summarize (FILE *fp, const char *fmt, char **command, resource_t *re
|
||||
}
|
||||
|
||||
if (ferror(fp))
|
||||
bb_error_msg_and_die("write error");
|
||||
bb_error_msg_and_die(bb_msg_write_error);
|
||||
}
|
||||
putc('\n', 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.
|
||||
@@ -434,8 +413,7 @@ static void run_command (char *const *cmd, resource_t *resp)
|
||||
pid = fork(); /* Run CMD as child process. */
|
||||
if (pid < 0)
|
||||
bb_error_msg_and_die("cannot fork");
|
||||
else if (pid == 0)
|
||||
{ /* If child. */
|
||||
else if (pid == 0) { /* If child. */
|
||||
/* Don't cast execvp arguments; that causes errors on some systems,
|
||||
versus merely warnings if the cast is left off. */
|
||||
execvp(cmd[0], cmd);
|
||||
|
Reference in New Issue
Block a user