aboutsummaryrefslogtreecommitdiff
path: root/procps/top.c
diff options
context:
space:
mode:
Diffstat (limited to 'procps/top.c')
-rw-r--r--procps/top.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/procps/top.c b/procps/top.c
index 015d1ab74..f97ded5d6 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -116,7 +116,6 @@
116//kbuild:lib-$(CONFIG_TOP) += top.o 116//kbuild:lib-$(CONFIG_TOP) += top.o
117 117
118#include "libbb.h" 118#include "libbb.h"
119#include "common_bufsiz.h"
120 119
121 120
122typedef struct top_status_t { 121typedef struct top_status_t {
@@ -154,6 +153,8 @@ typedef int (*cmp_funcp)(top_status_t *P, top_status_t *Q);
154 153
155enum { SORT_DEPTH = 3 }; 154enum { SORT_DEPTH = 3 };
156 155
156/* Screens wider than this are unlikely */
157enum { LINE_BUF_SIZE = 512 - 64 };
157 158
158struct globals { 159struct globals {
159 top_status_t *top; 160 top_status_t *top;
@@ -192,10 +193,9 @@ struct globals {
192#if ENABLE_FEATURE_TOP_INTERACTIVE 193#if ENABLE_FEATURE_TOP_INTERACTIVE
193 char kbd_input[KEYCODE_BUFFER_SIZE]; 194 char kbd_input[KEYCODE_BUFFER_SIZE];
194#endif 195#endif
195 char line_buf[80]; 196 char line_buf[LINE_BUF_SIZE];
196}; //FIX_ALIASING; - large code growth 197};
197enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) }; 198#define G (*ptr_to_globals)
198#define G (*(struct globals*)bb_common_bufsiz1)
199#define top (G.top ) 199#define top (G.top )
200#define ntop (G.ntop ) 200#define ntop (G.ntop )
201#define sort_field (G.sort_field ) 201#define sort_field (G.sort_field )
@@ -213,8 +213,7 @@ enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) };
213#define total_pcpu (G.total_pcpu ) 213#define total_pcpu (G.total_pcpu )
214#define line_buf (G.line_buf ) 214#define line_buf (G.line_buf )
215#define INIT_G() do { \ 215#define INIT_G() do { \
216 setup_common_bufsiz(); \ 216 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
217 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
218 BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \ 217 BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \
219} while (0) 218} while (0)
220 219
@@ -1110,15 +1109,14 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1110#endif 1109#endif
1111 1110
1112 /* all args are options; -n NUM */ 1111 /* all args are options; -n NUM */
1113 opt_complementary = "-"; /* options can be specified w/o dash */ 1112 make_all_argv_opts(argv); /* options can be specified w/o dash */
1114 col = getopt32(argv, "d:n:b"IF_FEATURE_TOPMEM("m"), &str_interval, &str_iterations); 1113 col = getopt32(argv, "d:n:b"IF_FEATURE_TOPMEM("m"), &str_interval, &str_iterations);
1115#if ENABLE_FEATURE_TOPMEM 1114#if ENABLE_FEATURE_TOPMEM
1116 if (col & OPT_m) /* -m (busybox specific) */ 1115 if (col & OPT_m) /* -m (busybox specific) */
1117 scan_mask = TOPMEM_MASK; 1116 scan_mask = TOPMEM_MASK;
1118#endif 1117#endif
1119 if (col & OPT_d) { 1118 if (col & OPT_d) {
1120 /* work around for "-d 1" -> "-d -1" done by getopt32 1119 /* work around for "-d 1" -> "-d -1" done by make_all_argv_opts() */
1121 * (opt_complementary == "-" does this) */
1122 if (str_interval[0] == '-') 1120 if (str_interval[0] == '-')
1123 str_interval++; 1121 str_interval++;
1124 /* Need to limit it to not overflow poll timeout */ 1122 /* Need to limit it to not overflow poll timeout */
@@ -1148,6 +1146,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1148 else { 1146 else {
1149 /* Turn on unbuffered input; turn off echoing, ^C ^Z etc */ 1147 /* Turn on unbuffered input; turn off echoing, ^C ^Z etc */
1150 set_termios_to_raw(STDIN_FILENO, &initial_settings, TERMIOS_CLEAR_ISIG); 1148 set_termios_to_raw(STDIN_FILENO, &initial_settings, TERMIOS_CLEAR_ISIG);
1149 die_func = reset_term;
1151 } 1150 }
1152 1151
1153 bb_signals(BB_FATAL_SIGS, sig_catcher); 1152 bb_signals(BB_FATAL_SIGS, sig_catcher);