aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/tar.c2
-rw-r--r--console-tools/dumpkmap.c1
-rw-r--r--coreutils/catv.c4
-rw-r--r--coreutils/cksum.c6
-rw-r--r--coreutils/date.c6
-rw-r--r--coreutils/split.c2
-rw-r--r--coreutils/stat.c7
-rw-r--r--coreutils/sum.c4
-rw-r--r--coreutils/tee.c6
-rw-r--r--editors/diff.c1
-rw-r--r--editors/ed.c8
-rw-r--r--miscutils/chat.c3
-rw-r--r--miscutils/conspy.c7
-rw-r--r--miscutils/fbsplash.c7
-rw-r--r--miscutils/inotifyd.c6
-rw-r--r--miscutils/less.c7
-rw-r--r--miscutils/microcom.c6
-rw-r--r--networking/httpd.c1
-rw-r--r--networking/isrv_identd.c7
-rw-r--r--networking/libiproute/ipaddress.c5
-rw-r--r--networking/libiproute/ipneigh.c3
-rw-r--r--networking/libiproute/iproute.c3
-rw-r--r--networking/nc.c3
-rw-r--r--procps/nmeter.c9
-rw-r--r--runit/svlogd.c4
-rw-r--r--sysklogd/klogd.c7
-rw-r--r--sysklogd/logger.c2
-rw-r--r--util-linux/script.c10
-rw-r--r--util-linux/umount.c1
29 files changed, 83 insertions, 55 deletions
diff --git a/archival/tar.c b/archival/tar.c
index caf4363de..346a9404e 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -162,6 +162,7 @@
162 162
163 163
164#define block_buf bb_common_bufsiz1 164#define block_buf bb_common_bufsiz1
165#define INIT_G() do { setup_common_bufsiz(); } while (0)
165 166
166 167
167#if ENABLE_FEATURE_TAR_CREATE 168#if ENABLE_FEATURE_TAR_CREATE
@@ -964,6 +965,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
964#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM 965#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
965 llist_t *excludes = NULL; 966 llist_t *excludes = NULL;
966#endif 967#endif
968 INIT_G();
967 969
968 /* Initialise default values */ 970 /* Initialise default values */
969 tar_handle = init_handle(); 971 tar_handle = init_handle();
diff --git a/console-tools/dumpkmap.c b/console-tools/dumpkmap.c
index 6412dffc8..b6fd466dc 100644
--- a/console-tools/dumpkmap.c
+++ b/console-tools/dumpkmap.c
@@ -38,6 +38,7 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
38 struct kbentry ke; 38 struct kbentry ke;
39 int i, j, fd; 39 int i, j, fd;
40#define flags bb_common_bufsiz1 40#define flags bb_common_bufsiz1
41 setup_common_bufsiz();
41 42
42 /* When user accidentally runs "dumpkmap FILE" 43 /* When user accidentally runs "dumpkmap FILE"
43 * instead of "dumpkmap >FILE", we'd dump binary stuff to tty. 44 * instead of "dumpkmap >FILE", we'd dump binary stuff to tty.
diff --git a/coreutils/catv.c b/coreutils/catv.c
index 801d2451d..0e71368a5 100644
--- a/coreutils/catv.c
+++ b/coreutils/catv.c
@@ -49,6 +49,9 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
49 /* Read from stdin if there's nothing else to do. */ 49 /* Read from stdin if there's nothing else to do. */
50 if (!argv[0]) 50 if (!argv[0])
51 *--argv = (char*)"-"; 51 *--argv = (char*)"-";
52
53#define read_buf bb_common_bufsiz1
54 setup_common_bufsiz();
52 do { 55 do {
53 fd = open_or_warn_stdin(*argv); 56 fd = open_or_warn_stdin(*argv);
54 if (fd < 0) { 57 if (fd < 0) {
@@ -58,7 +61,6 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
58 for (;;) { 61 for (;;) {
59 int i, res; 62 int i, res;
60 63
61#define read_buf bb_common_bufsiz1
62 res = read(fd, read_buf, COMMON_BUFSIZE); 64 res = read(fd, read_buf, COMMON_BUFSIZE);
63 if (res < 0) 65 if (res < 0)
64 retval = EXIT_FAILURE; 66 retval = EXIT_FAILURE;
diff --git a/coreutils/cksum.c b/coreutils/cksum.c
index d8351e7c6..8a8a39f68 100644
--- a/coreutils/cksum.c
+++ b/coreutils/cksum.c
@@ -33,6 +33,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
33 argv++; 33 argv++;
34#endif 34#endif
35 35
36 setup_common_bufsiz();
36 do { 37 do {
37 int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input); 38 int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
38 39
@@ -43,9 +44,8 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
43 crc = 0; 44 crc = 0;
44 length = 0; 45 length = 0;
45 46
46#define read_buf bb_common_bufsiz1 47#define read_buf bb_common_bufsiz1
47#define sizeof_read_buf COMMON_BUFSIZE 48 while ((bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE)) > 0) {
48 while ((bytes_read = safe_read(fd, read_buf, sizeof_read_buf)) > 0) {
49 length += bytes_read; 49 length += bytes_read;
50 crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table); 50 crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
51 } 51 }
diff --git a/coreutils/date.c b/coreutils/date.c
index 59b4b8f2a..ff3214d85 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -368,8 +368,8 @@ int date_main(int argc UNUSED_PARAM, char **argv)
368 } 368 }
369#endif 369#endif
370 370
371#define date_buf bb_common_bufsiz1 371#define date_buf bb_common_bufsiz1
372#define sizeof_date_buf COMMON_BUFSIZE 372 setup_common_bufsiz();
373 if (*fmt_dt2str == '\0') { 373 if (*fmt_dt2str == '\0') {
374 /* With no format string, just print a blank line */ 374 /* With no format string, just print a blank line */
375 date_buf[0] = '\0'; 375 date_buf[0] = '\0';
@@ -379,7 +379,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
379 fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S"; 379 fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
380 } 380 }
381 /* Generate output string */ 381 /* Generate output string */
382 strftime(date_buf, sizeof_date_buf, fmt_dt2str, &tm_time); 382 strftime(date_buf, COMMON_BUFSIZE, fmt_dt2str, &tm_time);
383 } 383 }
384 puts(date_buf); 384 puts(date_buf);
385 385
diff --git a/coreutils/split.c b/coreutils/split.c
index b2da74e27..e67c3de66 100644
--- a/coreutils/split.c
+++ b/coreutils/split.c
@@ -79,6 +79,8 @@ int split_main(int argc UNUSED_PARAM, char **argv)
79 ssize_t bytes_read, to_write; 79 ssize_t bytes_read, to_write;
80 char *src; 80 char *src;
81 81
82 setup_common_bufsiz();
83
82 opt_complementary = "?2:a+"; /* max 2 args; -a N */ 84 opt_complementary = "?2:a+"; /* max 2 args; -a N */
83 opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len); 85 opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len);
84 86
diff --git a/coreutils/stat.c b/coreutils/stat.c
index 78df9c948..ddcfcf2d7 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -158,10 +158,9 @@ static const char *human_time(time_t t)
158 /* coreutils 6.3 compat: */ 158 /* coreutils 6.3 compat: */
159 159
160 /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/ 160 /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
161#define buf bb_common_bufsiz1 161#define buf bb_common_bufsiz1
162#define sizeof_buf COMMON_BUFSIZE 162 setup_common_bufsiz();
163 163 strcpy(strftime_YYYYMMDDHHMMSS(buf, COMMON_BUFSIZE, &t), ".000000000");
164 strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof_buf, &t), ".000000000");
165 return buf; 164 return buf;
166#undef buf 165#undef buf
167} 166}
diff --git a/coreutils/sum.c b/coreutils/sum.c
index cc6677221..ec9ed2a11 100644
--- a/coreutils/sum.c
+++ b/coreutils/sum.c
@@ -31,12 +31,14 @@ enum { SUM_BSD, PRINT_NAME, SUM_SYSV };
31/* Return 1 if successful. */ 31/* Return 1 if successful. */
32static unsigned sum_file(const char *file, unsigned type) 32static unsigned sum_file(const char *file, unsigned type)
33{ 33{
34#define buf bb_common_bufsiz1
35 unsigned long long total_bytes = 0; 34 unsigned long long total_bytes = 0;
36 int fd, r; 35 int fd, r;
37 /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ 36 /* The sum of all the input bytes, modulo (UINT_MAX + 1). */
38 unsigned s = 0; 37 unsigned s = 0;
39 38
39#define buf bb_common_bufsiz1
40 setup_common_bufsiz();
41
40 fd = open_or_warn_stdin(file); 42 fd = open_or_warn_stdin(file);
41 if (fd == -1) 43 if (fd == -1)
42 return 0; 44 return 0;
diff --git a/coreutils/tee.c b/coreutils/tee.c
index a0e177cbc..a68e9446f 100644
--- a/coreutils/tee.c
+++ b/coreutils/tee.c
@@ -37,8 +37,8 @@ int tee_main(int argc, char **argv)
37//TODO: make unconditional 37//TODO: make unconditional
38#if ENABLE_FEATURE_TEE_USE_BLOCK_IO 38#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
39 ssize_t c; 39 ssize_t c;
40# define buf bb_common_bufsiz1 40# define buf bb_common_bufsiz1
41# define sizeof_buf COMMON_BUFSIZE 41 setup_common_bufsiz();
42#else 42#else
43 int c; 43 int c;
44#endif 44#endif
@@ -81,7 +81,7 @@ int tee_main(int argc, char **argv)
81 /* names[0] will be filled later */ 81 /* names[0] will be filled later */
82 82
83#if ENABLE_FEATURE_TEE_USE_BLOCK_IO 83#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
84 while ((c = safe_read(STDIN_FILENO, buf, sizeof_buf)) > 0) { 84 while ((c = safe_read(STDIN_FILENO, buf, COMMON_BUFSIZE)) > 0) {
85 fp = files; 85 fp = files;
86 do 86 do
87 fwrite(buf, 1, c, *fp); 87 fwrite(buf, 1, c, *fp);
diff --git a/editors/diff.c b/editors/diff.c
index 3c8e9074a..ff269360f 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -749,6 +749,7 @@ static int diffreg(char *file[2])
749 fp[i] = fdopen(fd, "r"); 749 fp[i] = fdopen(fd, "r");
750 } 750 }
751 751
752 setup_common_bufsiz();
752 while (1) { 753 while (1) {
753 const size_t sz = COMMON_BUFSIZE / 2; 754 const size_t sz = COMMON_BUFSIZE / 2;
754 char *const buf0 = bb_common_bufsiz1; 755 char *const buf0 = bb_common_bufsiz1;
diff --git a/editors/ed.c b/editors/ed.c
index 8da7b1dd5..c028b78cb 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -33,12 +33,11 @@ typedef struct LINE {
33} LINE; 33} LINE;
34 34
35 35
36#define searchString bb_common_bufsiz1 36#define searchString bb_common_bufsiz1
37#define sizeof_searchString COMMON_BUFSIZE
38 37
39enum { 38enum {
40 USERSIZE = sizeof_searchString > 1024 ? 1024 39 USERSIZE = COMMON_BUFSIZE > 1024 ? 1024
41 : sizeof_searchString - 1, /* max line length typed in by user */ 40 : COMMON_BUFSIZE - 1, /* max line length typed in by user */
42 INITBUF_SIZE = 1024, /* initial buffer size */ 41 INITBUF_SIZE = 1024, /* initial buffer size */
43}; 42};
44 43
@@ -68,6 +67,7 @@ struct globals {
68#define lines (G.lines ) 67#define lines (G.lines )
69#define marks (G.marks ) 68#define marks (G.marks )
70#define INIT_G() do { \ 69#define INIT_G() do { \
70 setup_common_bufsiz(); \
71 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 71 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
72} while (0) 72} while (0)
73 73
diff --git a/miscutils/chat.c b/miscutils/chat.c
index 25850dd20..6b429f2a6 100644
--- a/miscutils/chat.c
+++ b/miscutils/chat.c
@@ -286,9 +286,10 @@ int chat_main(int argc UNUSED_PARAM, char **argv)
286 && poll(&pfd, 1, timeout) > 0 286 && poll(&pfd, 1, timeout) > 0
287 && (pfd.revents & POLLIN) 287 && (pfd.revents & POLLIN)
288 ) { 288 ) {
289#define buf bb_common_bufsiz1
290 llist_t *l; 289 llist_t *l;
291 ssize_t delta; 290 ssize_t delta;
291#define buf bb_common_bufsiz1
292 setup_common_bufsiz();
292 293
293 // read next char from device 294 // read next char from device
294 if (safe_read(STDIN_FILENO, buf+buf_len, 1) > 0) { 295 if (safe_read(STDIN_FILENO, buf+buf_len, 1) > 0) {
diff --git a/miscutils/conspy.c b/miscutils/conspy.c
index 0d96a5f9a..f6468c116 100644
--- a/miscutils/conspy.c
+++ b/miscutils/conspy.c
@@ -364,8 +364,6 @@ int conspy_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
364int conspy_main(int argc UNUSED_PARAM, char **argv) 364int conspy_main(int argc UNUSED_PARAM, char **argv)
365{ 365{
366 char tty_name[sizeof(DEV_TTY "NN")]; 366 char tty_name[sizeof(DEV_TTY "NN")];
367#define keybuf bb_common_bufsiz1
368#define sizeof_keybuf COMMON_BUFSIZE
369 struct termios termbuf; 367 struct termios termbuf;
370 unsigned opts; 368 unsigned opts;
371 unsigned ttynum; 369 unsigned ttynum;
@@ -384,6 +382,9 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
384 382
385 applet_long_options = getopt_longopts; 383 applet_long_options = getopt_longopts;
386#endif 384#endif
385#define keybuf bb_common_bufsiz1
386 setup_common_bufsiz();
387
387 INIT_G(); 388 INIT_G();
388 strcpy(G.vcsa_name, DEV_VCSA); 389 strcpy(G.vcsa_name, DEV_VCSA);
389 390
@@ -515,7 +516,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
515 default: 516 default:
516 // Read the keys pressed 517 // Read the keys pressed
517 k = keybuf + G.key_count; 518 k = keybuf + G.key_count;
518 bytes_read = read(G.kbd_fd, k, sizeof_keybuf - G.key_count); 519 bytes_read = read(G.kbd_fd, k, COMMON_BUFSIZE - G.key_count);
519 if (bytes_read < 0) 520 if (bytes_read < 0)
520 goto abort; 521 goto abort;
521 522
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c
index b26ad2c15..3ddf8a242 100644
--- a/miscutils/fbsplash.c
+++ b/miscutils/fbsplash.c
@@ -373,12 +373,13 @@ static void fb_drawimage(void)
373 * - A raster of Width * Height pixels in triplets of rgb 373 * - A raster of Width * Height pixels in triplets of rgb
374 * in pure binary by 1 or 2 bytes. (we support only 1 byte) 374 * in pure binary by 1 or 2 bytes. (we support only 1 byte)
375 */ 375 */
376#define concat_buf bb_common_bufsiz1 376#define concat_buf bb_common_bufsiz1
377#define sizeof_concat_buf COMMON_BUFSIZE 377 setup_common_bufsiz();
378
378 read_ptr = concat_buf; 379 read_ptr = concat_buf;
379 while (1) { 380 while (1) {
380 int w, h, max_color_val; 381 int w, h, max_color_val;
381 int rem = concat_buf + sizeof_concat_buf - read_ptr; 382 int rem = concat_buf + COMMON_BUFSIZE - read_ptr;
382 if (rem < 2 383 if (rem < 2
383 || fgets(read_ptr, rem, theme_file) == NULL 384 || fgets(read_ptr, rem, theme_file) == NULL
384 ) { 385 ) {
diff --git a/miscutils/inotifyd.c b/miscutils/inotifyd.c
index 1d28e8f99..52db08ada 100644
--- a/miscutils/inotifyd.c
+++ b/miscutils/inotifyd.c
@@ -162,10 +162,10 @@ int inotifyd_main(int argc, char **argv)
162 162
163 // read out all pending events 163 // read out all pending events
164 // (NB: len must be int, not ssize_t or long!) 164 // (NB: len must be int, not ssize_t or long!)
165#define eventbuf bb_common_bufsiz1
166 setup_common_bufsiz();
165 xioctl(pfd.fd, FIONREAD, &len); 167 xioctl(pfd.fd, FIONREAD, &len);
166#define eventbuf bb_common_bufsiz1 168 ie = buf = (len <= COMMON_BUFSIZE) ? eventbuf : xmalloc(len);
167#define sizeof_eventbuf COMMON_BUFSIZE
168 ie = buf = (len <= sizeof_eventbuf) ? eventbuf : xmalloc(len);
169 len = full_read(pfd.fd, buf, len); 169 len = full_read(pfd.fd, buf, len);
170 // process events. N.B. events may vary in length 170 // process events. N.B. events may vary in length
171 while (len > 0) { 171 while (len > 0) {
diff --git a/miscutils/less.c b/miscutils/less.c
index 94ecf1686..d7076dbbc 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -440,8 +440,6 @@ static int at_end(void)
440 */ 440 */
441static void read_lines(void) 441static void read_lines(void)
442{ 442{
443#define readbuf bb_common_bufsiz1
444#define sizeof_readbuf COMMON_BUFSIZE
445 char *current_line, *p; 443 char *current_line, *p;
446 int w = width; 444 int w = width;
447 char last_terminated = terminated; 445 char last_terminated = terminated;
@@ -451,6 +449,9 @@ static void read_lines(void)
451 unsigned old_max_fline = max_fline; 449 unsigned old_max_fline = max_fline;
452#endif 450#endif
453 451
452#define readbuf bb_common_bufsiz1
453 setup_common_bufsiz();
454
454 /* (careful: max_fline can be -1) */ 455 /* (careful: max_fline can be -1) */
455 if (max_fline + 1 > MAXLINES) 456 if (max_fline + 1 > MAXLINES)
456 return; 457 return;
@@ -482,7 +483,7 @@ static void read_lines(void)
482 time_t t; 483 time_t t;
483 484
484 errno = 0; 485 errno = 0;
485 eof_error = safe_read(STDIN_FILENO, readbuf, sizeof_readbuf); 486 eof_error = safe_read(STDIN_FILENO, readbuf, COMMON_BUFSIZE);
486 if (errno != EAGAIN) 487 if (errno != EAGAIN)
487 break; 488 break;
488 t = time(NULL); 489 t = time(NULL);
diff --git a/miscutils/microcom.c b/miscutils/microcom.c
index 5eb2e6743..d9e8f9187 100644
--- a/miscutils/microcom.c
+++ b/miscutils/microcom.c
@@ -156,11 +156,11 @@ int microcom_main(int argc UNUSED_PARAM, char **argv)
156skip_write: ; 156skip_write: ;
157 } 157 }
158 if (pfd[0].revents) { 158 if (pfd[0].revents) {
159#define iobuf bb_common_bufsiz1
160#define sizeof_iobuf COMMON_BUFSIZE
161 ssize_t len; 159 ssize_t len;
160#define iobuf bb_common_bufsiz1
161 setup_common_bufsiz();
162 // read from device -> write to stdout 162 // read from device -> write to stdout
163 len = safe_read(sfd, iobuf, sizeof_iobuf); 163 len = safe_read(sfd, iobuf, COMMON_BUFSIZE);
164 if (len > 0) 164 if (len > 0)
165 full_write(STDOUT_FILENO, iobuf, len); 165 full_write(STDOUT_FILENO, iobuf, len);
166 else { 166 else {
diff --git a/networking/httpd.c b/networking/httpd.c
index ef90770ac..abe83a458 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -370,6 +370,7 @@ enum {
370# define content_gzip 0 370# define content_gzip 0
371#endif 371#endif
372#define INIT_G() do { \ 372#define INIT_G() do { \
373 setup_common_bufsiz(); \
373 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 374 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
374 IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \ 375 IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \
375 IF_FEATURE_HTTPD_RANGES(range_start = -1;) \ 376 IF_FEATURE_HTTPD_RANGES(range_start = -1;) \
diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c
index f63ed8ee4..8a15926e5 100644
--- a/networking/isrv_identd.c
+++ b/networking/isrv_identd.c
@@ -29,8 +29,7 @@ typedef struct identd_buf_t {
29 char buf[64 - sizeof(int)]; 29 char buf[64 - sizeof(int)];
30} identd_buf_t; 30} identd_buf_t;
31 31
32#define bogouser bb_common_bufsiz1 32#define bogouser bb_common_bufsiz1
33#define sizeof_bogouser COMMON_BUFSIZE
34 33
35static int new_peer(isrv_state_t *state, int fd) 34static int new_peer(isrv_state_t *state, int fd)
36{ 35{
@@ -117,10 +116,12 @@ int fakeidentd_main(int argc UNUSED_PARAM, char **argv)
117 unsigned opt; 116 unsigned opt;
118 int fd; 117 int fd;
119 118
119 setup_common_bufsiz();
120
120 opt = getopt32(argv, "fiwb:", &bind_address); 121 opt = getopt32(argv, "fiwb:", &bind_address);
121 strcpy(bogouser, "nobody"); 122 strcpy(bogouser, "nobody");
122 if (argv[optind]) 123 if (argv[optind])
123 strncpy(bogouser, argv[optind], sizeof_bogouser - 1); 124 strncpy(bogouser, argv[optind], COMMON_BUFSIZE - 1);
124 125
125 /* Daemonize if no -f and no -i and no -w */ 126 /* Daemonize if no -f and no -i and no -w */
126 if (!(opt & OPT_fiw)) 127 if (!(opt & OPT_fiw))
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index 2c0f514c7..d9e099607 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -41,7 +41,7 @@ struct filter_t {
41typedef struct filter_t filter_t; 41typedef struct filter_t filter_t;
42 42
43#define G_filter (*(filter_t*)bb_common_bufsiz1) 43#define G_filter (*(filter_t*)bb_common_bufsiz1)
44 44#define INIT_G() do { setup_common_bufsiz(); } while (0)
45 45
46static void print_link_flags(unsigned flags, unsigned mdown) 46static void print_link_flags(unsigned flags, unsigned mdown)
47{ 47{
@@ -745,6 +745,9 @@ int FAST_FUNC do_ipaddr(char **argv)
745 /* 0 1 2 3 4 5 6 7 8 */ 745 /* 0 1 2 3 4 5 6 7 8 */
746 "add\0""change\0""chg\0""replace\0""delete\0""list\0""show\0""lst\0""flush\0"; 746 "add\0""change\0""chg\0""replace\0""delete\0""list\0""show\0""lst\0""flush\0";
747 int cmd = 2; 747 int cmd = 2;
748
749 INIT_G();
750
748 if (*argv) { 751 if (*argv) {
749 cmd = index_in_substrings(commands, *argv); 752 cmd = index_in_substrings(commands, *argv);
750 if (cmd < 0) 753 if (cmd < 0)
diff --git a/networking/libiproute/ipneigh.c b/networking/libiproute/ipneigh.c
index 151d3d109..d2028b7b6 100644
--- a/networking/libiproute/ipneigh.c
+++ b/networking/libiproute/ipneigh.c
@@ -42,6 +42,7 @@ struct filter_t {
42typedef struct filter_t filter_t; 42typedef struct filter_t filter_t;
43 43
44#define G_filter (*(filter_t*)bb_common_bufsiz1) 44#define G_filter (*(filter_t*)bb_common_bufsiz1)
45#define INIT_G() do { setup_common_bufsiz(); } while (0)
45 46
46static int flush_update(void) 47static int flush_update(void)
47{ 48{
@@ -339,6 +340,8 @@ int FAST_FUNC do_ipneigh(char **argv)
339 /*0-1*/ "show\0" "flush\0"; 340 /*0-1*/ "show\0" "flush\0";
340 int command_num; 341 int command_num;
341 342
343 INIT_G();
344
342 if (!*argv) 345 if (!*argv)
343 return ipneigh_list_or_flush(argv, 0); 346 return ipneigh_list_or_flush(argv, 0);
344 347
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index 34d4f4758..e674e9a0d 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -45,6 +45,7 @@ struct filter_t {
45typedef struct filter_t filter_t; 45typedef struct filter_t filter_t;
46 46
47#define G_filter (*(filter_t*)bb_common_bufsiz1) 47#define G_filter (*(filter_t*)bb_common_bufsiz1)
48#define INIT_G() do { setup_common_bufsiz(); } while (0)
48 49
49static int flush_update(void) 50static int flush_update(void)
50{ 51{
@@ -903,6 +904,8 @@ int FAST_FUNC do_iproute(char **argv)
903 unsigned flags = 0; 904 unsigned flags = 0;
904 int cmd = RTM_NEWROUTE; 905 int cmd = RTM_NEWROUTE;
905 906
907 INIT_G();
908
906 if (!*argv) 909 if (!*argv)
907 return iproute_list_or_flush(argv, 0); 910 return iproute_list_or_flush(argv, 0);
908 911
diff --git a/networking/nc.c b/networking/nc.c
index 50edee450..13a9b48a8 100644
--- a/networking/nc.c
+++ b/networking/nc.c
@@ -239,6 +239,8 @@ int nc_main(int argc, char **argv)
239 FD_SET(cfd, &readfds); 239 FD_SET(cfd, &readfds);
240 FD_SET(STDIN_FILENO, &readfds); 240 FD_SET(STDIN_FILENO, &readfds);
241 241
242#define iobuf bb_common_bufsiz1
243 setup_common_bufsiz();
242 for (;;) { 244 for (;;) {
243 int fd; 245 int fd;
244 int ofd; 246 int ofd;
@@ -249,7 +251,6 @@ int nc_main(int argc, char **argv)
249 if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0) 251 if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0)
250 bb_perror_msg_and_die("select"); 252 bb_perror_msg_and_die("select");
251 253
252#define iobuf bb_common_bufsiz1
253 fd = STDIN_FILENO; 254 fd = STDIN_FILENO;
254 while (1) { 255 while (1) {
255 if (FD_ISSET(fd, &testfds)) { 256 if (FD_ISSET(fd, &testfds)) {
diff --git a/procps/nmeter.c b/procps/nmeter.c
index efa3d553d..3eac2d3b2 100644
--- a/procps/nmeter.c
+++ b/procps/nmeter.c
@@ -109,16 +109,15 @@ struct globals {
109#define proc_meminfo (G.proc_meminfo ) 109#define proc_meminfo (G.proc_meminfo )
110#define proc_diskstats (G.proc_diskstats ) 110#define proc_diskstats (G.proc_diskstats )
111#define proc_sys_fs_filenr (G.proc_sys_fs_filenr) 111#define proc_sys_fs_filenr (G.proc_sys_fs_filenr)
112#define outbuf bb_common_bufsiz1
112#define INIT_G() do { \ 113#define INIT_G() do { \
114 setup_common_bufsiz(); \
113 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 115 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
114 cur_outbuf = outbuf; \ 116 cur_outbuf = outbuf; \
115 G.final_char = '\n'; \ 117 G.final_char = '\n'; \
116 G.deltanz = G.delta = 1000000; \ 118 G.deltanz = G.delta = 1000000; \
117} while (0) 119} while (0)
118 120
119#define outbuf bb_common_bufsiz1
120#define sizeof_outbuf COMMON_BUFSIZE
121
122static inline void reset_outbuf(void) 121static inline void reset_outbuf(void)
123{ 122{
124 cur_outbuf = outbuf; 123 cur_outbuf = outbuf;
@@ -141,7 +140,7 @@ static void print_outbuf(void)
141static void put(const char *s) 140static void put(const char *s)
142{ 141{
143 char *p = cur_outbuf; 142 char *p = cur_outbuf;
144 int sz = outbuf + sizeof_outbuf - p; 143 int sz = outbuf + COMMON_BUFSIZE - p;
145 while (*s && --sz >= 0) 144 while (*s && --sz >= 0)
146 *p++ = *s++; 145 *p++ = *s++;
147 cur_outbuf = p; 146 cur_outbuf = p;
@@ -149,7 +148,7 @@ static void put(const char *s)
149 148
150static void put_c(char c) 149static void put_c(char c)
151{ 150{
152 if (cur_outbuf < outbuf + sizeof_outbuf) 151 if (cur_outbuf < outbuf + COMMON_BUFSIZE)
153 *cur_outbuf++ = c; 152 *cur_outbuf++ = c;
154} 153}
155 154
diff --git a/runit/svlogd.c b/runit/svlogd.c
index 09efdb695..7cae81cb2 100644
--- a/runit/svlogd.c
+++ b/runit/svlogd.c
@@ -234,7 +234,9 @@ struct globals {
234#define blocked_sigset (G.blocked_sigset) 234#define blocked_sigset (G.blocked_sigset)
235#define fl_flag_0 (G.fl_flag_0 ) 235#define fl_flag_0 (G.fl_flag_0 )
236#define dirn (G.dirn ) 236#define dirn (G.dirn )
237#define line bb_common_bufsiz1
237#define INIT_G() do { \ 238#define INIT_G() do { \
239 setup_common_bufsiz(); \
238 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ 240 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
239 linemax = 1000; \ 241 linemax = 1000; \
240 /*buflen = 1024;*/ \ 242 /*buflen = 1024;*/ \
@@ -242,8 +244,6 @@ struct globals {
242 replace = ""; \ 244 replace = ""; \
243} while (0) 245} while (0)
244 246
245#define line bb_common_bufsiz1
246
247 247
248#define FATAL "fatal: " 248#define FATAL "fatal: "
249#define WARNING "warning: " 249#define WARNING "warning: "
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c
index 845c49a5e..4db72110d 100644
--- a/sysklogd/klogd.c
+++ b/sysklogd/klogd.c
@@ -146,10 +146,9 @@ static void klogd_close(void)
146 146
147#endif 147#endif
148 148
149#define log_buffer bb_common_bufsiz1 149#define log_buffer bb_common_bufsiz1
150#define sizeof_log_buffer COMMON_BUFSIZE
151enum { 150enum {
152 KLOGD_LOGBUF_SIZE = sizeof_log_buffer, 151 KLOGD_LOGBUF_SIZE = COMMON_BUFSIZE,
153 OPT_LEVEL = (1 << 0), 152 OPT_LEVEL = (1 << 0),
154 OPT_FOREGROUND = (1 << 1), 153 OPT_FOREGROUND = (1 << 1),
155}; 154};
@@ -175,6 +174,8 @@ int klogd_main(int argc UNUSED_PARAM, char **argv)
175 int opt; 174 int opt;
176 int used; 175 int used;
177 176
177 setup_common_bufsiz();
178
178 opt = getopt32(argv, "c:n", &opt_c); 179 opt = getopt32(argv, "c:n", &opt_c);
179 if (opt & OPT_LEVEL) { 180 if (opt & OPT_LEVEL) {
180 /* Valid levels are between 1 and 8 */ 181 /* Valid levels are between 1 and 8 */
diff --git a/sysklogd/logger.c b/sysklogd/logger.c
index b3ca85703..f9eafeb25 100644
--- a/sysklogd/logger.c
+++ b/sysklogd/logger.c
@@ -99,6 +99,8 @@ int logger_main(int argc UNUSED_PARAM, char **argv)
99 int opt; 99 int opt;
100 int i = 0; 100 int i = 0;
101 101
102 setup_common_bufsiz();
103
102 /* Fill out the name string early (may be overwritten later) */ 104 /* Fill out the name string early (may be overwritten later) */
103 str_t = uid2uname_utoa(geteuid()); 105 str_t = uid2uname_utoa(geteuid());
104 106
diff --git a/util-linux/script.c b/util-linux/script.c
index 6195161bc..86475c1f1 100644
--- a/util-linux/script.c
+++ b/util-linux/script.c
@@ -109,12 +109,12 @@ int script_main(int argc UNUSED_PARAM, char **argv)
109 109
110 if (child_pid) { 110 if (child_pid) {
111 /* parent */ 111 /* parent */
112#define buf bb_common_bufsiz1
113#define sizeof_buf COMMON_BUFSIZE
114 struct pollfd pfd[2]; 112 struct pollfd pfd[2];
115 int outfd, count, loop; 113 int outfd, count, loop;
116 double oldtime = ENABLE_SCRIPTREPLAY ? time(NULL) : 0; 114 double oldtime = ENABLE_SCRIPTREPLAY ? time(NULL) : 0;
117 smallint fd_count = 2; 115 smallint fd_count = 2;
116#define buf bb_common_bufsiz1
117 setup_common_bufsiz();
118 118
119 outfd = xopen(fname, mode); 119 outfd = xopen(fname, mode);
120 pfd[0].fd = pty; 120 pfd[0].fd = pty;
@@ -136,7 +136,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
136 } 136 }
137 if (pfd[0].revents) { 137 if (pfd[0].revents) {
138 errno = 0; 138 errno = 0;
139 count = safe_read(pty, buf, sizeof_buf); 139 count = safe_read(pty, buf, COMMON_BUFSIZE);
140 if (count <= 0 && errno != EAGAIN) { 140 if (count <= 0 && errno != EAGAIN) {
141 /* err/eof from pty: exit */ 141 /* err/eof from pty: exit */
142 goto restore; 142 goto restore;
@@ -159,7 +159,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
159 } 159 }
160 } 160 }
161 if (pfd[1].revents) { 161 if (pfd[1].revents) {
162 count = safe_read(STDIN_FILENO, buf, sizeof_buf); 162 count = safe_read(STDIN_FILENO, buf, COMMON_BUFSIZE);
163 if (count <= 0) { 163 if (count <= 0) {
164 /* err/eof from stdin: don't read stdin anymore */ 164 /* err/eof from stdin: don't read stdin anymore */
165 pfd[1].revents = 0; 165 pfd[1].revents = 0;
@@ -178,7 +178,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
178 * (util-linux's script doesn't do this. buggy :) */ 178 * (util-linux's script doesn't do this. buggy :) */
179 loop = 999; 179 loop = 999;
180 /* pty is in O_NONBLOCK mode, we exit as soon as buffer is empty */ 180 /* pty is in O_NONBLOCK mode, we exit as soon as buffer is empty */
181 while (--loop && (count = safe_read(pty, buf, sizeof_buf)) > 0) { 181 while (--loop && (count = safe_read(pty, buf, COMMON_BUFSIZE)) > 0) {
182 full_write(STDOUT_FILENO, buf, count); 182 full_write(STDOUT_FILENO, buf, count);
183 full_write(outfd, buf, count); 183 full_write(outfd, buf, count);
184 } 184 }
diff --git a/util-linux/umount.c b/util-linux/umount.c
index be0300394..91da69674 100644
--- a/util-linux/umount.c
+++ b/util-linux/umount.c
@@ -103,6 +103,7 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
103 if (opt & OPT_ALL) 103 if (opt & OPT_ALL)
104 bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file); 104 bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file);
105 } else { 105 } else {
106 setup_common_bufsiz();
106 while (getmntent_r(fp, &me, bb_common_bufsiz1, COMMON_BUFSIZE)) { 107 while (getmntent_r(fp, &me, bb_common_bufsiz1, COMMON_BUFSIZE)) {
107 /* Match fstype if passed */ 108 /* Match fstype if passed */
108 if (!match_fstype(&me, fstype)) 109 if (!match_fstype(&me, fstype))