summaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorErik Andersen2000-02-08 19:58:47 +0000
committerErik Andersen2000-02-08 19:58:47 +0000
commite49d5ecbbe51718fa925b6890a735e5937cc2aa2 (patch)
treec90bda10731ad9333ce3b404f993354c9fc104b8 /procps
parentc0bf817bbc5c7867fbe8fb76d5c39f8ee802692f (diff)
downloadbusybox-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.zip
busybox-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.gz
Some formatting updates (ran the code through indent)
-Erik
Diffstat (limited to 'procps')
-rw-r--r--procps/free.c6
-rw-r--r--procps/kill.c299
-rw-r--r--procps/ps.c206
3 files changed, 260 insertions, 251 deletions
diff --git a/procps/free.c b/procps/free.c
index 36d3575..b071354 100644
--- a/procps/free.c
+++ b/procps/free.c
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
/*
* Mini free implementation for busybox
*
@@ -30,6 +31,7 @@
extern int free_main(int argc, char **argv)
{
- char* cmd[] = { "cat", "/proc/meminfo", "\0" };
- exit(cat_main( 3, cmd));
+ char *cmd[] = { "cat", "/proc/meminfo", "\0" };
+
+ exit(cat_main(3, cmd));
}
diff --git a/procps/kill.c b/procps/kill.c
index e72b734..5166212 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
/*
* Mini kill implementation for busybox
*
@@ -29,188 +30,188 @@
#include <sys/stat.h>
#include <unistd.h>
-static const char* kill_usage = "kill [-signal] process-id [process-id ...]\n\n"
-"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
-"Options:\n"
-"\t-l\tList all signal names and numbers.\n\n";
+static const char *kill_usage =
+ "kill [-signal] process-id [process-id ...]\n\n"
+ "Send a signal (default is SIGTERM) to the specified process(es).\n\n"
+ "Options:\n" "\t-l\tList all signal names and numbers.\n\n";
struct signal_name {
- const char *name;
- int number;
+ const char *name;
+ int number;
};
const struct signal_name signames[] = {
- {"HUP", SIGHUP},
- {"INT", SIGINT},
- {"QUIT", SIGQUIT},
- {"ILL", SIGILL},
- {"TRAP", SIGTRAP},
- {"ABRT", SIGABRT},
+ {"HUP", SIGHUP},
+ {"INT", SIGINT},
+ {"QUIT", SIGQUIT},
+ {"ILL", SIGILL},
+ {"TRAP", SIGTRAP},
+ {"ABRT", SIGABRT},
#ifndef __alpha__
- {"IOT", SIGIOT},
+ {"IOT", SIGIOT},
#endif
#if defined(__sparc__) || defined(__alpha__)
- {"EMT", SIGEMT},
+ {"EMT", SIGEMT},
#else
- {"BUS", SIGBUS},
+ {"BUS", SIGBUS},
#endif
- {"FPE", SIGFPE},
- {"KILL", SIGKILL},
+ {"FPE", SIGFPE},
+ {"KILL", SIGKILL},
#if defined(__sparc__) || defined(__alpha__)
- {"BUS", SIGBUS},
+ {"BUS", SIGBUS},
#else
- {"USR1", SIGUSR1},
+ {"USR1", SIGUSR1},
#endif
- {"SEGV", SIGSEGV},
+ {"SEGV", SIGSEGV},
#if defined(__sparc__) || defined(__alpha__)
- {"SYS", SIGSYS},
+ {"SYS", SIGSYS},
#else
- {"USR2", SIGUSR2},
+ {"USR2", SIGUSR2},
#endif
- {"PIPE", SIGPIPE},
- {"ALRM", SIGALRM},
- {"TERM", SIGTERM},
+ {"PIPE", SIGPIPE},
+ {"ALRM", SIGALRM},
+ {"TERM", SIGTERM},
#if defined(__sparc__) || defined(__alpha__)
- {"URG", SIGURG},
- {"STOP", SIGSTOP},
- {"TSTP", SIGTSTP},
- {"CONT", SIGCONT},
- {"CHLD", SIGCHLD},
- {"TTIN", SIGTTIN},
- {"TTOU", SIGTTOU},
- {"IO", SIGIO},
+ {"URG", SIGURG},
+ {"STOP", SIGSTOP},
+ {"TSTP", SIGTSTP},
+ {"CONT", SIGCONT},
+ {"CHLD", SIGCHLD},
+ {"TTIN", SIGTTIN},
+ {"TTOU", SIGTTOU},
+ {"IO", SIGIO},
# ifndef __alpha__
- {"POLL", SIGIO},
+ {"POLL", SIGIO},
# endif
- {"XCPU", SIGXCPU},
- {"XFSZ", SIGXFSZ},
- {"VTALRM", SIGVTALRM},
- {"PROF", SIGPROF},
- {"WINCH", SIGWINCH},
+ {"XCPU", SIGXCPU},
+ {"XFSZ", SIGXFSZ},
+ {"VTALRM", SIGVTALRM},
+ {"PROF", SIGPROF},
+ {"WINCH", SIGWINCH},
# ifdef __alpha__
- {"INFO", SIGINFO},
+ {"INFO", SIGINFO},
# else
- {"LOST", SIGLOST},
+ {"LOST", SIGLOST},
# endif
- {"USR1", SIGUSR1},
- {"USR2", SIGUSR2},
+ {"USR1", SIGUSR1},
+ {"USR2", SIGUSR2},
#else
- {"STKFLT", SIGSTKFLT},
- {"CHLD", SIGCHLD},
- {"CONT", SIGCONT},
- {"STOP", SIGSTOP},
- {"TSTP", SIGTSTP},
- {"TTIN", SIGTTIN},
- {"TTOU", SIGTTOU},
- {"URG", SIGURG},
- {"XCPU", SIGXCPU},
- {"XFSZ", SIGXFSZ},
- {"VTALRM", SIGVTALRM},
- {"PROF", SIGPROF},
- {"WINCH", SIGWINCH},
- {"IO", SIGIO},
- {"POLL", SIGPOLL},
- {"PWR", SIGPWR},
- {"UNUSED", SIGUNUSED},
+ {"STKFLT", SIGSTKFLT},
+ {"CHLD", SIGCHLD},
+ {"CONT", SIGCONT},
+ {"STOP", SIGSTOP},
+ {"TSTP", SIGTSTP},
+ {"TTIN", SIGTTIN},
+ {"TTOU", SIGTTOU},
+ {"URG", SIGURG},
+ {"XCPU", SIGXCPU},
+ {"XFSZ", SIGXFSZ},
+ {"VTALRM", SIGVTALRM},
+ {"PROF", SIGPROF},
+ {"WINCH", SIGWINCH},
+ {"IO", SIGIO},
+ {"POLL", SIGPOLL},
+ {"PWR", SIGPWR},
+ {"UNUSED", SIGUNUSED},
#endif
- {0, 0}
+ {0, 0}
};
-extern int kill_main (int argc, char **argv)
+extern int kill_main(int argc, char **argv)
{
- int sig = SIGTERM;
-
- argc--;
- argv++;
- /* Parse any options */
- if (argc < 1)
- usage(kill_usage);
-
- while (argc > 0 && **argv == '-') {
- while (*++(*argv)) {
- switch (**argv) {
- case 'l':
- {
- int col=0;
- const struct signal_name *s = signames;
-
- while (s->name != 0) {
- col+=fprintf(stderr, "%2d) %-8s", s->number, (s++)->name);
- if (col>60) {
- fprintf(stderr, "\n");
- col=0;
- }
- }
- fprintf(stderr, "\n\n");
- exit( TRUE);
- }
- break;
- case '-':
+ int sig = SIGTERM;
+
+ argc--;
+ argv++;
+ /* Parse any options */
+ if (argc < 1)
usage(kill_usage);
- default:
- {
- if (isdigit( **argv)) {
- sig = atoi (*argv);
- if (sig < 0 || sig >= NSIG)
- goto end;
- else {
- argc--;
- argv++;
- goto do_it_now;
- }
- }
- else {
- const struct signal_name *s = signames;
- while (s->name != 0) {
- if (strcasecmp (s->name, *argv) == 0) {
- sig = s->number;
- argc--;
- argv++;
- goto do_it_now;
- }
- s++;
+
+ while (argc > 0 && **argv == '-') {
+ while (*++(*argv)) {
+ switch (**argv) {
+ case 'l':
+ {
+ int col = 0;
+ const struct signal_name *s = signames;
+
+ while (s->name != 0) {
+ col +=
+ fprintf(stderr, "%2d) %-8s", s->number,
+ (s++)->name);
+ if (col > 60) {
+ fprintf(stderr, "\n");
+ col = 0;
+ }
+ }
+ fprintf(stderr, "\n\n");
+ exit(TRUE);
+ }
+ break;
+ case '-':
+ usage(kill_usage);
+ default:
+ {
+ if (isdigit(**argv)) {
+ sig = atoi(*argv);
+ if (sig < 0 || sig >= NSIG)
+ goto end;
+ else {
+ argc--;
+ argv++;
+ goto do_it_now;
+ }
+ } else {
+ const struct signal_name *s = signames;
+
+ while (s->name != 0) {
+ if (strcasecmp(s->name, *argv) == 0) {
+ sig = s->number;
+ argc--;
+ argv++;
+ goto do_it_now;
+ }
+ s++;
+ }
+ if (s->name == 0)
+ goto end;
+ }
+ }
}
- if (s->name == 0)
- goto end;
- }
+ argc--;
+ argv++;
}
- }
- argc--;
- argv++;
- }
- }
-
-do_it_now:
-
- while (--argc >= 0) {
- int pid;
- struct stat statbuf;
- char pidpath[20]="/proc/";
-
- if (! isdigit( **argv)) {
- fprintf(stderr, "bad PID: %s\n", *argv);
- exit( FALSE);
- }
- pid = atoi (*argv);
- snprintf(pidpath, 20, "/proc/%s/stat", *argv);
- if (stat( pidpath, &statbuf)!=0) {
- fprintf(stderr, "kill: (%d) - No such pid\n", pid);
- exit( FALSE);
}
- fprintf(stderr, "sig = %d\n", sig);
- if (kill (pid, sig) != 0) {
- perror (*argv);
- exit ( FALSE);
- }
- argv++;
- }
- exit ( TRUE);
+ do_it_now:
-end:
- fprintf(stderr, "bad signal name: %s\n", *argv);
- exit (TRUE);
-}
+ while (--argc >= 0) {
+ int pid;
+ struct stat statbuf;
+ char pidpath[20] = "/proc/";
+
+ if (!isdigit(**argv)) {
+ fprintf(stderr, "bad PID: %s\n", *argv);
+ exit(FALSE);
+ }
+ pid = atoi(*argv);
+ snprintf(pidpath, 20, "/proc/%s/stat", *argv);
+ if (stat(pidpath, &statbuf) != 0) {
+ fprintf(stderr, "kill: (%d) - No such pid\n", pid);
+ exit(FALSE);
+ }
+ fprintf(stderr, "sig = %d\n", sig);
+ if (kill(pid, sig) != 0) {
+ perror(*argv);
+ exit(FALSE);
+ }
+ argv++;
+ }
+ exit(TRUE);
+ end:
+ fprintf(stderr, "bad signal name: %s\n", *argv);
+ exit(TRUE);
+}
diff --git a/procps/ps.c b/procps/ps.c
index 4496faa..207cdaa 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
/*
* Mini ps implementation for busybox
*
@@ -33,123 +34,128 @@
#endif
typedef struct proc_s {
- char
- cmd[16]; /* basename of executable file in call to exec(2) */
- int
- ruid, rgid, /* real only (sorry) */
- pid, /* process id */
- ppid; /* pid of parent process */
- char
- state; /* single-char code for process state (S=sleeping) */
+ char
+ cmd[16]; /* basename of executable file in call to exec(2) */
+ int
+ ruid, rgid, /* real only (sorry) */
+ pid, /* process id */
+ ppid; /* pid of parent process */
+ char
+ state; /* single-char code for process state (S=sleeping) */
} proc_t;
-static int file2str(char *filename, char *ret, int cap)
+static int file2str(char *filename, char *ret, int cap)
{
- int fd, num_read;
-
- if ( (fd = open(filename, O_RDONLY, 0)) == -1 ) return -1;
- if ( (num_read = read(fd, ret, cap - 1)) <= 0 ) return -1;
- ret[num_read] = 0;
- close(fd);
- return num_read;
+ int fd, num_read;
+
+ if ((fd = open(filename, O_RDONLY, 0)) == -1)
+ return -1;
+ if ((num_read = read(fd, ret, cap - 1)) <= 0)
+ return -1;
+ ret[num_read] = 0;
+ close(fd);
+ return num_read;
}
-static void parse_proc_status(char* S, proc_t* P)
+static void parse_proc_status(char *S, proc_t * P)
{
- char* tmp;
- memset(P->cmd, 0, sizeof P->cmd);
- sscanf (S, "Name:\t%15c", P->cmd);
- tmp = strchr(P->cmd,'\n');
- if (tmp)
- *tmp='\0';
- tmp = strstr (S,"State");
- sscanf (tmp, "State:\t%c", &P->state);
-
- tmp = strstr (S,"Pid:");
- if(tmp) sscanf (tmp,
- "Pid:\t%d\n"
- "PPid:\t%d\n",
- &P->pid,
- &P->ppid
- );
- else fprintf(stderr, "Internal error!\n");
-
- /* For busybox, ignoring effective, saved, etc */
- tmp = strstr (S,"Uid:");
- if(tmp) sscanf (tmp,
- "Uid:\t%d", &P->ruid);
- else fprintf(stderr, "Internal error!\n");
-
- tmp = strstr (S,"Gid:");
- if(tmp) sscanf (tmp,
- "Gid:\t%d", &P->rgid);
- else fprintf(stderr, "Internal error!\n");
+ char *tmp;
+
+ memset(P->cmd, 0, sizeof P->cmd);
+ sscanf(S, "Name:\t%15c", P->cmd);
+ tmp = strchr(P->cmd, '\n');
+ if (tmp)
+ *tmp = '\0';
+ tmp = strstr(S, "State");
+ sscanf(tmp, "State:\t%c", &P->state);
+
+ tmp = strstr(S, "Pid:");
+ if (tmp)
+ sscanf(tmp, "Pid:\t%d\n" "PPid:\t%d\n", &P->pid, &P->ppid);
+ else
+ fprintf(stderr, "Internal error!\n");
+
+ /* For busybox, ignoring effective, saved, etc */
+ tmp = strstr(S, "Uid:");
+ if (tmp)
+ sscanf(tmp, "Uid:\t%d", &P->ruid);
+ else
+ fprintf(stderr, "Internal error!\n");
+
+ tmp = strstr(S, "Gid:");
+ if (tmp)
+ sscanf(tmp, "Gid:\t%d", &P->rgid);
+ else
+ fprintf(stderr, "Internal error!\n");
}
extern int ps_main(int argc, char **argv)
{
- proc_t p;
- DIR *dir;
- FILE *file;
- struct dirent *entry;
- char path[32], sbuf[512];
- char uidName[10]="";
- char groupName[10]="";
- int i, c;
-
- if ( argc>1 && **(argv+1) == '-' ) {
- usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
- }
-
- dir = opendir("/proc");
- if (!dir) {
- perror("Can't open /proc");
- exit(FALSE);
- }
-
- fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid", "State", "Command");
- while ((entry = readdir(dir)) != NULL) {
- uidName[0]='\0';
- groupName[0]='\0';
-
- if (! isdigit(*entry->d_name))
- continue;
- sprintf(path, "/proc/%s/status", entry->d_name);
- if ((file2str(path, sbuf, sizeof sbuf)) != -1 ) {
- parse_proc_status(sbuf, &p);
+ proc_t p;
+ DIR *dir;
+ FILE *file;
+ struct dirent *entry;
+ char path[32], sbuf[512];
+ char uidName[10] = "";
+ char groupName[10] = "";
+ int i, c;
+
+ if (argc > 1 && **(argv + 1) == '-') {
+ usage
+ ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
}
- /* Make some adjustments as needed */
- my_getpwuid( uidName, p.ruid);
- my_getgrgid( groupName, p.rgid);
- if (*uidName == '\0')
- sprintf( uidName, "%d", p.ruid);
- if (*groupName == '\0')
- sprintf( groupName, "%d", p.rgid);
-
- fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName, p.state);
- sprintf(path, "/proc/%s/cmdline", entry->d_name);
- file = fopen(path, "r");
- if (file == NULL) {
- perror(path);
- exit(FALSE);
+ dir = opendir("/proc");
+ if (!dir) {
+ perror("Can't open /proc");
+ exit(FALSE);
}
- i=0;
- while (((c = getc(file)) != EOF) && (i < 53)) {
- i++;
- if (c == '\0')
- c = ' ';
- putc(c, stdout);
+
+ fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
+ "State", "Command");
+ while ((entry = readdir(dir)) != NULL) {
+ uidName[0] = '\0';
+ groupName[0] = '\0';
+
+ if (!isdigit(*entry->d_name))
+ continue;
+ sprintf(path, "/proc/%s/status", entry->d_name);
+ if ((file2str(path, sbuf, sizeof sbuf)) != -1) {
+ parse_proc_status(sbuf, &p);
+ }
+
+ /* Make some adjustments as needed */
+ my_getpwuid(uidName, p.ruid);
+ my_getgrgid(groupName, p.rgid);
+ if (*uidName == '\0')
+ sprintf(uidName, "%d", p.ruid);
+ if (*groupName == '\0')
+ sprintf(groupName, "%d", p.rgid);
+
+ fprintf(stdout, "%5d %-8s %-8s %c ", p.pid, uidName, groupName,
+ p.state);
+ sprintf(path, "/proc/%s/cmdline", entry->d_name);
+ file = fopen(path, "r");
+ if (file == NULL) {
+ perror(path);
+ exit(FALSE);
+ }
+ i = 0;
+ while (((c = getc(file)) != EOF) && (i < 53)) {
+ i++;
+ if (c == '\0')
+ c = ' ';
+ putc(c, stdout);
+ }
+ if (i == 0)
+ fprintf(stdout, "%s", p.cmd);
+ fprintf(stdout, "\n");
}
- if (i==0)
- fprintf(stdout, "%s", p.cmd);
- fprintf(stdout, "\n");
- }
- closedir(dir);
- exit(TRUE);
+ closedir(dir);
+ exit(TRUE);
}