aboutsummaryrefslogtreecommitdiff
path: root/procps/ps.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-19 14:47:11 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-19 14:47:11 +0000
commit8581863a1b536e2db20036e680b58cc07c54ad55 (patch)
treedd38275bbe7988a0d2c8a806ea51c99e326fa772 /procps/ps.c
parent516a0ca2dc92d9ea103535863102cc5425fe648e (diff)
downloadbusybox-8581863a1b536e2db20036e680b58cc07c54ad55.tar.gz
procps: remove all global variables
text data bss dec hex filename 1462 14 24 1500 5dc busybox.t2/procps/ps.o 1484 0 0 1484 5cc busybox.t3/procps/ps.o 3122 0 252 3374 d2e busybox.t1/procps/top.o 3117 0 0 3117 c2d busybox.t3/procps/top.o
Diffstat (limited to 'procps/ps.c')
-rw-r--r--procps/ps.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/procps/ps.c b/procps/ps.c
index 0c9b71e09..5128c3d59 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -109,7 +109,7 @@ static const ps_out_t out_spec[] = {
// { sizeof("RGROUP" )-1, "rgroup","RGROUP" ,func_rgroup,PSSCAN_UIDGID },
// { sizeof("RUSER" )-1, "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID },
// { sizeof("TIME" )-1, "time" ,"TIME" ,func_time ,PSSCAN_ },
- { sizeof("TT" )-1, "tty" ,"TT" ,func_tty ,PSSCAN_TTY },
+ { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY },
{ 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ },
// Not mandated by POSIX, but useful:
{ 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS },
@@ -117,13 +117,25 @@ static const ps_out_t out_spec[] = {
#define VEC_SIZE(v) ( sizeof(v) / sizeof((v)[0]) )
-static ps_out_t* out;
-static int out_cnt;
-static int print_header;
-static int ps_flags;
-static char *buffer;
-static unsigned terminal_width;
+#define DEFAULT_O_STR "pid,user" /* TODO: ,vsz,stat */ ",args"
+struct globals {
+ ps_out_t* out;
+ int out_cnt;
+ int print_header;
+ int need_flags;
+ char *buffer;
+ unsigned terminal_width;
+ char default_o[sizeof(DEFAULT_O_STR)];
+};
+#define G (*(struct globals*)&bb_common_bufsiz1)
+#define out (G.out )
+#define out_cnt (G.out_cnt )
+#define print_header (G.print_header )
+#define need_flags (G.need_flags )
+#define buffer (G.buffer )
+#define terminal_width (G.terminal_width)
+#define default_o (G.default_o )
static ps_out_t* new_out_t(void)
{
@@ -186,7 +198,7 @@ static void post_process(void)
int i;
int width = 0;
for (i = 0; i < out_cnt; i++) {
- ps_flags |= out[i].ps_flags;
+ need_flags |= out[i].ps_flags;
if (out[i].header[0]) {
print_header = 1;
}
@@ -241,15 +253,15 @@ static void format_process(const procps_status_t *ps)
printf("%.*s\n", terminal_width, buffer);
}
-/* Cannot be const: parse_o() will choke */
-static char default_o[] = "pid,user" /* TODO: ,vsz,stat */ ",args";
-
int ps_main(int argc, char **argv);
int ps_main(int argc, char **argv)
{
procps_status_t *p;
llist_t* opt_o = NULL;
+ /* Cannot be const: parse_o() will choke */
+ strcpy(default_o, DEFAULT_O_STR);
+
// POSIX:
// -a Write information for all processes associated with terminals
// Implementations may omit session leaders from this list
@@ -282,7 +294,7 @@ int ps_main(int argc, char **argv)
format_header();
p = NULL;
- while ((p = procps_scan(p, ps_flags))) {
+ while ((p = procps_scan(p, need_flags))) {
format_process(p);
}