aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--archival/cpio.c3
-rw-r--r--archival/lzop.c3
-rw-r--r--archival/rpm.c3
-rw-r--r--archival/tar.c1
-rw-r--r--console-tools/dumpkmap.c1
-rw-r--r--console-tools/resize.c3
-rw-r--r--coreutils/catv.c1
-rw-r--r--coreutils/cksum.c6
-rw-r--r--coreutils/date.c6
-rw-r--r--coreutils/dd.c3
-rw-r--r--coreutils/du.c3
-rw-r--r--coreutils/expr.c3
-rw-r--r--coreutils/ls.c3
-rw-r--r--coreutils/od_bloaty.c3
-rw-r--r--coreutils/split.c1
-rw-r--r--coreutils/stat.c6
-rw-r--r--coreutils/stty.c3
-rw-r--r--coreutils/sum.c3
-rw-r--r--coreutils/tail.c3
-rw-r--r--coreutils/tee.c6
-rw-r--r--debianutils/run_parts.c3
-rw-r--r--debianutils/start_stop_daemon.c3
-rw-r--r--e2fsprogs/fsck.c3
-rw-r--r--editors/diff.c1
-rw-r--r--editors/ed.c8
-rw-r--r--editors/sed.c3
-rw-r--r--findutils/find.c3
-rw-r--r--findutils/grep.c3
-rw-r--r--findutils/xargs.c3
-rw-r--r--include/libbb.h4
-rw-r--r--init/bootchartd.c3
-rw-r--r--libbb/common_bufsiz.c74
-rw-r--r--libbb/messages.c5
-rw-r--r--loginutils/login.c3
-rw-r--r--miscutils/chat.c1
-rw-r--r--miscutils/conspy.c6
-rw-r--r--miscutils/crond.c3
-rw-r--r--miscutils/dc.c3
-rw-r--r--miscutils/fbsplash.c6
-rw-r--r--miscutils/hdparm.c3
-rw-r--r--miscutils/i2c_tools.c1
-rw-r--r--miscutils/inotifyd.c6
-rw-r--r--miscutils/less.c6
-rw-r--r--miscutils/microcom.c6
-rw-r--r--networking/arp.c3
-rw-r--r--networking/arping.c3
-rw-r--r--networking/ftpd.c3
-rw-r--r--networking/ftpgetput.c3
-rw-r--r--networking/httpd.c10
-rw-r--r--networking/ifupdown.c3
-rw-r--r--networking/inetd.c3
-rw-r--r--networking/isrv_identd.c6
-rw-r--r--networking/libiproute/ipaddress.c3
-rw-r--r--networking/libiproute/ipneigh.c3
-rw-r--r--networking/libiproute/iproute.c3
-rw-r--r--networking/nc.c3
-rw-r--r--networking/ping.c5
-rw-r--r--networking/slattach.c3
-rw-r--r--networking/tc.c3
-rw-r--r--networking/tcpudp.c3
-rw-r--r--networking/telnet.c3
-rw-r--r--networking/telnetd.c3
-rw-r--r--networking/tftp.c6
-rw-r--r--networking/udhcp/common.h1
-rw-r--r--networking/udhcp/dhcpd.h2
-rw-r--r--networking/udhcp/dhcprelay.c2
-rw-r--r--networking/udhcp/files.c46
-rw-r--r--networking/zcip.c3
-rw-r--r--procps/free.c3
-rw-r--r--procps/fuser.c3
-rw-r--r--procps/nmeter.c9
-rw-r--r--procps/ps.c3
-rw-r--r--procps/top.c3
-rw-r--r--runit/runsv.c3
-rw-r--r--runit/runsvdir.c3
-rw-r--r--runit/sv.c3
-rw-r--r--runit/svlogd.c5
-rwxr-xr-xscripts/generate_BUFSIZ.sh114
-rw-r--r--selinux/setfiles.c2
-rw-r--r--sysklogd/klogd.c6
-rw-r--r--sysklogd/logread.c3
-rw-r--r--sysklogd/syslogd_and_logger.c1
-rw-r--r--util-linux/mdev.c3
-rw-r--r--util-linux/mkswap.c1
-rw-r--r--util-linux/more.c1
-rw-r--r--util-linux/mount.c3
-rw-r--r--util-linux/script.c10
-rw-r--r--util-linux/swaponoff.c3
-rw-r--r--util-linux/uevent.c3
-rw-r--r--util-linux/umount.c3
91 files changed, 414 insertions, 131 deletions
diff --git a/Makefile b/Makefile
index dab807805..75a33c1fb 100644
--- a/Makefile
+++ b/Makefile
@@ -610,7 +610,8 @@ quiet_cmd_busybox__ ?= LINK $@
610 "$(LDFLAGS) $(EXTRA_LDFLAGS)" \ 610 "$(LDFLAGS) $(EXTRA_LDFLAGS)" \
611 "$(core-y)" \ 611 "$(core-y)" \
612 "$(libs-y)" \ 612 "$(libs-y)" \
613 "$(LDLIBS)" 613 "$(LDLIBS)" \
614 && $(srctree)/scripts/generate_BUFSIZ.sh include/common_bufsiz.h
614 615
615# Generate System.map 616# Generate System.map
616quiet_cmd_sysmap = SYSMAP 617quiet_cmd_sysmap = SYSMAP
@@ -844,12 +845,15 @@ export CPPFLAGS_busybox.lds += -P -C -U$(ARCH)
844# Split autoconf.h into include/linux/config/* 845# Split autoconf.h into include/linux/config/*
845quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h 846quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h
846 cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs include/bbconfigopts.h include/bbconfigopts_bz2.h 847 cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs include/bbconfigopts.h include/bbconfigopts_bz2.h
848quiet_cmd_gen_common_bufsiz = GEN include/common_bufsiz.h
849 cmd_gen_common_bufsiz = $(srctree)/scripts/generate_BUFSIZ.sh include/common_bufsiz.h
847quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/* 850quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/*
848 cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config 851 cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config
849#bbox# piggybacked generation of few .h files 852#bbox# piggybacked generation of few .h files
850include/config/MARKER: scripts/basic/split-include include/autoconf.h 853include/config/MARKER: scripts/basic/split-include include/autoconf.h
851 $(call cmd,split_autoconf) 854 $(call cmd,split_autoconf)
852 $(call cmd,gen_bbconfigopts) 855 $(call cmd,gen_bbconfigopts)
856 $(call cmd,gen_common_bufsiz)
853 @touch $@ 857 @touch $@
854 858
855# Generate some files 859# Generate some files
@@ -965,6 +969,7 @@ CLEAN_FILES += busybox busybox_unstripped* busybox.links \
965MRPROPER_DIRS += include/config include2 969MRPROPER_DIRS += include/config include2
966MRPROPER_FILES += .config .config.old include/asm .version .old_version \ 970MRPROPER_FILES += .config .config.old include/asm .version .old_version \
967 include/NUM_APPLETS.h \ 971 include/NUM_APPLETS.h \
972 include/common_bufsiz.h \
968 include/autoconf.h \ 973 include/autoconf.h \
969 include/bbconfigopts.h \ 974 include/bbconfigopts.h \
970 include/bbconfigopts_bz2.h \ 975 include/bbconfigopts_bz2.h \
diff --git a/archival/cpio.c b/archival/cpio.c
index 82b3fe5ed..a3036e1ab 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -11,6 +11,7 @@
11 * Only supports new ASCII and CRC formats 11 * Only supports new ASCII and CRC formats
12 */ 12 */
13#include "libbb.h" 13#include "libbb.h"
14#include "common_bufsiz.h"
14#include "bb_archive.h" 15#include "bb_archive.h"
15 16
16//config:config CPIO 17//config:config CPIO
@@ -170,7 +171,7 @@ enum {
170struct globals { 171struct globals {
171 struct bb_uidgid_t owner_ugid; 172 struct bb_uidgid_t owner_ugid;
172} FIX_ALIASING; 173} FIX_ALIASING;
173#define G (*(struct globals*)&bb_common_bufsiz1) 174#define G (*(struct globals*)bb_common_bufsiz1)
174void BUG_cpio_globals_too_big(void); 175void BUG_cpio_globals_too_big(void);
175#define INIT_G() do { \ 176#define INIT_G() do { \
176 G.owner_ugid.uid = -1L; \ 177 G.owner_ugid.uid = -1L; \
diff --git a/archival/lzop.c b/archival/lzop.c
index a5fc01941..1371c9751 100644
--- a/archival/lzop.c
+++ b/archival/lzop.c
@@ -71,6 +71,7 @@
71//usage: "\n -F Don't store or verify checksum" 71//usage: "\n -F Don't store or verify checksum"
72 72
73#include "libbb.h" 73#include "libbb.h"
74#include "common_bufsiz.h"
74#include "bb_archive.h" 75#include "bb_archive.h"
75#include "liblzo_interface.h" 76#include "liblzo_interface.h"
76 77
@@ -443,7 +444,7 @@ struct globals {
443 chksum_t chksum_in; 444 chksum_t chksum_in;
444 chksum_t chksum_out; 445 chksum_t chksum_out;
445} FIX_ALIASING; 446} FIX_ALIASING;
446#define G (*(struct globals*)&bb_common_bufsiz1) 447#define G (*(struct globals*)bb_common_bufsiz1)
447#define INIT_G() do { } while (0) 448#define INIT_G() do { } while (0)
448//#define G (*ptr_to_globals) 449//#define G (*ptr_to_globals)
449//#define INIT_G() do { 450//#define INIT_G() do {
diff --git a/archival/rpm.c b/archival/rpm.c
index 105394481..079b7a95b 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -29,6 +29,7 @@
29//usage: "\n -qpc List config files" 29//usage: "\n -qpc List config files"
30 30
31#include "libbb.h" 31#include "libbb.h"
32#include "common_bufsiz.h"
32#include "bb_archive.h" 33#include "bb_archive.h"
33#include "rpm.h" 34#include "rpm.h"
34 35
@@ -93,7 +94,7 @@ struct globals {
93 rpm_index **mytags; 94 rpm_index **mytags;
94 int tagcount; 95 int tagcount;
95} FIX_ALIASING; 96} FIX_ALIASING;
96#define G (*(struct globals*)&bb_common_bufsiz1) 97#define G (*(struct globals*)bb_common_bufsiz1)
97#define INIT_G() do { } while (0) 98#define INIT_G() do { } while (0)
98 99
99static void extract_cpio(int fd, const char *source_rpm) 100static void extract_cpio(int fd, const char *source_rpm)
diff --git a/archival/tar.c b/archival/tar.c
index 23ac00e86..caf4363de 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -146,6 +146,7 @@
146 146
147#include <fnmatch.h> 147#include <fnmatch.h>
148#include "libbb.h" 148#include "libbb.h"
149#include "common_bufsiz.h"
149#include "bb_archive.h" 150#include "bb_archive.h"
150/* FIXME: Stop using this non-standard feature */ 151/* FIXME: Stop using this non-standard feature */
151#ifndef FNM_LEADING_DIR 152#ifndef FNM_LEADING_DIR
diff --git a/console-tools/dumpkmap.c b/console-tools/dumpkmap.c
index bf8d690da..6412dffc8 100644
--- a/console-tools/dumpkmap.c
+++ b/console-tools/dumpkmap.c
@@ -18,6 +18,7 @@
18//usage: "$ dumpkmap > keymap\n" 18//usage: "$ dumpkmap > keymap\n"
19 19
20#include "libbb.h" 20#include "libbb.h"
21#include "common_bufsiz.h"
21 22
22/* From <linux/kd.h> */ 23/* From <linux/kd.h> */
23struct kbentry { 24struct kbentry {
diff --git a/console-tools/resize.c b/console-tools/resize.c
index 4b0d63a03..ed80aa082 100644
--- a/console-tools/resize.c
+++ b/console-tools/resize.c
@@ -14,10 +14,11 @@
14//usage: "Resize the screen" 14//usage: "Resize the screen"
15 15
16#include "libbb.h" 16#include "libbb.h"
17#include "common_bufsiz.h"
17 18
18#define ESC "\033" 19#define ESC "\033"
19 20
20#define old_termios_p ((struct termios*)&bb_common_bufsiz1) 21#define old_termios_p ((struct termios*)bb_common_bufsiz1)
21 22
22static void 23static void
23onintr(int sig UNUSED_PARAM) 24onintr(int sig UNUSED_PARAM)
diff --git a/coreutils/catv.c b/coreutils/catv.c
index 6bb73ba63..801d2451d 100644
--- a/coreutils/catv.c
+++ b/coreutils/catv.c
@@ -19,6 +19,7 @@
19//usage: "\n -v Don't use ^x or M-x escapes" 19//usage: "\n -v Don't use ^x or M-x escapes"
20 20
21#include "libbb.h" 21#include "libbb.h"
22#include "common_bufsiz.h"
22 23
23#define CATV_OPT_e (1<<0) 24#define CATV_OPT_e (1<<0)
24#define CATV_OPT_t (1<<1) 25#define CATV_OPT_t (1<<1)
diff --git a/coreutils/cksum.c b/coreutils/cksum.c
index ac0b0c319..d8351e7c6 100644
--- a/coreutils/cksum.c
+++ b/coreutils/cksum.c
@@ -13,6 +13,7 @@
13//usage: "Calculate the CRC32 checksums of FILES" 13//usage: "Calculate the CRC32 checksums of FILES"
14 14
15#include "libbb.h" 15#include "libbb.h"
16#include "common_bufsiz.h"
16 17
17/* This is a NOEXEC applet. Be very careful! */ 18/* This is a NOEXEC applet. Be very careful! */
18 19
@@ -42,8 +43,9 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
42 crc = 0; 43 crc = 0;
43 length = 0; 44 length = 0;
44 45
45#define read_buf bb_common_bufsiz1 46#define read_buf bb_common_bufsiz1
46 while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) { 47#define sizeof_read_buf COMMON_BUFSIZE
48 while ((bytes_read = safe_read(fd, read_buf, sizeof_read_buf)) > 0) {
47 length += bytes_read; 49 length += bytes_read;
48 crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table); 50 crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
49 } 51 }
diff --git a/coreutils/date.c b/coreutils/date.c
index 7965775fe..59b4b8f2a 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -138,6 +138,7 @@
138//usage: "Wed Apr 12 18:52:41 MDT 2000\n" 138//usage: "Wed Apr 12 18:52:41 MDT 2000\n"
139 139
140#include "libbb.h" 140#include "libbb.h"
141#include "common_bufsiz.h"
141#if ENABLE_FEATURE_DATE_NANO 142#if ENABLE_FEATURE_DATE_NANO
142# include <sys/syscall.h> 143# include <sys/syscall.h>
143#endif 144#endif
@@ -367,7 +368,8 @@ int date_main(int argc UNUSED_PARAM, char **argv)
367 } 368 }
368#endif 369#endif
369 370
370#define date_buf bb_common_bufsiz1 371#define date_buf bb_common_bufsiz1
372#define sizeof_date_buf COMMON_BUFSIZE
371 if (*fmt_dt2str == '\0') { 373 if (*fmt_dt2str == '\0') {
372 /* With no format string, just print a blank line */ 374 /* With no format string, just print a blank line */
373 date_buf[0] = '\0'; 375 date_buf[0] = '\0';
@@ -377,7 +379,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
377 fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S"; 379 fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
378 } 380 }
379 /* Generate output string */ 381 /* Generate output string */
380 strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time); 382 strftime(date_buf, sizeof_date_buf, fmt_dt2str, &tm_time);
381 } 383 }
382 puts(date_buf); 384 puts(date_buf);
383 385
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 0c0ea07b9..a5b8882a0 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -91,6 +91,7 @@
91//usage: "4+0 records out\n" 91//usage: "4+0 records out\n"
92 92
93#include "libbb.h" 93#include "libbb.h"
94#include "common_bufsiz.h"
94 95
95/* This is a NOEXEC applet. Be very careful! */ 96/* This is a NOEXEC applet. Be very careful! */
96 97
@@ -108,7 +109,7 @@ struct globals {
108#endif 109#endif
109 int flags; 110 int flags;
110} FIX_ALIASING; 111} FIX_ALIASING;
111#define G (*(struct globals*)&bb_common_bufsiz1) 112#define G (*(struct globals*)bb_common_bufsiz1)
112#define INIT_G() do { \ 113#define INIT_G() do { \
113 /* we have to zero it out because of NOEXEC */ \ 114 /* we have to zero it out because of NOEXEC */ \
114 memset(&G, 0, sizeof(G)); \ 115 memset(&G, 0, sizeof(G)); \
diff --git a/coreutils/du.c b/coreutils/du.c
index 1889c16bb..3d6777670 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -58,6 +58,7 @@
58//usage: "2417 .\n" 58//usage: "2417 .\n"
59 59
60#include "libbb.h" 60#include "libbb.h"
61#include "common_bufsiz.h"
61 62
62enum { 63enum {
63 OPT_a_files_too = (1 << 0), 64 OPT_a_files_too = (1 << 0),
@@ -85,7 +86,7 @@ struct globals {
85 int du_depth; 86 int du_depth;
86 dev_t dir_dev; 87 dev_t dir_dev;
87} FIX_ALIASING; 88} FIX_ALIASING;
88#define G (*(struct globals*)&bb_common_bufsiz1) 89#define G (*(struct globals*)bb_common_bufsiz1)
89#define INIT_G() do { } while (0) 90#define INIT_G() do { } while (0)
90 91
91 92
diff --git a/coreutils/expr.c b/coreutils/expr.c
index c986f9327..59a66d9c5 100644
--- a/coreutils/expr.c
+++ b/coreutils/expr.c
@@ -61,6 +61,7 @@
61//usage: "of characters matched or 0." 61//usage: "of characters matched or 0."
62 62
63#include "libbb.h" 63#include "libbb.h"
64#include "common_bufsiz.h"
64#include "xregex.h" 65#include "xregex.h"
65 66
66#if ENABLE_EXPR_MATH_SUPPORT_64 67#if ENABLE_EXPR_MATH_SUPPORT_64
@@ -99,7 +100,7 @@ typedef struct valinfo VALUE;
99struct globals { 100struct globals {
100 char **args; 101 char **args;
101} FIX_ALIASING; 102} FIX_ALIASING;
102#define G (*(struct globals*)&bb_common_bufsiz1) 103#define G (*(struct globals*)bb_common_bufsiz1)
103#define INIT_G() do { } while (0) 104#define INIT_G() do { } while (0)
104 105
105/* forward declarations */ 106/* forward declarations */
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 20bd61860..e8c3e0490 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -93,6 +93,7 @@
93//usage: ) 93//usage: )
94 94
95#include "libbb.h" 95#include "libbb.h"
96#include "common_bufsiz.h"
96#include "unicode.h" 97#include "unicode.h"
97 98
98 99
@@ -365,7 +366,7 @@ struct globals {
365 time_t current_time_t; 366 time_t current_time_t;
366#endif 367#endif
367} FIX_ALIASING; 368} FIX_ALIASING;
368#define G (*(struct globals*)&bb_common_bufsiz1) 369#define G (*(struct globals*)bb_common_bufsiz1)
369#define INIT_G() do { \ 370#define INIT_G() do { \
370 /* we have to zero it out because of NOEXEC */ \ 371 /* we have to zero it out because of NOEXEC */ \
371 memset(&G, 0, sizeof(G)); \ 372 memset(&G, 0, sizeof(G)); \
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index f47f84b54..1e252caf0 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -20,6 +20,7 @@
20 20
21 21
22/* #include "libbb.h" - done in od.c */ 22/* #include "libbb.h" - done in od.c */
23#include "common_bufsiz.h"
23#define assert(a) ((void)0) 24#define assert(a) ((void)0)
24 25
25 26
@@ -214,7 +215,7 @@ struct globals {
214#if !ENABLE_LONG_OPTS 215#if !ENABLE_LONG_OPTS
215enum { G_pseudo_offset = 0 }; 216enum { G_pseudo_offset = 0 };
216#endif 217#endif
217#define G (*(struct globals*)&bb_common_bufsiz1) 218#define G (*(struct globals*)bb_common_bufsiz1)
218#define INIT_G() do { \ 219#define INIT_G() do { \
219 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ 220 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
220 G.bytes_per_block = 32; \ 221 G.bytes_per_block = 32; \
diff --git a/coreutils/split.c b/coreutils/split.c
index 1e1673efb..b2da74e27 100644
--- a/coreutils/split.c
+++ b/coreutils/split.c
@@ -22,6 +22,7 @@
22//usage: "$ cat TODO | split -a 2 -l 2 TODO_\n" 22//usage: "$ cat TODO | split -a 2 -l 2 TODO_\n"
23 23
24#include "libbb.h" 24#include "libbb.h"
25#include "common_bufsiz.h"
25 26
26#if ENABLE_FEATURE_SPLIT_FANCY 27#if ENABLE_FEATURE_SPLIT_FANCY
27static const struct suffix_mult split_suffixes[] = { 28static const struct suffix_mult split_suffixes[] = {
diff --git a/coreutils/stat.c b/coreutils/stat.c
index 1a490fef7..78df9c948 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -103,6 +103,7 @@
103//usage: ) 103//usage: )
104 104
105#include "libbb.h" 105#include "libbb.h"
106#include "common_bufsiz.h"
106 107
107enum { 108enum {
108 OPT_TERSE = (1 << 0), 109 OPT_TERSE = (1 << 0),
@@ -157,9 +158,10 @@ static const char *human_time(time_t t)
157 /* coreutils 6.3 compat: */ 158 /* coreutils 6.3 compat: */
158 159
159 /*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;*/
160#define buf bb_common_bufsiz1 161#define buf bb_common_bufsiz1
162#define sizeof_buf COMMON_BUFSIZE
161 163
162 strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &t), ".000000000"); 164 strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof_buf, &t), ".000000000");
163 return buf; 165 return buf;
164#undef buf 166#undef buf
165} 167}
diff --git a/coreutils/stty.c b/coreutils/stty.c
index b63b0b91a..0e32fc898 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -32,6 +32,7 @@
32//usage: "\n [SETTING] See manpage" 32//usage: "\n [SETTING] See manpage"
33 33
34#include "libbb.h" 34#include "libbb.h"
35#include "common_bufsiz.h"
35 36
36#ifndef _POSIX_VDISABLE 37#ifndef _POSIX_VDISABLE
37# define _POSIX_VDISABLE ((unsigned char) 0) 38# define _POSIX_VDISABLE ((unsigned char) 0)
@@ -775,7 +776,7 @@ struct globals {
775 unsigned current_col; 776 unsigned current_col;
776 char buf[10]; 777 char buf[10];
777} FIX_ALIASING; 778} FIX_ALIASING;
778#define G (*(struct globals*)&bb_common_bufsiz1) 779#define G (*(struct globals*)bb_common_bufsiz1)
779#define INIT_G() do { \ 780#define INIT_G() do { \
780 G.device_name = bb_msg_standard_input; \ 781 G.device_name = bb_msg_standard_input; \
781 G.max_col = 80; \ 782 G.max_col = 80; \
diff --git a/coreutils/sum.c b/coreutils/sum.c
index deb068e10..cc6677221 100644
--- a/coreutils/sum.c
+++ b/coreutils/sum.c
@@ -21,6 +21,7 @@
21//usage: "\n -s Use System V sum algorithm (512byte blocks)" 21//usage: "\n -s Use System V sum algorithm (512byte blocks)"
22 22
23#include "libbb.h" 23#include "libbb.h"
24#include "common_bufsiz.h"
24 25
25enum { SUM_BSD, PRINT_NAME, SUM_SYSV }; 26enum { SUM_BSD, PRINT_NAME, SUM_SYSV };
26 27
@@ -41,7 +42,7 @@ static unsigned sum_file(const char *file, unsigned type)
41 return 0; 42 return 0;
42 43
43 while (1) { 44 while (1) {
44 size_t bytes_read = safe_read(fd, buf, BUFSIZ); 45 size_t bytes_read = safe_read(fd, buf, COMMON_BUFSIZE);
45 46
46 if ((ssize_t)bytes_read <= 0) { 47 if ((ssize_t)bytes_read <= 0) {
47 r = (fd && close(fd) != 0); 48 r = (fd && close(fd) != 0);
diff --git a/coreutils/tail.c b/coreutils/tail.c
index e352ab627..cdc9fb66a 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -49,12 +49,13 @@
49//usage: "nameserver 10.0.0.1\n" 49//usage: "nameserver 10.0.0.1\n"
50 50
51#include "libbb.h" 51#include "libbb.h"
52#include "common_bufsiz.h"
52 53
53struct globals { 54struct globals {
54 bool from_top; 55 bool from_top;
55 bool exitcode; 56 bool exitcode;
56} FIX_ALIASING; 57} FIX_ALIASING;
57#define G (*(struct globals*)&bb_common_bufsiz1) 58#define G (*(struct globals*)bb_common_bufsiz1)
58#define INIT_G() do { } while (0) 59#define INIT_G() do { } while (0)
59 60
60static void tail_xprint_header(const char *fmt, const char *filename) 61static void tail_xprint_header(const char *fmt, const char *filename)
diff --git a/coreutils/tee.c b/coreutils/tee.c
index 48cc0508f..a0e177cbc 100644
--- a/coreutils/tee.c
+++ b/coreutils/tee.c
@@ -23,6 +23,7 @@
23//usage: "Hello\n" 23//usage: "Hello\n"
24 24
25#include "libbb.h" 25#include "libbb.h"
26#include "common_bufsiz.h"
26 27
27int tee_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 28int tee_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
28int tee_main(int argc, char **argv) 29int tee_main(int argc, char **argv)
@@ -36,7 +37,8 @@ int tee_main(int argc, char **argv)
36//TODO: make unconditional 37//TODO: make unconditional
37#if ENABLE_FEATURE_TEE_USE_BLOCK_IO 38#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
38 ssize_t c; 39 ssize_t c;
39# define buf bb_common_bufsiz1 40# define buf bb_common_bufsiz1
41# define sizeof_buf COMMON_BUFSIZE
40#else 42#else
41 int c; 43 int c;
42#endif 44#endif
@@ -79,7 +81,7 @@ int tee_main(int argc, char **argv)
79 /* names[0] will be filled later */ 81 /* names[0] will be filled later */
80 82
81#if ENABLE_FEATURE_TEE_USE_BLOCK_IO 83#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
82 while ((c = safe_read(STDIN_FILENO, buf, sizeof(buf))) > 0) { 84 while ((c = safe_read(STDIN_FILENO, buf, sizeof_buf)) > 0) {
83 fp = files; 85 fp = files;
84 do 86 do
85 fwrite(buf, 1, c, *fp); 87 fwrite(buf, 1, c, *fp);
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c
index 13617c6e1..a5e53576c 100644
--- a/debianutils/run_parts.c
+++ b/debianutils/run_parts.c
@@ -89,13 +89,14 @@
89//usage: "+ shutdown -h +4m" 89//usage: "+ shutdown -h +4m"
90 90
91#include "libbb.h" 91#include "libbb.h"
92#include "common_bufsiz.h"
92 93
93struct globals { 94struct globals {
94 char **names; 95 char **names;
95 int cur; 96 int cur;
96 char *cmd[2 /* using 1 provokes compiler warning */]; 97 char *cmd[2 /* using 1 provokes compiler warning */];
97} FIX_ALIASING; 98} FIX_ALIASING;
98#define G (*(struct globals*)&bb_common_bufsiz1) 99#define G (*(struct globals*)bb_common_bufsiz1)
99#define names (G.names) 100#define names (G.names)
100#define cur (G.cur ) 101#define cur (G.cur )
101#define cmd (G.cmd ) 102#define cmd (G.cmd )
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index d7c730f45..6b8d53b13 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -153,6 +153,7 @@ Misc options:
153/* Override ENABLE_FEATURE_PIDFILE */ 153/* Override ENABLE_FEATURE_PIDFILE */
154#define WANT_PIDFILE 1 154#define WANT_PIDFILE 1
155#include "libbb.h" 155#include "libbb.h"
156#include "common_bufsiz.h"
156 157
157struct pid_list { 158struct pid_list {
158 struct pid_list *next; 159 struct pid_list *next;
@@ -191,7 +192,7 @@ struct globals {
191 int user_id; 192 int user_id;
192 smallint signal_nr; 193 smallint signal_nr;
193} FIX_ALIASING; 194} FIX_ALIASING;
194#define G (*(struct globals*)&bb_common_bufsiz1) 195#define G (*(struct globals*)bb_common_bufsiz1)
195#define userspec (G.userspec ) 196#define userspec (G.userspec )
196#define cmdname (G.cmdname ) 197#define cmdname (G.cmdname )
197#define execname (G.execname ) 198#define execname (G.execname )
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c
index 987d97528..b534568c2 100644
--- a/e2fsprogs/fsck.c
+++ b/e2fsprogs/fsck.c
@@ -60,6 +60,7 @@
60//usage: "\n -t TYPE List of filesystem types to check" 60//usage: "\n -t TYPE List of filesystem types to check"
61 61
62#include "libbb.h" 62#include "libbb.h"
63#include "common_bufsiz.h"
63 64
64/* "progress indicator" code is somewhat buggy and ext[23] specific. 65/* "progress indicator" code is somewhat buggy and ext[23] specific.
65 * We should be filesystem agnostic. IOW: there should be a well-defined 66 * We should be filesystem agnostic. IOW: there should be a well-defined
@@ -169,7 +170,7 @@ struct globals {
169 struct fs_info *filesys_last; 170 struct fs_info *filesys_last;
170 struct fsck_instance *instance_list; 171 struct fsck_instance *instance_list;
171} FIX_ALIASING; 172} FIX_ALIASING;
172#define G (*(struct globals*)&bb_common_bufsiz1) 173#define G (*(struct globals*)bb_common_bufsiz1)
173#define INIT_G() do { \ 174#define INIT_G() do { \
174 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ 175 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
175} while (0) 176} while (0)
diff --git a/editors/diff.c b/editors/diff.c
index a892cfdf2..3c8e9074a 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -125,6 +125,7 @@
125//usage: "\n -w Ignore all whitespace" 125//usage: "\n -w Ignore all whitespace"
126 126
127#include "libbb.h" 127#include "libbb.h"
128#include "common_bufsiz.h"
128 129
129#if 0 130#if 0
130# define dbg_error_msg(...) bb_error_msg(__VA_ARGS__) 131# define dbg_error_msg(...) bb_error_msg(__VA_ARGS__)
diff --git a/editors/ed.c b/editors/ed.c
index a4c419099..8da7b1dd5 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -23,6 +23,7 @@
23//usage:#define ed_full_usage "" 23//usage:#define ed_full_usage ""
24 24
25#include "libbb.h" 25#include "libbb.h"
26#include "common_bufsiz.h"
26 27
27typedef struct LINE { 28typedef struct LINE {
28 struct LINE *next; 29 struct LINE *next;
@@ -32,11 +33,12 @@ typedef struct LINE {
32} LINE; 33} LINE;
33 34
34 35
35#define searchString bb_common_bufsiz1 36#define searchString bb_common_bufsiz1
37#define sizeof_searchString COMMON_BUFSIZE
36 38
37enum { 39enum {
38 USERSIZE = sizeof(searchString) > 1024 ? 1024 40 USERSIZE = sizeof_searchString > 1024 ? 1024
39 : sizeof(searchString) - 1, /* max line length typed in by user */ 41 : sizeof_searchString - 1, /* max line length typed in by user */
40 INITBUF_SIZE = 1024, /* initial buffer size */ 42 INITBUF_SIZE = 1024, /* initial buffer size */
41}; 43};
42 44
diff --git a/editors/sed.c b/editors/sed.c
index 9c4c8e148..330190e78 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -86,6 +86,7 @@
86//usage: "bar\n" 86//usage: "bar\n"
87 87
88#include "libbb.h" 88#include "libbb.h"
89#include "common_bufsiz.h"
89#include "xregex.h" 90#include "xregex.h"
90 91
91#if 0 92#if 0
@@ -161,7 +162,7 @@ struct globals {
161 int len; /* Space allocated */ 162 int len; /* Space allocated */
162 } pipeline; 163 } pipeline;
163} FIX_ALIASING; 164} FIX_ALIASING;
164#define G (*(struct globals*)&bb_common_bufsiz1) 165#define G (*(struct globals*)bb_common_bufsiz1)
165#define INIT_G() do { \ 166#define INIT_G() do { \
166 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ 167 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
167 G.sed_cmd_tail = &G.sed_cmd_head; \ 168 G.sed_cmd_tail = &G.sed_cmd_head; \
diff --git a/findutils/find.c b/findutils/find.c
index a0d4853de..32d830337 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -342,6 +342,7 @@
342 342
343#include <fnmatch.h> 343#include <fnmatch.h>
344#include "libbb.h" 344#include "libbb.h"
345#include "common_bufsiz.h"
345#if ENABLE_FEATURE_FIND_REGEX 346#if ENABLE_FEATURE_FIND_REGEX
346# include "xregex.h" 347# include "xregex.h"
347#endif 348#endif
@@ -421,7 +422,7 @@ struct globals {
421 recurse_flags_t recurse_flags; 422 recurse_flags_t recurse_flags;
422 IF_FEATURE_FIND_EXEC_PLUS(unsigned max_argv_len;) 423 IF_FEATURE_FIND_EXEC_PLUS(unsigned max_argv_len;)
423} FIX_ALIASING; 424} FIX_ALIASING;
424#define G (*(struct globals*)&bb_common_bufsiz1) 425#define G (*(struct globals*)bb_common_bufsiz1)
425#define INIT_G() do { \ 426#define INIT_G() do { \
426 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ 427 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
427 /* we have to zero it out because of NOEXEC */ \ 428 /* we have to zero it out because of NOEXEC */ \
diff --git a/findutils/grep.c b/findutils/grep.c
index dece90c58..a669ac80b 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -58,6 +58,7 @@
58//config: Print the specified number of context lines (-C). 58//config: Print the specified number of context lines (-C).
59 59
60#include "libbb.h" 60#include "libbb.h"
61#include "common_bufsiz.h"
61#include "xregex.h" 62#include "xregex.h"
62 63
63 64
@@ -201,7 +202,7 @@ struct globals {
201 llist_t *pattern_head; /* growable list of patterns to match */ 202 llist_t *pattern_head; /* growable list of patterns to match */
202 const char *cur_file; /* the current file we are reading */ 203 const char *cur_file; /* the current file we are reading */
203} FIX_ALIASING; 204} FIX_ALIASING;
204#define G (*(struct globals*)&bb_common_bufsiz1) 205#define G (*(struct globals*)bb_common_bufsiz1)
205#define INIT_G() do { \ 206#define INIT_G() do { \
206 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ 207 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
207} while (0) 208} while (0)
diff --git a/findutils/xargs.c b/findutils/xargs.c
index 69f83b128..bfbd94960 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -66,6 +66,7 @@
66//kbuild:lib-$(CONFIG_XARGS) += xargs.o 66//kbuild:lib-$(CONFIG_XARGS) += xargs.o
67 67
68#include "libbb.h" 68#include "libbb.h"
69#include "common_bufsiz.h"
69 70
70/* This is a NOEXEC applet. Be very careful! */ 71/* This is a NOEXEC applet. Be very careful! */
71 72
@@ -100,7 +101,7 @@ struct globals {
100 const char *eof_str; 101 const char *eof_str;
101 int idx; 102 int idx;
102} FIX_ALIASING; 103} FIX_ALIASING;
103#define G (*(struct globals*)&bb_common_bufsiz1) 104#define G (*(struct globals*)bb_common_bufsiz1)
104#define INIT_G() do { \ 105#define INIT_G() do { \
105 G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \ 106 G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \
106 IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \ 107 IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \
diff --git a/include/libbb.h b/include/libbb.h
index 111dd66e0..fd40ef74c 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1827,10 +1827,6 @@ extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr
1827extern const int const_int_0; 1827extern const int const_int_0;
1828//extern const int const_int_1; 1828//extern const int const_int_1;
1829 1829
1830
1831/* Providing hard guarantee on minimum size (think of BUFSIZ == 128) */
1832enum { COMMON_BUFSIZE = (BUFSIZ >= 256*sizeof(void*) ? BUFSIZ+1 : 256*sizeof(void*)) };
1833extern char bb_common_bufsiz1[COMMON_BUFSIZE];
1834/* This struct is deliberately not defined. */ 1830/* This struct is deliberately not defined. */
1835/* See docs/keep_data_small.txt */ 1831/* See docs/keep_data_small.txt */
1836struct globals; 1832struct globals;
diff --git a/init/bootchartd.c b/init/bootchartd.c
index c7388c99e..5101b28ae 100644
--- a/init/bootchartd.c
+++ b/init/bootchartd.c
@@ -47,6 +47,7 @@
47//config: and /etc/bootchartd.conf files. 47//config: and /etc/bootchartd.conf files.
48 48
49#include "libbb.h" 49#include "libbb.h"
50#include "common_bufsiz.h"
50/* After libbb.h, since it needs sys/types.h on some systems */ 51/* After libbb.h, since it needs sys/types.h on some systems */
51#include <sys/utsname.h> 52#include <sys/utsname.h>
52 53
@@ -115,7 +116,7 @@
115struct globals { 116struct globals {
116 char jiffy_line[COMMON_BUFSIZE]; 117 char jiffy_line[COMMON_BUFSIZE];
117} FIX_ALIASING; 118} FIX_ALIASING;
118#define G (*(struct globals*)&bb_common_bufsiz1) 119#define G (*(struct globals*)bb_common_bufsiz1)
119#define INIT_G() do { } while (0) 120#define INIT_G() do { } while (0)
120 121
121static void dump_file(FILE *fp, const char *filename) 122static void dump_file(FILE *fp, const char *filename)
diff --git a/libbb/common_bufsiz.c b/libbb/common_bufsiz.c
new file mode 100644
index 000000000..c16c361c9
--- /dev/null
+++ b/libbb/common_bufsiz.c
@@ -0,0 +1,74 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) 2016 Denys Vlasenko
6 *
7 * Licensed under GPLv2, see file LICENSE in this source tree.
8 */
9//config:config FEATURE_USE_BSS_TAIL
10//config: bool "Use the end of BSS page"
11//config: default n
12//config: help
13//config: Attempt to reclaim a small unused part of BSS.
14//config:
15//config: Executables have the following parts:
16//config: = read-only executable code and constants, also known as "text"
17//config: = read-write data
18//config: = non-initialized (zeroed on demand) data, also known as "bss"
19//config:
20//config: At link time, "text" is padded to a full page. At runtime, all "text"
21//config: pages are mapped RO and executable.
22//config: "Data" starts on the next page boundary, but is not padded
23//config: to a full page at the end. "Bss" starts wherever "data" ends.
24//config: At runtime, "data" pages are mapped RW and they are file-backed
25//config: (this includes a small portion of "bss" which may live in the last
26//config: partial page of "data").
27//config: Pages which are fully in "bss" are mapped to anonymous memory.
28//config:
29//config: "Bss" end is usually not page-aligned. There is an unused space
30//config: in the last page. Linker marks its start with the "_end" symbol.
31//config:
32//config: This option will attempt to use that space for bb_common_bufsiz1[]
33//config: array. If it fits after _end, it will be used, and COMMON_BUFSIZE
34//config: will be enlarged from its guaranteed minimum size of 1 kbyte.
35//config: This may require recompilation a second time, since value of _end
36//config: is known only after final link.
37//config:
38//config: If you are getting a build error like this:
39//config: appletlib.c:(.text.main+0xd): undefined reference to '_end'
40//config: disable this option.
41
42//kbuild:lib-y += common_bufsiz.o
43
44#include "libbb.h"
45#include "common_bufsiz.h"
46
47#if !ENABLE_FEATURE_USE_BSS_TAIL
48
49/* We use it for "global" data via *(struct global*)bb_common_bufsiz1.
50 * Since gcc insists on aligning struct global's members, it would be a pity
51 * (and an alignment fault on some CPUs) to mess it up. */
52char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));
53
54#else
55
56# ifndef setup_common_bufsiz
57/*
58 * It is not a "((void)0)" macro. It means we have to provide this function.
59 */
60char* bb_common_bufsiz1;
61char* setup_common_bufsiz(void)
62{
63 if (!bb_common_bufsiz1)
64 bb_common_bufsiz1 = xzalloc(COMMON_BUFSIZE);
65 return bb_common_bufsiz1;
66}
67# else
68# ifndef bb_common_bufsiz1
69 /* bb_common_bufsiz1[] is not aliased to _end[] */
70char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));
71# endif
72# endif
73
74#endif
diff --git a/libbb/messages.c b/libbb/messages.c
index 23e440bcd..cb0836de8 100644
--- a/libbb/messages.c
+++ b/libbb/messages.c
@@ -59,8 +59,3 @@ const char bb_path_wtmp_file[] ALIGN1 =
59# error unknown path to wtmp file 59# error unknown path to wtmp file
60# endif 60# endif
61#endif 61#endif
62
63/* We use it for "global" data via *(struct global*)&bb_common_bufsiz1.
64 * Since gcc insists on aligning struct global's members, it would be a pity
65 * (and an alignment fault on some CPUs) to mess it up. */
66char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));
diff --git a/loginutils/login.c b/loginutils/login.c
index 4ebc18502..ea7c5a23d 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -62,6 +62,7 @@
62//usage: "\n -p Preserve environment" 62//usage: "\n -p Preserve environment"
63 63
64#include "libbb.h" 64#include "libbb.h"
65#include "common_bufsiz.h"
65#include <syslog.h> 66#include <syslog.h>
66#include <sys/resource.h> 67#include <sys/resource.h>
67 68
@@ -138,7 +139,7 @@ enum {
138struct globals { 139struct globals {
139 struct termios tty_attrs; 140 struct termios tty_attrs;
140} FIX_ALIASING; 141} FIX_ALIASING;
141#define G (*(struct globals*)&bb_common_bufsiz1) 142#define G (*(struct globals*)bb_common_bufsiz1)
142#define INIT_G() do { } while (0) 143#define INIT_G() do { } while (0)
143 144
144 145
diff --git a/miscutils/chat.c b/miscutils/chat.c
index bd2abc24a..25850dd20 100644
--- a/miscutils/chat.c
+++ b/miscutils/chat.c
@@ -17,6 +17,7 @@
17//usage: "chat '' ATZ OK ATD123456 CONNECT '' ogin: pppuser word: ppppass '~'" 17//usage: "chat '' ATZ OK ATD123456 CONNECT '' ogin: pppuser word: ppppass '~'"
18 18
19#include "libbb.h" 19#include "libbb.h"
20#include "common_bufsiz.h"
20 21
21// default timeout: 45 sec 22// default timeout: 45 sec
22#define DEFAULT_CHAT_TIMEOUT 45*1000 23#define DEFAULT_CHAT_TIMEOUT 45*1000
diff --git a/miscutils/conspy.c b/miscutils/conspy.c
index 1a46a4340..0d96a5f9a 100644
--- a/miscutils/conspy.c
+++ b/miscutils/conspy.c
@@ -42,6 +42,7 @@
42//usage: "\n -y LINE Starting line" 42//usage: "\n -y LINE Starting line"
43 43
44#include "libbb.h" 44#include "libbb.h"
45#include "common_bufsiz.h"
45#include <sys/kd.h> 46#include <sys/kd.h>
46 47
47#define ESC "\033" 48#define ESC "\033"
@@ -363,7 +364,8 @@ int conspy_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
363int conspy_main(int argc UNUSED_PARAM, char **argv) 364int conspy_main(int argc UNUSED_PARAM, char **argv)
364{ 365{
365 char tty_name[sizeof(DEV_TTY "NN")]; 366 char tty_name[sizeof(DEV_TTY "NN")];
366#define keybuf bb_common_bufsiz1 367#define keybuf bb_common_bufsiz1
368#define sizeof_keybuf COMMON_BUFSIZE
367 struct termios termbuf; 369 struct termios termbuf;
368 unsigned opts; 370 unsigned opts;
369 unsigned ttynum; 371 unsigned ttynum;
@@ -513,7 +515,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv)
513 default: 515 default:
514 // Read the keys pressed 516 // Read the keys pressed
515 k = keybuf + G.key_count; 517 k = keybuf + G.key_count;
516 bytes_read = read(G.kbd_fd, k, sizeof(keybuf) - G.key_count); 518 bytes_read = read(G.kbd_fd, k, sizeof_keybuf - G.key_count);
517 if (bytes_read < 0) 519 if (bytes_read < 0)
518 goto abort; 520 goto abort;
519 521
diff --git a/miscutils/crond.c b/miscutils/crond.c
index eb327f855..8536d43c5 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -60,6 +60,7 @@
60//usage: "\n -c DIR Cron dir. Default:"CONFIG_FEATURE_CROND_DIR"/crontabs" 60//usage: "\n -c DIR Cron dir. Default:"CONFIG_FEATURE_CROND_DIR"/crontabs"
61 61
62#include "libbb.h" 62#include "libbb.h"
63#include "common_bufsiz.h"
63#include <syslog.h> 64#include <syslog.h>
64 65
65/* glibc frees previous setenv'ed value when we do next setenv() 66/* glibc frees previous setenv'ed value when we do next setenv()
@@ -140,7 +141,7 @@ struct globals {
140 char *env_var_logname; 141 char *env_var_logname;
141#endif 142#endif
142} FIX_ALIASING; 143} FIX_ALIASING;
143#define G (*(struct globals*)&bb_common_bufsiz1) 144#define G (*(struct globals*)bb_common_bufsiz1)
144#define INIT_G() do { \ 145#define INIT_G() do { \
145 G.log_level = 8; \ 146 G.log_level = 8; \
146 G.crontab_dir_name = CRONTABS; \ 147 G.crontab_dir_name = CRONTABS; \
diff --git a/miscutils/dc.c b/miscutils/dc.c
index 9c74172ba..3fbb89f5b 100644
--- a/miscutils/dc.c
+++ b/miscutils/dc.c
@@ -4,6 +4,7 @@
4 */ 4 */
5 5
6#include "libbb.h" 6#include "libbb.h"
7#include "common_bufsiz.h"
7#include <math.h> 8#include <math.h>
8 9
9//usage:#define dc_trivial_usage 10//usage:#define dc_trivial_usage
@@ -47,7 +48,7 @@ struct globals {
47 double stack[1]; 48 double stack[1];
48} FIX_ALIASING; 49} FIX_ALIASING;
49enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof(double) }; 50enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof(double) };
50#define G (*(struct globals*)&bb_common_bufsiz1) 51#define G (*(struct globals*)bb_common_bufsiz1)
51#define pointer (G.pointer ) 52#define pointer (G.pointer )
52#define base (G.base ) 53#define base (G.base )
53#define stack (G.stack ) 54#define stack (G.stack )
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c
index 9557c41db..b26ad2c15 100644
--- a/miscutils/fbsplash.c
+++ b/miscutils/fbsplash.c
@@ -34,6 +34,7 @@
34//usage: "\n commands: 'NN' (% for progress bar) or 'exit'" 34//usage: "\n commands: 'NN' (% for progress bar) or 'exit'"
35 35
36#include "libbb.h" 36#include "libbb.h"
37#include "common_bufsiz.h"
37#include <linux/fb.h> 38#include <linux/fb.h>
38 39
39/* If you want logging messages on /tmp/fbsplash.log... */ 40/* If you want logging messages on /tmp/fbsplash.log... */
@@ -372,11 +373,12 @@ static void fb_drawimage(void)
372 * - A raster of Width * Height pixels in triplets of rgb 373 * - A raster of Width * Height pixels in triplets of rgb
373 * 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)
374 */ 375 */
375#define concat_buf bb_common_bufsiz1 376#define concat_buf bb_common_bufsiz1
377#define sizeof_concat_buf COMMON_BUFSIZE
376 read_ptr = concat_buf; 378 read_ptr = concat_buf;
377 while (1) { 379 while (1) {
378 int w, h, max_color_val; 380 int w, h, max_color_val;
379 int rem = concat_buf + sizeof(concat_buf) - read_ptr; 381 int rem = concat_buf + sizeof_concat_buf - read_ptr;
380 if (rem < 2 382 if (rem < 2
381 || fgets(read_ptr, rem, theme_file) == NULL 383 || fgets(read_ptr, rem, theme_file) == NULL
382 ) { 384 ) {
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index 8e201ac35..9e141de2f 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -63,6 +63,7 @@
63//usage: "\n -z Reread partition table" 63//usage: "\n -z Reread partition table"
64 64
65#include "libbb.h" 65#include "libbb.h"
66#include "common_bufsiz.h"
66/* must be _after_ libbb.h: */ 67/* must be _after_ libbb.h: */
67#include <linux/hdreg.h> 68#include <linux/hdreg.h>
68#include <sys/mount.h> 69#include <sys/mount.h>
@@ -367,7 +368,7 @@ struct globals {
367 unsigned char flushcache[4] = { WIN_FLUSHCACHE, 0, 0, 0 }; 368 unsigned char flushcache[4] = { WIN_FLUSHCACHE, 0, 0, 0 };
368#endif 369#endif
369} FIX_ALIASING; 370} FIX_ALIASING;
370#define G (*(struct globals*)&bb_common_bufsiz1) 371#define G (*(struct globals*)bb_common_bufsiz1)
371#define get_identity (G.get_identity ) 372#define get_identity (G.get_identity )
372#define get_geom (G.get_geom ) 373#define get_geom (G.get_geom )
373#define do_flush (G.do_flush ) 374#define do_flush (G.do_flush )
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c
index aa1c7c5cc..57bb72ae7 100644
--- a/miscutils/i2c_tools.c
+++ b/miscutils/i2c_tools.c
@@ -60,6 +60,7 @@
60 */ 60 */
61 61
62#include "libbb.h" 62#include "libbb.h"
63#include "common_bufsiz.h"
63 64
64#include <linux/i2c.h> 65#include <linux/i2c.h>
65#include <linux/i2c-dev.h> 66#include <linux/i2c-dev.h>
diff --git a/miscutils/inotifyd.c b/miscutils/inotifyd.c
index 908d657fd..1d28e8f99 100644
--- a/miscutils/inotifyd.c
+++ b/miscutils/inotifyd.c
@@ -56,6 +56,7 @@
56//usage: "\nWhen x event happens for all FILEs, inotifyd exits." 56//usage: "\nWhen x event happens for all FILEs, inotifyd exits."
57 57
58#include "libbb.h" 58#include "libbb.h"
59#include "common_bufsiz.h"
59#include <sys/inotify.h> 60#include <sys/inotify.h>
60 61
61static const char mask_names[] ALIGN1 = 62static const char mask_names[] ALIGN1 =
@@ -162,8 +163,9 @@ int inotifyd_main(int argc, char **argv)
162 // read out all pending events 163 // read out all pending events
163 // (NB: len must be int, not ssize_t or long!) 164 // (NB: len must be int, not ssize_t or long!)
164 xioctl(pfd.fd, FIONREAD, &len); 165 xioctl(pfd.fd, FIONREAD, &len);
165#define eventbuf bb_common_bufsiz1 166#define eventbuf bb_common_bufsiz1
166 ie = buf = (len <= sizeof(eventbuf)) ? eventbuf : xmalloc(len); 167#define sizeof_eventbuf COMMON_BUFSIZE
168 ie = buf = (len <= sizeof_eventbuf) ? eventbuf : xmalloc(len);
167 len = full_read(pfd.fd, buf, len); 169 len = full_read(pfd.fd, buf, len);
168 // process events. N.B. events may vary in length 170 // process events. N.B. events may vary in length
169 while (len > 0) { 171 while (len > 0) {
diff --git a/miscutils/less.c b/miscutils/less.c
index ccdb15fdc..94ecf1686 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -127,6 +127,7 @@
127#include <sched.h> /* sched_yield() */ 127#include <sched.h> /* sched_yield() */
128 128
129#include "libbb.h" 129#include "libbb.h"
130#include "common_bufsiz.h"
130#if ENABLE_FEATURE_LESS_REGEXP 131#if ENABLE_FEATURE_LESS_REGEXP
131#include "xregex.h" 132#include "xregex.h"
132#endif 133#endif
@@ -439,7 +440,8 @@ static int at_end(void)
439 */ 440 */
440static void read_lines(void) 441static void read_lines(void)
441{ 442{
442#define readbuf bb_common_bufsiz1 443#define readbuf bb_common_bufsiz1
444#define sizeof_readbuf COMMON_BUFSIZE
443 char *current_line, *p; 445 char *current_line, *p;
444 int w = width; 446 int w = width;
445 char last_terminated = terminated; 447 char last_terminated = terminated;
@@ -480,7 +482,7 @@ static void read_lines(void)
480 time_t t; 482 time_t t;
481 483
482 errno = 0; 484 errno = 0;
483 eof_error = safe_read(STDIN_FILENO, readbuf, sizeof(readbuf)); 485 eof_error = safe_read(STDIN_FILENO, readbuf, sizeof_readbuf);
484 if (errno != EAGAIN) 486 if (errno != EAGAIN)
485 break; 487 break;
486 t = time(NULL); 488 t = time(NULL);
diff --git a/miscutils/microcom.c b/miscutils/microcom.c
index 5e29a1acd..5eb2e6743 100644
--- a/miscutils/microcom.c
+++ b/miscutils/microcom.c
@@ -19,6 +19,7 @@
19//usage: "\n -X Disable special meaning of NUL and Ctrl-X from stdin" 19//usage: "\n -X Disable special meaning of NUL and Ctrl-X from stdin"
20 20
21#include "libbb.h" 21#include "libbb.h"
22#include "common_bufsiz.h"
22 23
23// set raw tty mode 24// set raw tty mode
24static void xget1(int fd, struct termios *t, struct termios *oldt) 25static void xget1(int fd, struct termios *t, struct termios *oldt)
@@ -155,10 +156,11 @@ int microcom_main(int argc UNUSED_PARAM, char **argv)
155skip_write: ; 156skip_write: ;
156 } 157 }
157 if (pfd[0].revents) { 158 if (pfd[0].revents) {
158#define iobuf bb_common_bufsiz1 159#define iobuf bb_common_bufsiz1
160#define sizeof_iobuf COMMON_BUFSIZE
159 ssize_t len; 161 ssize_t len;
160 // read from device -> write to stdout 162 // read from device -> write to stdout
161 len = safe_read(sfd, iobuf, sizeof(iobuf)); 163 len = safe_read(sfd, iobuf, sizeof_iobuf);
162 if (len > 0) 164 if (len > 0)
163 full_write(STDOUT_FILENO, iobuf, len); 165 full_write(STDOUT_FILENO, iobuf, len);
164 else { 166 else {
diff --git a/networking/arp.c b/networking/arp.c
index 0099aa534..5f7818663 100644
--- a/networking/arp.c
+++ b/networking/arp.c
@@ -32,6 +32,7 @@
32//usage: "\n -H HWTYPE Hardware address type" 32//usage: "\n -H HWTYPE Hardware address type"
33 33
34#include "libbb.h" 34#include "libbb.h"
35#include "common_bufsiz.h"
35#include "inet_common.h" 36#include "inet_common.h"
36 37
37#include <arpa/inet.h> 38#include <arpa/inet.h>
@@ -69,7 +70,7 @@ struct globals {
69 const char *device; /* current device */ 70 const char *device; /* current device */
70 smallint hw_set; /* flag if hw-type was set (-H) */ 71 smallint hw_set; /* flag if hw-type was set (-H) */
71} FIX_ALIASING; 72} FIX_ALIASING;
72#define G (*(struct globals*)&bb_common_bufsiz1) 73#define G (*(struct globals*)bb_common_bufsiz1)
73#define ap (G.ap ) 74#define ap (G.ap )
74#define hw (G.hw ) 75#define hw (G.hw )
75#define device (G.device ) 76#define device (G.device )
diff --git a/networking/arping.c b/networking/arping.c
index ef205e5e6..52f5ba51f 100644
--- a/networking/arping.c
+++ b/networking/arping.c
@@ -28,6 +28,7 @@
28#include <netpacket/packet.h> 28#include <netpacket/packet.h>
29 29
30#include "libbb.h" 30#include "libbb.h"
31#include "common_bufsiz.h"
31 32
32/* We don't expect to see 1000+ seconds delay, unsigned is enough */ 33/* We don't expect to see 1000+ seconds delay, unsigned is enough */
33#define MONOTONIC_US() ((unsigned)monotonic_us()) 34#define MONOTONIC_US() ((unsigned)monotonic_us())
@@ -60,7 +61,7 @@ struct globals {
60 unsigned brd_recv; 61 unsigned brd_recv;
61 unsigned req_recv; 62 unsigned req_recv;
62} FIX_ALIASING; 63} FIX_ALIASING;
63#define G (*(struct globals*)&bb_common_bufsiz1) 64#define G (*(struct globals*)bb_common_bufsiz1)
64#define src (G.src ) 65#define src (G.src )
65#define dst (G.dst ) 66#define dst (G.dst )
66#define me (G.me ) 67#define me (G.me )
diff --git a/networking/ftpd.c b/networking/ftpd.c
index 8345ae67c..8553a28f5 100644
--- a/networking/ftpd.c
+++ b/networking/ftpd.c
@@ -29,6 +29,7 @@
29//usage: "\n DIR Change root to this directory" 29//usage: "\n DIR Change root to this directory"
30 30
31#include "libbb.h" 31#include "libbb.h"
32#include "common_bufsiz.h"
32#include <syslog.h> 33#include <syslog.h>
33#include <netinet/tcp.h> 34#include <netinet/tcp.h>
34 35
@@ -123,7 +124,7 @@ struct globals {
123 char msg_ok [(sizeof("NNN " MSG_OK ) + 3) & 0xfffc]; 124 char msg_ok [(sizeof("NNN " MSG_OK ) + 3) & 0xfffc];
124 char msg_err[(sizeof("NNN " MSG_ERR) + 3) & 0xfffc]; 125 char msg_err[(sizeof("NNN " MSG_ERR) + 3) & 0xfffc];
125} FIX_ALIASING; 126} FIX_ALIASING;
126#define G (*(struct globals*)&bb_common_bufsiz1) 127#define G (*(struct globals*)bb_common_bufsiz1)
127#define INIT_G() do { \ 128#define INIT_G() do { \
128 /* Moved to main */ \ 129 /* Moved to main */ \
129 /*strcpy(G.msg_ok + 4, MSG_OK );*/ \ 130 /*strcpy(G.msg_ok + 4, MSG_OK );*/ \
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index b398bc874..61bc45c4e 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -50,6 +50,7 @@
50//usage: ) 50//usage: )
51 51
52#include "libbb.h" 52#include "libbb.h"
53#include "common_bufsiz.h"
53 54
54struct globals { 55struct globals {
55 const char *user; 56 const char *user;
@@ -60,7 +61,7 @@ struct globals {
60 int do_continue; 61 int do_continue;
61 char buf[4]; /* actually [BUFSZ] */ 62 char buf[4]; /* actually [BUFSZ] */
62} FIX_ALIASING; 63} FIX_ALIASING;
63#define G (*(struct globals*)&bb_common_bufsiz1) 64#define G (*(struct globals*)bb_common_bufsiz1)
64enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) }; 65enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) };
65#define user (G.user ) 66#define user (G.user )
66#define password (G.password ) 67#define password (G.password )
diff --git a/networking/httpd.c b/networking/httpd.c
index ed15fd883..ef90770ac 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -125,6 +125,7 @@
125//usage: "\n -d STRING URL decode STRING" 125//usage: "\n -d STRING URL decode STRING"
126 126
127#include "libbb.h" 127#include "libbb.h"
128#include "common_bufsiz.h"
128#if ENABLE_PAM 129#if ENABLE_PAM
129/* PAM may include <locale.h>. We may need to undefine bbox's stub define: */ 130/* PAM may include <locale.h>. We may need to undefine bbox's stub define: */
130# undef setlocale 131# undef setlocale
@@ -307,7 +308,8 @@ struct globals {
307 Htaccess *script_i; /* config script interpreters */ 308 Htaccess *script_i; /* config script interpreters */
308#endif 309#endif
309 char *iobuf; /* [IOBUF_SIZE] */ 310 char *iobuf; /* [IOBUF_SIZE] */
310#define hdr_buf bb_common_bufsiz1 311#define hdr_buf bb_common_bufsiz1
312#define sizeof_hdr_buf COMMON_BUFSIZE
311 char *hdr_ptr; 313 char *hdr_ptr;
312 int hdr_cnt; 314 int hdr_cnt;
313#if ENABLE_FEATURE_HTTPD_ERROR_PAGES 315#if ENABLE_FEATURE_HTTPD_ERROR_PAGES
@@ -1066,7 +1068,7 @@ static int get_line(void)
1066 alarm(HEADER_READ_TIMEOUT); 1068 alarm(HEADER_READ_TIMEOUT);
1067 while (1) { 1069 while (1) {
1068 if (hdr_cnt <= 0) { 1070 if (hdr_cnt <= 0) {
1069 hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof(hdr_buf)); 1071 hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf);
1070 if (hdr_cnt <= 0) 1072 if (hdr_cnt <= 0)
1071 break; 1073 break;
1072 hdr_ptr = hdr_buf; 1074 hdr_ptr = hdr_buf;
@@ -1191,9 +1193,9 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post
1191 /* We expect data, prev data portion is eaten by CGI 1193 /* We expect data, prev data portion is eaten by CGI
1192 * and there *is* data to read from the peer 1194 * and there *is* data to read from the peer
1193 * (POSTDATA) */ 1195 * (POSTDATA) */
1194 //count = post_len > (int)sizeof(hdr_buf) ? (int)sizeof(hdr_buf) : post_len; 1196 //count = post_len > (int)sizeof_hdr_buf ? (int)sizeof_hdr_buf : post_len;
1195 //count = safe_read(STDIN_FILENO, hdr_buf, count); 1197 //count = safe_read(STDIN_FILENO, hdr_buf, count);
1196 count = safe_read(STDIN_FILENO, hdr_buf, sizeof(hdr_buf)); 1198 count = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf);
1197 if (count > 0) { 1199 if (count > 0) {
1198 hdr_cnt = count; 1200 hdr_cnt = count;
1199 hdr_ptr = hdr_buf; 1201 hdr_ptr = hdr_buf;
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 2c6db926f..399ff6b5d 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -44,6 +44,7 @@
44//usage: "\n -f Force de/configuration" 44//usage: "\n -f Force de/configuration"
45 45
46#include "libbb.h" 46#include "libbb.h"
47#include "common_bufsiz.h"
47/* After libbb.h, since it needs sys/types.h on some systems */ 48/* After libbb.h, since it needs sys/types.h on some systems */
48#include <sys/utsname.h> 49#include <sys/utsname.h>
49#include <fnmatch.h> 50#include <fnmatch.h>
@@ -129,7 +130,7 @@ struct globals {
129 const char *startup_PATH; 130 const char *startup_PATH;
130 char *shell; 131 char *shell;
131} FIX_ALIASING; 132} FIX_ALIASING;
132#define G (*(struct globals*)&bb_common_bufsiz1) 133#define G (*(struct globals*)bb_common_bufsiz1)
133#define INIT_G() do { } while (0) 134#define INIT_G() do { } while (0)
134 135
135 136
diff --git a/networking/inetd.c b/networking/inetd.c
index 4f6673b12..aa35ffa2b 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -170,6 +170,7 @@
170#include <sys/un.h> 170#include <sys/un.h>
171 171
172#include "libbb.h" 172#include "libbb.h"
173#include "common_bufsiz.h"
173 174
174#if ENABLE_FEATURE_INETD_RPC 175#if ENABLE_FEATURE_INETD_RPC
175# if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_RPC__) 176# if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_RPC__)
@@ -327,7 +328,7 @@ struct globals {
327 /* Used in next_line(), and as scratch read buffer */ 328 /* Used in next_line(), and as scratch read buffer */
328 char line[256]; /* _at least_ 256, see LINE_SIZE */ 329 char line[256]; /* _at least_ 256, see LINE_SIZE */
329} FIX_ALIASING; 330} FIX_ALIASING;
330#define G (*(struct globals*)&bb_common_bufsiz1) 331#define G (*(struct globals*)bb_common_bufsiz1)
331enum { LINE_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line) }; 332enum { LINE_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line) };
332#define rlim_ofile_cur (G.rlim_ofile_cur ) 333#define rlim_ofile_cur (G.rlim_ofile_cur )
333#define rlim_ofile (G.rlim_ofile ) 334#define rlim_ofile (G.rlim_ofile )
diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c
index 252c8aba9..f63ed8ee4 100644
--- a/networking/isrv_identd.c
+++ b/networking/isrv_identd.c
@@ -18,6 +18,7 @@
18//usage: "\n STRING Ident answer string (default: nobody)" 18//usage: "\n STRING Ident answer string (default: nobody)"
19 19
20#include "libbb.h" 20#include "libbb.h"
21#include "common_bufsiz.h"
21#include <syslog.h> 22#include <syslog.h>
22#include "isrv.h" 23#include "isrv.h"
23 24
@@ -28,7 +29,8 @@ typedef struct identd_buf_t {
28 char buf[64 - sizeof(int)]; 29 char buf[64 - sizeof(int)];
29} identd_buf_t; 30} identd_buf_t;
30 31
31#define bogouser bb_common_bufsiz1 32#define bogouser bb_common_bufsiz1
33#define sizeof_bogouser COMMON_BUFSIZE
32 34
33static int new_peer(isrv_state_t *state, int fd) 35static int new_peer(isrv_state_t *state, int fd)
34{ 36{
@@ -118,7 +120,7 @@ int fakeidentd_main(int argc UNUSED_PARAM, char **argv)
118 opt = getopt32(argv, "fiwb:", &bind_address); 120 opt = getopt32(argv, "fiwb:", &bind_address);
119 strcpy(bogouser, "nobody"); 121 strcpy(bogouser, "nobody");
120 if (argv[optind]) 122 if (argv[optind])
121 strncpy(bogouser, argv[optind], sizeof(bogouser) - 1); 123 strncpy(bogouser, argv[optind], sizeof_bogouser - 1);
122 124
123 /* Daemonize if no -f and no -i and no -w */ 125 /* Daemonize if no -f and no -i and no -w */
124 if (!(opt & OPT_fiw)) 126 if (!(opt & OPT_fiw))
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index 5c975d8c5..2c0f514c7 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -13,6 +13,7 @@
13#include <net/if_arp.h> 13#include <net/if_arp.h>
14 14
15#include "ip_common.h" /* #include "libbb.h" is inside */ 15#include "ip_common.h" /* #include "libbb.h" is inside */
16#include "common_bufsiz.h"
16#include "rt_names.h" 17#include "rt_names.h"
17#include "utils.h" 18#include "utils.h"
18 19
@@ -39,7 +40,7 @@ struct filter_t {
39} FIX_ALIASING; 40} FIX_ALIASING;
40typedef struct filter_t filter_t; 41typedef struct filter_t filter_t;
41 42
42#define G_filter (*(filter_t*)&bb_common_bufsiz1) 43#define G_filter (*(filter_t*)bb_common_bufsiz1)
43 44
44 45
45static void print_link_flags(unsigned flags, unsigned mdown) 46static void print_link_flags(unsigned flags, unsigned mdown)
diff --git a/networking/libiproute/ipneigh.c b/networking/libiproute/ipneigh.c
index 179505c2d..151d3d109 100644
--- a/networking/libiproute/ipneigh.c
+++ b/networking/libiproute/ipneigh.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include "ip_common.h" /* #include "libbb.h" is inside */ 10#include "ip_common.h" /* #include "libbb.h" is inside */
11#include "common_bufsiz.h"
11#include "rt_names.h" 12#include "rt_names.h"
12#include "utils.h" 13#include "utils.h"
13#include <linux/neighbour.h> 14#include <linux/neighbour.h>
@@ -40,7 +41,7 @@ struct filter_t {
40} FIX_ALIASING; 41} FIX_ALIASING;
41typedef struct filter_t filter_t; 42typedef struct filter_t filter_t;
42 43
43#define G_filter (*(filter_t*)&bb_common_bufsiz1) 44#define G_filter (*(filter_t*)bb_common_bufsiz1)
44 45
45static int flush_update(void) 46static int flush_update(void)
46{ 47{
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index 82827488f..34d4f4758 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include "ip_common.h" /* #include "libbb.h" is inside */ 13#include "ip_common.h" /* #include "libbb.h" is inside */
14#include "common_bufsiz.h"
14#include "rt_names.h" 15#include "rt_names.h"
15#include "utils.h" 16#include "utils.h"
16 17
@@ -43,7 +44,7 @@ struct filter_t {
43} FIX_ALIASING; 44} FIX_ALIASING;
44typedef struct filter_t filter_t; 45typedef struct filter_t filter_t;
45 46
46#define G_filter (*(filter_t*)&bb_common_bufsiz1) 47#define G_filter (*(filter_t*)bb_common_bufsiz1)
47 48
48static int flush_update(void) 49static int flush_update(void)
49{ 50{
diff --git a/networking/nc.c b/networking/nc.c
index 2f9e17466..50edee450 100644
--- a/networking/nc.c
+++ b/networking/nc.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include "libbb.h" 10#include "libbb.h"
11#include "common_bufsiz.h"
11 12
12//config:config NC 13//config:config NC
13//config: bool "nc" 14//config: bool "nc"
@@ -252,7 +253,7 @@ int nc_main(int argc, char **argv)
252 fd = STDIN_FILENO; 253 fd = STDIN_FILENO;
253 while (1) { 254 while (1) {
254 if (FD_ISSET(fd, &testfds)) { 255 if (FD_ISSET(fd, &testfds)) {
255 nread = safe_read(fd, iobuf, sizeof(iobuf)); 256 nread = safe_read(fd, iobuf, COMMON_BUFSIZE);
256 if (fd == cfd) { 257 if (fd == cfd) {
257 if (nread < 1) 258 if (nread < 1)
258 exit(EXIT_SUCCESS); 259 exit(EXIT_SUCCESS);
diff --git a/networking/ping.c b/networking/ping.c
index 0eb1ae799..761660979 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -28,6 +28,7 @@
28#include <net/if.h> 28#include <net/if.h>
29#include <netinet/ip_icmp.h> 29#include <netinet/ip_icmp.h>
30#include "libbb.h" 30#include "libbb.h"
31#include "common_bufsiz.h"
31 32
32#ifdef __BIONIC__ 33#ifdef __BIONIC__
33/* should be in netinet/ip_icmp.h */ 34/* should be in netinet/ip_icmp.h */
@@ -186,7 +187,7 @@ struct globals {
186 char *hostname; 187 char *hostname;
187 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; 188 char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
188} FIX_ALIASING; 189} FIX_ALIASING;
189#define G (*(struct globals*)&bb_common_bufsiz1) 190#define G (*(struct globals*)bb_common_bufsiz1)
190#define INIT_G() do { } while (0) 191#define INIT_G() do { } while (0)
191 192
192static void noresp(int ign UNUSED_PARAM) 193static void noresp(int ign UNUSED_PARAM)
@@ -378,7 +379,7 @@ struct globals {
378 } pingaddr; 379 } pingaddr;
379 unsigned char rcvd_tbl[MAX_DUP_CHK / 8]; 380 unsigned char rcvd_tbl[MAX_DUP_CHK / 8];
380} FIX_ALIASING; 381} FIX_ALIASING;
381#define G (*(struct globals*)&bb_common_bufsiz1) 382#define G (*(struct globals*)bb_common_bufsiz1)
382#define if_index (G.if_index ) 383#define if_index (G.if_index )
383#define source_lsa (G.source_lsa ) 384#define source_lsa (G.source_lsa )
384#define str_I (G.str_I ) 385#define str_I (G.str_I )
diff --git a/networking/slattach.c b/networking/slattach.c
index 14e0c1941..d9d8fe7b8 100644
--- a/networking/slattach.c
+++ b/networking/slattach.c
@@ -27,6 +27,7 @@
27//usage: "\n -F Disable RTS/CTS flow control" 27//usage: "\n -F Disable RTS/CTS flow control"
28 28
29#include "libbb.h" 29#include "libbb.h"
30#include "common_bufsiz.h"
30#include "libiproute/utils.h" /* invarg_1_to_2() */ 31#include "libiproute/utils.h" /* invarg_1_to_2() */
31 32
32struct globals { 33struct globals {
@@ -34,7 +35,7 @@ struct globals {
34 int saved_disc; 35 int saved_disc;
35 struct termios saved_state; 36 struct termios saved_state;
36} FIX_ALIASING; 37} FIX_ALIASING;
37#define G (*(struct globals*)&bb_common_bufsiz1) 38#define G (*(struct globals*)bb_common_bufsiz1)
38#define handle (G.handle ) 39#define handle (G.handle )
39#define saved_disc (G.saved_disc ) 40#define saved_disc (G.saved_disc )
40#define saved_state (G.saved_state ) 41#define saved_state (G.saved_state )
diff --git a/networking/tc.c b/networking/tc.c
index c84c18a67..1372ca081 100644
--- a/networking/tc.c
+++ b/networking/tc.c
@@ -29,6 +29,7 @@
29//usage: "filter show [ dev STRING ] [ root | parent CLASSID ]" 29//usage: "filter show [ dev STRING ] [ root | parent CLASSID ]"
30 30
31#include "libbb.h" 31#include "libbb.h"
32#include "common_bufsiz.h"
32 33
33#include "libiproute/utils.h" 34#include "libiproute/utils.h"
34#include "libiproute/ip_common.h" 35#include "libiproute/ip_common.h"
@@ -63,7 +64,7 @@ struct globals {
63 uint32_t filter_prio; 64 uint32_t filter_prio;
64 uint32_t filter_proto; 65 uint32_t filter_proto;
65} FIX_ALIASING; 66} FIX_ALIASING;
66#define G (*(struct globals*)&bb_common_bufsiz1) 67#define G (*(struct globals*)bb_common_bufsiz1)
67#define filter_ifindex (G.filter_ifindex) 68#define filter_ifindex (G.filter_ifindex)
68#define filter_qdisc (G.filter_qdisc) 69#define filter_qdisc (G.filter_qdisc)
69#define filter_parent (G.filter_parent) 70#define filter_parent (G.filter_parent)
diff --git a/networking/tcpudp.c b/networking/tcpudp.c
index 3df6a98d8..624973042 100644
--- a/networking/tcpudp.c
+++ b/networking/tcpudp.c
@@ -67,6 +67,7 @@
67//usage: "\n -v Verbose" 67//usage: "\n -v Verbose"
68 68
69#include "libbb.h" 69#include "libbb.h"
70#include "common_bufsiz.h"
70 71
71/* Wants <limits.h> etc, thus included after libbb.h: */ 72/* Wants <limits.h> etc, thus included after libbb.h: */
72#ifdef __linux__ 73#ifdef __linux__
@@ -91,7 +92,7 @@ struct globals {
91 char **env_cur; 92 char **env_cur;
92 char *env_var[1]; /* actually bigger */ 93 char *env_var[1]; /* actually bigger */
93} FIX_ALIASING; 94} FIX_ALIASING;
94#define G (*(struct globals*)&bb_common_bufsiz1) 95#define G (*(struct globals*)bb_common_bufsiz1)
95#define verbose (G.verbose ) 96#define verbose (G.verbose )
96#define max_per_host (G.max_per_host) 97#define max_per_host (G.max_per_host)
97#define cur_per_host (G.cur_per_host) 98#define cur_per_host (G.cur_per_host)
diff --git a/networking/telnet.c b/networking/telnet.c
index 944cf1bd6..2946bc831 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -39,6 +39,7 @@
39#include <arpa/telnet.h> 39#include <arpa/telnet.h>
40#include <netinet/in.h> 40#include <netinet/in.h>
41#include "libbb.h" 41#include "libbb.h"
42#include "common_bufsiz.h"
42 43
43#ifdef __BIONIC__ 44#ifdef __BIONIC__
44/* should be in arpa/telnet.h */ 45/* should be in arpa/telnet.h */
@@ -108,7 +109,7 @@ struct globals {
108 struct termios termios_def; 109 struct termios termios_def;
109 struct termios termios_raw; 110 struct termios termios_raw;
110} FIX_ALIASING; 111} FIX_ALIASING;
111#define G (*(struct globals*)&bb_common_bufsiz1) 112#define G (*(struct globals*)bb_common_bufsiz1)
112#define INIT_G() do { \ 113#define INIT_G() do { \
113 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ 114 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
114} while (0) 115} while (0)
diff --git a/networking/telnetd.c b/networking/telnetd.c
index 25d05fe7a..13d5a8f64 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -44,6 +44,7 @@
44#define DEBUG 0 44#define DEBUG 0
45 45
46#include "libbb.h" 46#include "libbb.h"
47#include "common_bufsiz.h"
47#include <syslog.h> 48#include <syslog.h>
48 49
49#if DEBUG 50#if DEBUG
@@ -82,7 +83,7 @@ struct globals {
82 const char *issuefile; 83 const char *issuefile;
83 int maxfd; 84 int maxfd;
84} FIX_ALIASING; 85} FIX_ALIASING;
85#define G (*(struct globals*)&bb_common_bufsiz1) 86#define G (*(struct globals*)bb_common_bufsiz1)
86#define INIT_G() do { \ 87#define INIT_G() do { \
87 G.loginpath = "/bin/login"; \ 88 G.loginpath = "/bin/login"; \
88 G.issuefile = "/etc/issue.net"; \ 89 G.issuefile = "/etc/issue.net"; \
diff --git a/networking/tftp.c b/networking/tftp.c
index ad9308e52..8aeb79aca 100644
--- a/networking/tftp.c
+++ b/networking/tftp.c
@@ -51,6 +51,7 @@
51//usage: "\n -l Log to syslog (inetd mode requires this)" 51//usage: "\n -l Log to syslog (inetd mode requires this)"
52 52
53#include "libbb.h" 53#include "libbb.h"
54#include "common_bufsiz.h"
54#include <syslog.h> 55#include <syslog.h>
55 56
56#if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT 57#if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT
@@ -128,7 +129,7 @@ struct globals {
128 bb_progress_t pmt; 129 bb_progress_t pmt;
129#endif 130#endif
130} FIX_ALIASING; 131} FIX_ALIASING;
131#define G (*(struct globals*)&bb_common_bufsiz1) 132#define G (*(struct globals*)bb_common_bufsiz1)
132#define INIT_G() do { \ 133#define INIT_G() do { \
133 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ 134 BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
134} while (0) 135} while (0)
@@ -757,7 +758,8 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv)
757{ 758{
758 len_and_sockaddr *our_lsa; 759 len_and_sockaddr *our_lsa;
759 len_and_sockaddr *peer_lsa; 760 len_and_sockaddr *peer_lsa;
760 char *local_file, *mode, *user_opt; 761 char *mode, *user_opt;
762 char *local_file = local_file;
761 const char *error_msg; 763 const char *error_msg;
762 int opt, result, opcode; 764 int opt, result, opcode;
763 IF_FEATURE_TFTP_BLOCKSIZE(int blksize = TFTP_BLKSIZE_DEFAULT;) 765 IF_FEATURE_TFTP_BLOCKSIZE(int blksize = TFTP_BLKSIZE_DEFAULT;)
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index 496ab11a1..a526494d7 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -9,6 +9,7 @@
9#define UDHCP_COMMON_H 1 9#define UDHCP_COMMON_H 1
10 10
11#include "libbb.h" 11#include "libbb.h"
12#include "common_bufsiz.h"
12#include <netinet/udp.h> 13#include <netinet/udp.h>
13#include <netinet/ip.h> 14#include <netinet/ip.h>
14 15
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h
index 183e7e24c..9dd5bef9e 100644
--- a/networking/udhcp/dhcpd.h
+++ b/networking/udhcp/dhcpd.h
@@ -57,7 +57,7 @@ struct server_config_t {
57 struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */ 57 struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */
58} FIX_ALIASING; 58} FIX_ALIASING;
59 59
60#define server_config (*(struct server_config_t*)&bb_common_bufsiz1) 60#define server_config (*(struct server_config_t*)bb_common_bufsiz1)
61/* client_config sits in 2nd half of bb_common_bufsiz1 */ 61/* client_config sits in 2nd half of bb_common_bufsiz1 */
62 62
63#if ENABLE_FEATURE_UDHCP_PORT 63#if ENABLE_FEATURE_UDHCP_PORT
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c
index f82ac05b4..1722a85de 100644
--- a/networking/udhcp/dhcprelay.c
+++ b/networking/udhcp/dhcprelay.c
@@ -33,7 +33,7 @@ struct xid_item {
33 struct xid_item *next; 33 struct xid_item *next;
34} FIX_ALIASING; 34} FIX_ALIASING;
35 35
36#define dhcprelay_xid_list (*(struct xid_item*)&bb_common_bufsiz1) 36#define dhcprelay_xid_list (*(struct xid_item*)bb_common_bufsiz1)
37 37
38static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client) 38static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client)
39{ 39{
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index 7b57c6258..b22425352 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -57,33 +57,35 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg)
57struct config_keyword { 57struct config_keyword {
58 const char *keyword; 58 const char *keyword;
59 int (*handler)(const char *line, void *var) FAST_FUNC; 59 int (*handler)(const char *line, void *var) FAST_FUNC;
60 void *var; 60 unsigned ofs;
61 const char *def; 61 const char *def;
62}; 62};
63 63
64#define OFS(field) offsetof(struct server_config_t, field)
65
64static const struct config_keyword keywords[] = { 66static const struct config_keyword keywords[] = {
65 /* keyword handler variable address default */ 67 /* keyword handler variable address default */
66 {"start" , udhcp_str2nip , &server_config.start_ip , "192.168.0.20"}, 68 {"start" , udhcp_str2nip , OFS(start_ip ), "192.168.0.20"},
67 {"end" , udhcp_str2nip , &server_config.end_ip , "192.168.0.254"}, 69 {"end" , udhcp_str2nip , OFS(end_ip ), "192.168.0.254"},
68 {"interface" , read_str , &server_config.interface , "eth0"}, 70 {"interface" , read_str , OFS(interface ), "eth0"},
69 /* Avoid "max_leases value not sane" warning by setting default 71 /* Avoid "max_leases value not sane" warning by setting default
70 * to default_end_ip - default_start_ip + 1: */ 72 * to default_end_ip - default_start_ip + 1: */
71 {"max_leases" , read_u32 , &server_config.max_leases , "235"}, 73 {"max_leases" , read_u32 , OFS(max_leases ), "235"},
72 {"auto_time" , read_u32 , &server_config.auto_time , "7200"}, 74 {"auto_time" , read_u32 , OFS(auto_time ), "7200"},
73 {"decline_time" , read_u32 , &server_config.decline_time , "3600"}, 75 {"decline_time" , read_u32 , OFS(decline_time ), "3600"},
74 {"conflict_time", read_u32 , &server_config.conflict_time, "3600"}, 76 {"conflict_time", read_u32 , OFS(conflict_time), "3600"},
75 {"offer_time" , read_u32 , &server_config.offer_time , "60"}, 77 {"offer_time" , read_u32 , OFS(offer_time ), "60"},
76 {"min_lease" , read_u32 , &server_config.min_lease_sec, "60"}, 78 {"min_lease" , read_u32 , OFS(min_lease_sec), "60"},
77 {"lease_file" , read_str , &server_config.lease_file , LEASES_FILE}, 79 {"lease_file" , read_str , OFS(lease_file ), LEASES_FILE},
78 {"pidfile" , read_str , &server_config.pidfile , "/var/run/udhcpd.pid"}, 80 {"pidfile" , read_str , OFS(pidfile ), "/var/run/udhcpd.pid"},
79 {"siaddr" , udhcp_str2nip , &server_config.siaddr_nip , "0.0.0.0"}, 81 {"siaddr" , udhcp_str2nip , OFS(siaddr_nip ), "0.0.0.0"},
80 /* keywords with no defaults must be last! */ 82 /* keywords with no defaults must be last! */
81 {"option" , udhcp_str2optset, &server_config.options , ""}, 83 {"option" , udhcp_str2optset, OFS(options ), ""},
82 {"opt" , udhcp_str2optset, &server_config.options , ""}, 84 {"opt" , udhcp_str2optset, OFS(options ), ""},
83 {"notify_file" , read_str , &server_config.notify_file , NULL}, 85 {"notify_file" , read_str , OFS(notify_file ), NULL},
84 {"sname" , read_str , &server_config.sname , NULL}, 86 {"sname" , read_str , OFS(sname ), NULL},
85 {"boot_file" , read_str , &server_config.boot_file , NULL}, 87 {"boot_file" , read_str , OFS(boot_file ), NULL},
86 {"static_lease" , read_staticlease, &server_config.static_leases, ""}, 88 {"static_lease" , read_staticlease, OFS(static_leases), ""},
87}; 89};
88enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 }; 90enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 };
89 91
@@ -95,17 +97,17 @@ void FAST_FUNC read_config(const char *file)
95 char *token[2]; 97 char *token[2];
96 98
97 for (i = 0; i < KWS_WITH_DEFAULTS; i++) 99 for (i = 0; i < KWS_WITH_DEFAULTS; i++)
98 keywords[i].handler(keywords[i].def, keywords[i].var); 100 keywords[i].handler(keywords[i].def, (char*)&server_config + keywords[i].ofs);
99 101
100 parser = config_open(file); 102 parser = config_open(file);
101 while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { 103 while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
102 for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) { 104 for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
103 if (strcasecmp(token[0], k->keyword) == 0) { 105 if (strcasecmp(token[0], k->keyword) == 0) {
104 if (!k->handler(token[1], k->var)) { 106 if (!k->handler(token[1], (char*)&server_config + k->ofs)) {
105 bb_error_msg("can't parse line %u in %s", 107 bb_error_msg("can't parse line %u in %s",
106 parser->lineno, file); 108 parser->lineno, file);
107 /* reset back to the default value */ 109 /* reset back to the default value */
108 k->handler(k->def, k->var); 110 k->handler(k->def, (char*)&server_config + k->ofs);
109 } 111 }
110 break; 112 break;
111 } 113 }
diff --git a/networking/zcip.c b/networking/zcip.c
index c93082619..79643458c 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -40,6 +40,7 @@
40//usage: "\nexits only on I/O errors (link down etc)" 40//usage: "\nexits only on I/O errors (link down etc)"
41 41
42#include "libbb.h" 42#include "libbb.h"
43#include "common_bufsiz.h"
43#include <netinet/ether.h> 44#include <netinet/ether.h>
44#include <net/if.h> 45#include <net/if.h>
45#include <net/if_arp.h> 46#include <net/if_arp.h>
@@ -90,7 +91,7 @@ struct globals {
90 struct ether_addr our_ethaddr; 91 struct ether_addr our_ethaddr;
91 uint32_t localnet_ip; 92 uint32_t localnet_ip;
92} FIX_ALIASING; 93} FIX_ALIASING;
93#define G (*(struct globals*)&bb_common_bufsiz1) 94#define G (*(struct globals*)bb_common_bufsiz1)
94#define INIT_G() do { } while (0) 95#define INIT_G() do { } while (0)
95 96
96 97
diff --git a/procps/free.c b/procps/free.c
index 0d023f740..9fde64b64 100644
--- a/procps/free.c
+++ b/procps/free.c
@@ -22,6 +22,7 @@
22//usage: "Total: 386144 257128 129016\n" 22//usage: "Total: 386144 257128 129016\n"
23 23
24#include "libbb.h" 24#include "libbb.h"
25#include "common_bufsiz.h"
25#ifdef __linux__ 26#ifdef __linux__
26# include <sys/sysinfo.h> 27# include <sys/sysinfo.h>
27#endif 28#endif
@@ -35,7 +36,7 @@ struct globals {
35# define G_unit_steps 10 36# define G_unit_steps 10
36#endif 37#endif
37} FIX_ALIASING; 38} FIX_ALIASING;
38#define G (*(struct globals*)&bb_common_bufsiz1) 39#define G (*(struct globals*)bb_common_bufsiz1)
39#define INIT_G() do { } while (0) 40#define INIT_G() do { } while (0)
40 41
41 42
diff --git a/procps/fuser.c b/procps/fuser.c
index 05b52abb1..2cda0f9d7 100644
--- a/procps/fuser.c
+++ b/procps/fuser.c
@@ -18,6 +18,7 @@
18//usage: "\n -SIGNAL Signal to send (default: KILL)" 18//usage: "\n -SIGNAL Signal to send (default: KILL)"
19 19
20#include "libbb.h" 20#include "libbb.h"
21#include "common_bufsiz.h"
21 22
22#define MAX_LINE 255 23#define MAX_LINE 255
23 24
@@ -43,7 +44,7 @@ struct globals {
43 smallint kill_failed; 44 smallint kill_failed;
44 int killsig; 45 int killsig;
45} FIX_ALIASING; 46} FIX_ALIASING;
46#define G (*(struct globals*)&bb_common_bufsiz1) 47#define G (*(struct globals*)bb_common_bufsiz1)
47#define INIT_G() do { \ 48#define INIT_G() do { \
48 G.mypid = getpid(); \ 49 G.mypid = getpid(); \
49 G.killsig = SIGKILL; \ 50 G.killsig = SIGKILL; \
diff --git a/procps/nmeter.c b/procps/nmeter.c
index 33de3790f..efa3d553d 100644
--- a/procps/nmeter.c
+++ b/procps/nmeter.c
@@ -53,6 +53,7 @@
53// totalswap=134209536, freeswap=134209536, procs=157}) 53// totalswap=134209536, freeswap=134209536, procs=157})
54 54
55#include "libbb.h" 55#include "libbb.h"
56#include "common_bufsiz.h"
56 57
57typedef unsigned long long ullong; 58typedef unsigned long long ullong;
58 59
@@ -115,8 +116,8 @@ struct globals {
115 G.deltanz = G.delta = 1000000; \ 116 G.deltanz = G.delta = 1000000; \
116} while (0) 117} while (0)
117 118
118// We depend on this being a char[], not char* - we take sizeof() of it 119#define outbuf bb_common_bufsiz1
119#define outbuf bb_common_bufsiz1 120#define sizeof_outbuf COMMON_BUFSIZE
120 121
121static inline void reset_outbuf(void) 122static inline void reset_outbuf(void)
122{ 123{
@@ -140,7 +141,7 @@ static void print_outbuf(void)
140static void put(const char *s) 141static void put(const char *s)
141{ 142{
142 char *p = cur_outbuf; 143 char *p = cur_outbuf;
143 int sz = outbuf + sizeof(outbuf) - p; 144 int sz = outbuf + sizeof_outbuf - p;
144 while (*s && --sz >= 0) 145 while (*s && --sz >= 0)
145 *p++ = *s++; 146 *p++ = *s++;
146 cur_outbuf = p; 147 cur_outbuf = p;
@@ -148,7 +149,7 @@ static void put(const char *s)
148 149
149static void put_c(char c) 150static void put_c(char c)
150{ 151{
151 if (cur_outbuf < outbuf + sizeof(outbuf)) 152 if (cur_outbuf < outbuf + sizeof_outbuf)
152 *cur_outbuf++ = c; 153 *cur_outbuf++ = c;
153} 154}
154 155
diff --git a/procps/ps.c b/procps/ps.c
index fbafa68a9..65d62e256 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -62,6 +62,7 @@
62//usage: " 2990 andersen andersen R ps\n" 62//usage: " 2990 andersen andersen R ps\n"
63 63
64#include "libbb.h" 64#include "libbb.h"
65#include "common_bufsiz.h"
65#ifdef __linux__ 66#ifdef __linux__
66# include <sys/sysinfo.h> 67# include <sys/sysinfo.h>
67#endif 68#endif
@@ -144,7 +145,7 @@ struct globals {
144 unsigned long seconds_since_boot; 145 unsigned long seconds_since_boot;
145#endif 146#endif
146} FIX_ALIASING; 147} FIX_ALIASING;
147#define G (*(struct globals*)&bb_common_bufsiz1) 148#define G (*(struct globals*)bb_common_bufsiz1)
148#define out (G.out ) 149#define out (G.out )
149#define out_cnt (G.out_cnt ) 150#define out_cnt (G.out_cnt )
150#define print_header (G.print_header ) 151#define print_header (G.print_header )
diff --git a/procps/top.c b/procps/top.c
index ddf794d7d..1c42b249c 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -105,6 +105,7 @@
105//config: Enable 's' in top (gives lots of memory info). 105//config: Enable 's' in top (gives lots of memory info).
106 106
107#include "libbb.h" 107#include "libbb.h"
108#include "common_bufsiz.h"
108 109
109 110
110typedef struct top_status_t { 111typedef struct top_status_t {
@@ -183,7 +184,7 @@ struct globals {
183 char line_buf[80]; 184 char line_buf[80];
184}; //FIX_ALIASING; - large code growth 185}; //FIX_ALIASING; - large code growth
185enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) }; 186enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) };
186#define G (*(struct globals*)&bb_common_bufsiz1) 187#define G (*(struct globals*)bb_common_bufsiz1)
187#define top (G.top ) 188#define top (G.top )
188#define ntop (G.ntop ) 189#define ntop (G.ntop )
189#define sort_field (G.sort_field ) 190#define sort_field (G.sort_field )
diff --git a/runit/runsv.c b/runit/runsv.c
index 4b18d12d5..8833f4c96 100644
--- a/runit/runsv.c
+++ b/runit/runsv.c
@@ -45,6 +45,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 45
46#include <sys/file.h> 46#include <sys/file.h>
47#include "libbb.h" 47#include "libbb.h"
48#include "common_bufsiz.h"
48#include "runit_lib.h" 49#include "runit_lib.h"
49 50
50#if ENABLE_MONOTONIC_SYSCALL 51#if ENABLE_MONOTONIC_SYSCALL
@@ -105,7 +106,7 @@ struct globals {
105 char *dir; 106 char *dir;
106 struct svdir svd[2]; 107 struct svdir svd[2];
107} FIX_ALIASING; 108} FIX_ALIASING;
108#define G (*(struct globals*)&bb_common_bufsiz1) 109#define G (*(struct globals*)bb_common_bufsiz1)
109#define haslog (G.haslog ) 110#define haslog (G.haslog )
110#define sigterm (G.sigterm ) 111#define sigterm (G.sigterm )
111#define pidchanged (G.pidchanged ) 112#define pidchanged (G.pidchanged )
diff --git a/runit/runsvdir.c b/runit/runsvdir.c
index b3d9e7390..49c8f5b48 100644
--- a/runit/runsvdir.c
+++ b/runit/runsvdir.c
@@ -57,6 +57,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 57
58#include <sys/file.h> 58#include <sys/file.h>
59#include "libbb.h" 59#include "libbb.h"
60#include "common_bufsiz.h"
60#include "runit_lib.h" 61#include "runit_lib.h"
61 62
62#define MAXSERVICES 1000 63#define MAXSERVICES 1000
@@ -84,7 +85,7 @@ struct globals {
84 unsigned stamplog; 85 unsigned stamplog;
85#endif 86#endif
86} FIX_ALIASING; 87} FIX_ALIASING;
87#define G (*(struct globals*)&bb_common_bufsiz1) 88#define G (*(struct globals*)bb_common_bufsiz1)
88#define sv (G.sv ) 89#define sv (G.sv )
89#define svdir (G.svdir ) 90#define svdir (G.svdir )
90#define svnum (G.svnum ) 91#define svnum (G.svnum )
diff --git a/runit/sv.c b/runit/sv.c
index de8a0d8a4..e83a29781 100644
--- a/runit/sv.c
+++ b/runit/sv.c
@@ -189,6 +189,7 @@ Exit Codes
189 189
190#include <sys/file.h> 190#include <sys/file.h>
191#include "libbb.h" 191#include "libbb.h"
192#include "common_bufsiz.h"
192#include "runit_lib.h" 193#include "runit_lib.h"
193 194
194struct globals { 195struct globals {
@@ -199,7 +200,7 @@ struct globals {
199 uint64_t tstart, tnow; 200 uint64_t tstart, tnow;
200 svstatus_t svstatus; 201 svstatus_t svstatus;
201} FIX_ALIASING; 202} FIX_ALIASING;
202#define G (*(struct globals*)&bb_common_bufsiz1) 203#define G (*(struct globals*)bb_common_bufsiz1)
203#define acts (G.acts ) 204#define acts (G.acts )
204#define service (G.service ) 205#define service (G.service )
205#define rc (G.rc ) 206#define rc (G.rc )
diff --git a/runit/svlogd.c b/runit/svlogd.c
index dbe8df65c..09efdb695 100644
--- a/runit/svlogd.c
+++ b/runit/svlogd.c
@@ -155,6 +155,7 @@ log message, you can use a pattern like this instead
155 155
156#include <sys/file.h> 156#include <sys/file.h>
157#include "libbb.h" 157#include "libbb.h"
158#include "common_bufsiz.h"
158#include "runit_lib.h" 159#include "runit_lib.h"
159 160
160#define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0) 161#define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0)
@@ -1045,9 +1046,9 @@ int svlogd_main(int argc, char **argv)
1045 } 1046 }
1046 if (opt & 2) if (!repl) repl = '_'; // -R 1047 if (opt & 2) if (!repl) repl = '_'; // -R
1047 if (opt & 4) { // -l 1048 if (opt & 4) { // -l
1048 linemax = xatou_range(l, 0, BUFSIZ-26); 1049 linemax = xatou_range(l, 0, COMMON_BUFSIZE-26);
1049 if (linemax == 0) 1050 if (linemax == 0)
1050 linemax = BUFSIZ-26; 1051 linemax = COMMON_BUFSIZE-26;
1051 if (linemax < 256) 1052 if (linemax < 256)
1052 linemax = 256; 1053 linemax = 256;
1053 } 1054 }
diff --git a/scripts/generate_BUFSIZ.sh b/scripts/generate_BUFSIZ.sh
new file mode 100755
index 000000000..afe9eee1e
--- /dev/null
+++ b/scripts/generate_BUFSIZ.sh
@@ -0,0 +1,114 @@
1#!/bin/sh
2# Called from top-level directory a-la
3#
4# scripts/generate_BUFSIZ.sh include/common_bufsiz.h
5
6. ./.config || exit 1
7
8debug=false
9
10common_bufsiz_h=$1
11
12test x"$NM" = x"" && NM="${CONFIG_CROSS_COMPILER_PREFIX}nm"
13test x"$CC" = x"" && CC="${CONFIG_CROSS_COMPILER_PREFIX}gcc"
14
15regenerate() {
16 cat >"$1.$$"
17 test -f "$1" && diff "$1.$$" "$1" >/dev/null && rm "$1.$$" && return
18 mv "$1.$$" "$1"
19}
20
21generate_std_and_exit() {
22 $debug && echo "Default: bb_common_bufsiz1[] in bss"
23 {
24 echo "enum { COMMON_BUFSIZE = 1024 };"
25 echo "extern char bb_common_bufsiz1[];"
26 echo "#define setup_common_bufsiz() ((void)0)"
27 } | regenerate "$common_bufsiz_h"
28 exit 0
29}
30
31# User does not want any funky stuff?
32test x"$CONFIG_FEATURE_USE_BSS_TAIL" = x"y" || generate_std_and_exit
33
34test -f busybox_unstripped || {
35 # We did not try anything yet
36 $debug && echo "Will try to fit bb_common_bufsiz1[] into _end[]"
37 {
38 echo "enum { COMMON_BUFSIZE = 1024 };"
39 echo "extern char _end[]; /* linker-provided label */"
40 echo "#define bb_common_bufsiz1 _end"
41 echo "#define setup_common_bufsiz() ((void)0)"
42 } | regenerate "$common_bufsiz_h"
43 echo 1024 >"$common_bufsiz_h.BUFSIZE"
44 exit 0
45}
46
47# Get _end address
48END=`$NM busybox_unstripped | grep ' . _end$'| cut -d' ' -f1`
49test x"$END" = x"" && generate_std_and_exit
50$debug && echo "END:0x$END $((0x$END))"
51END=$((0x$END))
52
53# Get PAGE_SIZE
54echo "\
55#include <sys/user.h>
56#if defined(PAGE_SIZE) && PAGE_SIZE > 0
57char page_size[PAGE_SIZE];
58#else
59char page_size[1];
60#endif
61" >page_size_$$.c
62$CC -c "page_size_$$.c" || generate_std_and_exit
63PAGE_SIZE=`$NM --size-sort "page_size_$$.o" | cut -d' ' -f1`
64rm "page_size_$$.c" "page_size_$$.o"
65test x"$PAGE_SIZE" = x"" && generate_std_and_exit
66$debug && echo "PAGE_SIZE:0x$PAGE_SIZE $((0x$PAGE_SIZE))"
67PAGE_SIZE=$((0x$PAGE_SIZE))
68test $PAGE_SIZE -lt 1024 && generate_std_and_exit
69
70# How much space between _end[] and next page?
71PAGE_MASK=$((PAGE_SIZE-1))
72REM=$(( (-END) & PAGE_MASK ))
73$debug && echo "REM:$REM"
74
75if test $REM -lt 1024; then
76 # _end[] has no enough space for bb_common_bufsiz1[],
77 # users will need to malloc it.
78 {
79 echo "enum { COMMON_BUFSIZE = 1024 };"
80 echo "extern char *bb_common_bufsiz1;"
81 echo "void setup_common_bufsiz(void);"
82 } | regenerate "$common_bufsiz_h"
83 # Check that we aren't left with a buggy binary:
84 if test -f "$common_bufsiz_h.BUFSIZE"; then
85 rm "$common_bufsiz_h.BUFSIZE"
86 echo "Warning! Space in _end[] is too small ($REM bytes)!"
87 echo "Rerun make to build a binary which doesn't use it!"
88 exit 1
89 fi
90 exit 0
91fi
92
93# _end[] has REM bytes for bb_common_bufsiz1[]
94OLD=1024
95test -f "$common_bufsiz_h.BUFSIZE" && OLD=`cat "$common_bufsiz_h.BUFSIZE"`
96$debug && echo "OLD:$OLD"
97{
98echo "enum { COMMON_BUFSIZE = $REM };"
99echo "extern char _end[]; /* linker-provided label */"
100echo "#define bb_common_bufsiz1 _end"
101echo "#define setup_common_bufsiz() ((void)0)"
102} | regenerate "$common_bufsiz_h"
103echo $REM >"$common_bufsiz_h.BUFSIZE"
104
105# Check that code did not grow too much and thus _end[] did not shink:
106if test $OLD -gt $REM; then
107 echo "Warning! Space in _end[] has decreased from $OLD to $REM bytes!"
108 echo "Rerun make!"
109 exit 1
110fi
111
112if test $OLD != $REM; then
113 echo "Space in _end[] is $REM bytes. Rerun make to use larger COMMON_BUFSIZE."
114fi
diff --git a/selinux/setfiles.c b/selinux/setfiles.c
index de99dfe44..441345ae9 100644
--- a/selinux/setfiles.c
+++ b/selinux/setfiles.c
@@ -77,7 +77,7 @@ struct globals {
77 int nerr; 77 int nerr;
78 struct edir excludeArray[MAX_EXCLUDES]; 78 struct edir excludeArray[MAX_EXCLUDES];
79} FIX_ALIASING; 79} FIX_ALIASING;
80#define G (*(struct globals*)&bb_common_bufsiz1) 80#define G (*(struct globals*)bb_common_bufsiz1)
81void BUG_setfiles_globals_too_big(void); 81void BUG_setfiles_globals_too_big(void);
82#define INIT_G() do { \ 82#define INIT_G() do { \
83 if (sizeof(G) > COMMON_BUFSIZE) \ 83 if (sizeof(G) > COMMON_BUFSIZE) \
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c
index 03d65b37f..845c49a5e 100644
--- a/sysklogd/klogd.c
+++ b/sysklogd/klogd.c
@@ -58,6 +58,7 @@
58//usage: "\n -n Run in foreground" 58//usage: "\n -n Run in foreground"
59 59
60#include "libbb.h" 60#include "libbb.h"
61#include "common_bufsiz.h"
61#include <syslog.h> 62#include <syslog.h>
62 63
63 64
@@ -145,9 +146,10 @@ static void klogd_close(void)
145 146
146#endif 147#endif
147 148
148#define log_buffer bb_common_bufsiz1 149#define log_buffer bb_common_bufsiz1
150#define sizeof_log_buffer COMMON_BUFSIZE
149enum { 151enum {
150 KLOGD_LOGBUF_SIZE = sizeof(log_buffer), 152 KLOGD_LOGBUF_SIZE = sizeof_log_buffer,
151 OPT_LEVEL = (1 << 0), 153 OPT_LEVEL = (1 << 0),
152 OPT_FOREGROUND = (1 << 1), 154 OPT_FOREGROUND = (1 << 1),
153}; 155};
diff --git a/sysklogd/logread.c b/sysklogd/logread.c
index 781a603b2..ebd7f8b2c 100644
--- a/sysklogd/logread.c
+++ b/sysklogd/logread.c
@@ -42,6 +42,7 @@
42//usage: "\n -F Same as -f, but dump buffer first" 42//usage: "\n -F Same as -f, but dump buffer first"
43 43
44#include "libbb.h" 44#include "libbb.h"
45#include "common_bufsiz.h"
45#include <sys/ipc.h> 46#include <sys/ipc.h>
46#include <sys/sem.h> 47#include <sys/sem.h>
47#include <sys/shm.h> 48#include <sys/shm.h>
@@ -67,7 +68,7 @@ struct globals {
67 struct sembuf SMrdn[2]; // {1, 0}, {0, +1, SEM_UNDO} 68 struct sembuf SMrdn[2]; // {1, 0}, {0, +1, SEM_UNDO}
68 struct shbuf_ds *shbuf; 69 struct shbuf_ds *shbuf;
69} FIX_ALIASING; 70} FIX_ALIASING;
70#define G (*(struct globals*)&bb_common_bufsiz1) 71#define G (*(struct globals*)bb_common_bufsiz1)
71#define SMrup (G.SMrup) 72#define SMrup (G.SMrup)
72#define SMrdn (G.SMrdn) 73#define SMrdn (G.SMrdn)
73#define shbuf (G.shbuf) 74#define shbuf (G.shbuf)
diff --git a/sysklogd/syslogd_and_logger.c b/sysklogd/syslogd_and_logger.c
index 0964f239c..6458a9332 100644
--- a/sysklogd/syslogd_and_logger.c
+++ b/sysklogd/syslogd_and_logger.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include "libbb.h" 10#include "libbb.h"
11#include "common_bufsiz.h"
11#define SYSLOG_NAMES 12#define SYSLOG_NAMES
12#define SYSLOG_NAMES_CONST 13#define SYSLOG_NAMES_CONST
13#include <syslog.h> 14#include <syslog.h>
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 37fa56827..7473b1855 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -97,6 +97,7 @@
97//usage: "If /dev/mdev.log file exists, debug log will be appended to it." 97//usage: "If /dev/mdev.log file exists, debug log will be appended to it."
98 98
99#include "libbb.h" 99#include "libbb.h"
100#include "common_bufsiz.h"
100#include "xregex.h" 101#include "xregex.h"
101 102
102/* "mdev -s" scans /sys/class/xxx, looking for directories which have dev 103/* "mdev -s" scans /sys/class/xxx, looking for directories which have dev
@@ -285,7 +286,7 @@ struct globals {
285 struct rule cur_rule; 286 struct rule cur_rule;
286 char timestr[sizeof("HH:MM:SS.123456")]; 287 char timestr[sizeof("HH:MM:SS.123456")];
287} FIX_ALIASING; 288} FIX_ALIASING;
288#define G (*(struct globals*)&bb_common_bufsiz1) 289#define G (*(struct globals*)bb_common_bufsiz1)
289#define INIT_G() do { \ 290#define INIT_G() do { \
290 IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.maj = -1;) \ 291 IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.maj = -1;) \
291 IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.mode = 0660;) \ 292 IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.mode = 0660;) \
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index b5d2c49b6..f9451792b 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -13,6 +13,7 @@
13//usage: "\n -L LBL Label" 13//usage: "\n -L LBL Label"
14 14
15#include "libbb.h" 15#include "libbb.h"
16#include "common_bufsiz.h"
16 17
17#if ENABLE_SELINUX 18#if ENABLE_SELINUX
18static void mkswap_selinux_setcontext(int fd, const char *path) 19static void mkswap_selinux_setcontext(int fd, const char *path)
diff --git a/util-linux/more.c b/util-linux/more.c
index 359571397..58be3ac3b 100644
--- a/util-linux/more.c
+++ b/util-linux/more.c
@@ -23,6 +23,7 @@
23//usage: "$ dmesg | more\n" 23//usage: "$ dmesg | more\n"
24 24
25#include "libbb.h" 25#include "libbb.h"
26#include "common_bufsiz.h"
26 27
27/* Support for FEATURE_USE_TERMIOS */ 28/* Support for FEATURE_USE_TERMIOS */
28 29
diff --git a/util-linux/mount.c b/util-linux/mount.c
index c428f5827..e5c85feff 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -223,6 +223,7 @@
223#define BB_MS_INVERTED_VALUE (1u << 31) 223#define BB_MS_INVERTED_VALUE (1u << 31)
224 224
225#include "libbb.h" 225#include "libbb.h"
226#include "common_bufsiz.h"
226#if ENABLE_FEATURE_MOUNT_LABEL 227#if ENABLE_FEATURE_MOUNT_LABEL
227# include "volume_id.h" 228# include "volume_id.h"
228#else 229#else
@@ -447,7 +448,7 @@ struct globals {
447 char getmntent_buf[1]; 448 char getmntent_buf[1];
448} FIX_ALIASING; 449} FIX_ALIASING;
449enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_buf) }; 450enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_buf) };
450#define G (*(struct globals*)&bb_common_bufsiz1) 451#define G (*(struct globals*)bb_common_bufsiz1)
451#define nfs_mount_version (G.nfs_mount_version) 452#define nfs_mount_version (G.nfs_mount_version)
452#if ENABLE_FEATURE_MOUNT_VERBOSE 453#if ENABLE_FEATURE_MOUNT_VERBOSE
453#define verbose (G.verbose ) 454#define verbose (G.verbose )
diff --git a/util-linux/script.c b/util-linux/script.c
index abcd73bff..6195161bc 100644
--- a/util-linux/script.c
+++ b/util-linux/script.c
@@ -23,6 +23,7 @@
23//usage: ) 23//usage: )
24 24
25#include "libbb.h" 25#include "libbb.h"
26#include "common_bufsiz.h"
26 27
27int script_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 28int script_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
28int script_main(int argc UNUSED_PARAM, char **argv) 29int script_main(int argc UNUSED_PARAM, char **argv)
@@ -108,7 +109,8 @@ int script_main(int argc UNUSED_PARAM, char **argv)
108 109
109 if (child_pid) { 110 if (child_pid) {
110 /* parent */ 111 /* parent */
111#define buf bb_common_bufsiz1 112#define buf bb_common_bufsiz1
113#define sizeof_buf COMMON_BUFSIZE
112 struct pollfd pfd[2]; 114 struct pollfd pfd[2];
113 int outfd, count, loop; 115 int outfd, count, loop;
114 double oldtime = ENABLE_SCRIPTREPLAY ? time(NULL) : 0; 116 double oldtime = ENABLE_SCRIPTREPLAY ? time(NULL) : 0;
@@ -134,7 +136,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
134 } 136 }
135 if (pfd[0].revents) { 137 if (pfd[0].revents) {
136 errno = 0; 138 errno = 0;
137 count = safe_read(pty, buf, sizeof(buf)); 139 count = safe_read(pty, buf, sizeof_buf);
138 if (count <= 0 && errno != EAGAIN) { 140 if (count <= 0 && errno != EAGAIN) {
139 /* err/eof from pty: exit */ 141 /* err/eof from pty: exit */
140 goto restore; 142 goto restore;
@@ -157,7 +159,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
157 } 159 }
158 } 160 }
159 if (pfd[1].revents) { 161 if (pfd[1].revents) {
160 count = safe_read(STDIN_FILENO, buf, sizeof(buf)); 162 count = safe_read(STDIN_FILENO, buf, sizeof_buf);
161 if (count <= 0) { 163 if (count <= 0) {
162 /* err/eof from stdin: don't read stdin anymore */ 164 /* err/eof from stdin: don't read stdin anymore */
163 pfd[1].revents = 0; 165 pfd[1].revents = 0;
@@ -176,7 +178,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
176 * (util-linux's script doesn't do this. buggy :) */ 178 * (util-linux's script doesn't do this. buggy :) */
177 loop = 999; 179 loop = 999;
178 /* 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 */
179 while (--loop && (count = safe_read(pty, buf, sizeof(buf))) > 0) { 181 while (--loop && (count = safe_read(pty, buf, sizeof_buf)) > 0) {
180 full_write(STDOUT_FILENO, buf, count); 182 full_write(STDOUT_FILENO, buf, count);
181 full_write(outfd, buf, count); 183 full_write(outfd, buf, count);
182 } 184 }
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index c29dd3071..43228a6ba 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -28,6 +28,7 @@
28//usage: "\n -a Stop swapping on all swap devices" 28//usage: "\n -a Stop swapping on all swap devices"
29 29
30#include "libbb.h" 30#include "libbb.h"
31#include "common_bufsiz.h"
31#include <mntent.h> 32#include <mntent.h>
32#ifndef __BIONIC__ 33#ifndef __BIONIC__
33# include <sys/swap.h> 34# include <sys/swap.h>
@@ -62,7 +63,7 @@
62struct globals { 63struct globals {
63 int flags; 64 int flags;
64} FIX_ALIASING; 65} FIX_ALIASING;
65#define G (*(struct globals*)&bb_common_bufsiz1) 66#define G (*(struct globals*)bb_common_bufsiz1)
66#define g_flags (G.flags) 67#define g_flags (G.flags)
67#define save_g_flags() int save_g_flags = g_flags 68#define save_g_flags() int save_g_flags = g_flags
68#define restore_g_flags() g_flags = save_g_flags 69#define restore_g_flags() g_flags = save_g_flags
diff --git a/util-linux/uevent.c b/util-linux/uevent.c
index 514a9e934..58668fa5d 100644
--- a/util-linux/uevent.c
+++ b/util-linux/uevent.c
@@ -25,11 +25,12 @@
25//usage: "\n"" # uevent mdev & mdev -s" 25//usage: "\n"" # uevent mdev & mdev -s"
26 26
27#include "libbb.h" 27#include "libbb.h"
28#include "common_bufsiz.h"
28#include <linux/netlink.h> 29#include <linux/netlink.h>
29 30
30#define BUFFER_SIZE 16*1024 31#define BUFFER_SIZE 16*1024
31 32
32#define env ((char **)&bb_common_bufsiz1) 33#define env ((char **)bb_common_bufsiz1)
33enum { 34enum {
34 MAX_ENV = COMMON_BUFSIZE / sizeof(env[0]) - 1, 35 MAX_ENV = COMMON_BUFSIZE / sizeof(env[0]) - 1,
35}; 36};
diff --git a/util-linux/umount.c b/util-linux/umount.c
index 30bef1686..be0300394 100644
--- a/util-linux/umount.c
+++ b/util-linux/umount.c
@@ -34,6 +34,7 @@
34# define MNT_DETACH 0x00000002 34# define MNT_DETACH 0x00000002
35#endif 35#endif
36#include "libbb.h" 36#include "libbb.h"
37#include "common_bufsiz.h"
37 38
38#if defined(__dietlibc__) 39#if defined(__dietlibc__)
39// TODO: This does not belong here. 40// TODO: This does not belong here.
@@ -102,7 +103,7 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
102 if (opt & OPT_ALL) 103 if (opt & OPT_ALL)
103 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);
104 } else { 105 } else {
105 while (getmntent_r(fp, &me, bb_common_bufsiz1, sizeof(bb_common_bufsiz1))) { 106 while (getmntent_r(fp, &me, bb_common_bufsiz1, COMMON_BUFSIZE)) {
106 /* Match fstype if passed */ 107 /* Match fstype if passed */
107 if (!match_fstype(&me, fstype)) 108 if (!match_fstype(&me, fstype))
108 continue; 109 continue;