From e6a2f4cc5a47d3022bdf5ca2cacbaa5a8c5baf7a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 21 Apr 2016 16:26:30 +0200 Subject: libbb: make bb_common_bufsiz1 1 kbyte, add capability to use bss tail for it The config item is FEATURE_USE_BSS_TAIL. When it is off (default): function old new delta read_config 210 228 +18 doCommands 2279 2294 +15 ipneigh_list_or_flush 763 772 +9 ipaddr_list_or_flush 1256 1261 +5 display_process_list 1301 1306 +5 conspy_main 1378 1383 +5 do_lzo_compress 352 355 +3 do_lzo_decompress 565 567 +2 push 46 44 -2 inetd_main 2136 2134 -2 uevent_main 421 418 -3 addLines 97 92 -5 bb_common_bufsiz1 8193 1024 -7169 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 8/5 up/down: 62/-7181) Total: -7119 bytes text data bss dec hex filename 829850 4086 9080 843016 cdd08 busybox_old 829901 4086 1904 835891 cc133 busybox_unstripped FEATURE_USE_BSS_TAIL=y: read_config 210 228 +18 doCommands 2279 2294 +15 ipneigh_list_or_flush 763 772 +9 ipaddr_list_or_flush 1256 1261 +5 display_process_list 1301 1306 +5 conspy_main 1378 1383 +5 do_lzo_compress 352 355 +3 do_lzo_decompress 565 567 +2 inetd_main 2136 2134 -2 bb_common_bufsiz1 8193 - -8193 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 8/1 up/down: 62/-8195) Total: -8133 bytes text data bss dec hex filename 829850 4086 9080 843016 cdd08 busybox_old 829911 4086 880 834877 cbd3d busybox_unstripped FIXME: setup_common_bufsiz() calls are missing. Signed-off-by: Denys Vlasenko --- runit/runsv.c | 3 ++- runit/runsvdir.c | 3 ++- runit/sv.c | 3 ++- runit/svlogd.c | 5 +++-- 4 files changed, 9 insertions(+), 5 deletions(-) (limited to 'runit') 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. #include #include "libbb.h" +#include "common_bufsiz.h" #include "runit_lib.h" #if ENABLE_MONOTONIC_SYSCALL @@ -105,7 +106,7 @@ struct globals { char *dir; struct svdir svd[2]; } FIX_ALIASING; -#define G (*(struct globals*)&bb_common_bufsiz1) +#define G (*(struct globals*)bb_common_bufsiz1) #define haslog (G.haslog ) #define sigterm (G.sigterm ) #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. #include #include "libbb.h" +#include "common_bufsiz.h" #include "runit_lib.h" #define MAXSERVICES 1000 @@ -84,7 +85,7 @@ struct globals { unsigned stamplog; #endif } FIX_ALIASING; -#define G (*(struct globals*)&bb_common_bufsiz1) +#define G (*(struct globals*)bb_common_bufsiz1) #define sv (G.sv ) #define svdir (G.svdir ) #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 #include #include "libbb.h" +#include "common_bufsiz.h" #include "runit_lib.h" struct globals { @@ -199,7 +200,7 @@ struct globals { uint64_t tstart, tnow; svstatus_t svstatus; } FIX_ALIASING; -#define G (*(struct globals*)&bb_common_bufsiz1) +#define G (*(struct globals*)bb_common_bufsiz1) #define acts (G.acts ) #define service (G.service ) #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 #include #include "libbb.h" +#include "common_bufsiz.h" #include "runit_lib.h" #define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0) @@ -1045,9 +1046,9 @@ int svlogd_main(int argc, char **argv) } if (opt & 2) if (!repl) repl = '_'; // -R if (opt & 4) { // -l - linemax = xatou_range(l, 0, BUFSIZ-26); + linemax = xatou_range(l, 0, COMMON_BUFSIZE-26); if (linemax == 0) - linemax = BUFSIZ-26; + linemax = COMMON_BUFSIZE-26; if (linemax < 256) linemax = 256; } -- cgit v1.2.3-55-g6feb From 47cfbf32fd66563f8c4e09ad6cced6abfbe2fad5 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 21 Apr 2016 18:18:48 +0200 Subject: *: add most of the required setup_common_bufsiz() calls Signed-off-by: Denys Vlasenko --- archival/cpio.c | 1 + archival/lzop.c | 2 +- archival/rpm.c | 2 +- console-tools/resize.c | 3 +++ coreutils/dd.c | 1 + coreutils/du.c | 2 +- coreutils/expr.c | 2 +- coreutils/ls.c | 1 + coreutils/od_bloaty.c | 1 + coreutils/tail.c | 2 +- debianutils/run_parts.c | 2 +- debianutils/start_stop_daemon.c | 1 + e2fsprogs/fsck.c | 1 + editors/sed.c | 1 + findutils/find.c | 1 + findutils/grep.c | 1 + findutils/xargs.c | 1 + init/bootchartd.c | 2 +- loginutils/login.c | 2 +- miscutils/crond.c | 1 + miscutils/dc.c | 1 + miscutils/hdparm.c | 1 + networking/arp.c | 1 + networking/arping.c | 1 + networking/ftpd.c | 1 + networking/ftpgetput.c | 1 + networking/ifupdown.c | 2 +- networking/inetd.c | 1 + networking/ping.c | 3 ++- networking/slattach.c | 2 +- networking/tc.c | 1 + networking/tcpudp.c | 1 + networking/telnet.c | 1 + networking/telnetd.c | 1 + networking/tftp.c | 1 + networking/udhcp/dhcprelay.c | 3 +++ networking/zcip.c | 2 +- procps/free.c | 2 +- procps/fuser.c | 1 + procps/ps.c | 2 +- procps/top.c | 1 + runit/runsv.c | 1 + runit/runsvdir.c | 2 +- runit/sv.c | 2 +- scripts/generate_BUFSIZ.sh | 2 ++ selinux/setfiles.c | 1 + sysklogd/logread.c | 1 + util-linux/mdev.c | 1 + util-linux/mkswap.c | 3 +++ util-linux/more.c | 2 +- util-linux/mount.c | 2 +- util-linux/swaponoff.c | 2 +- util-linux/uevent.c | 3 +++ 53 files changed, 63 insertions(+), 19 deletions(-) (limited to 'runit') diff --git a/archival/cpio.c b/archival/cpio.c index a3036e1ab..3b1550720 100644 --- a/archival/cpio.c +++ b/archival/cpio.c @@ -174,6 +174,7 @@ struct globals { #define G (*(struct globals*)bb_common_bufsiz1) void BUG_cpio_globals_too_big(void); #define INIT_G() do { \ + setup_common_bufsiz(); \ G.owner_ugid.uid = -1L; \ G.owner_ugid.gid = -1L; \ } while (0) diff --git a/archival/lzop.c b/archival/lzop.c index 1371c9751..4afa21889 100644 --- a/archival/lzop.c +++ b/archival/lzop.c @@ -445,7 +445,7 @@ struct globals { chksum_t chksum_out; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) //#define G (*ptr_to_globals) //#define INIT_G() do { // SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); diff --git a/archival/rpm.c b/archival/rpm.c index 079b7a95b..83160f975 100644 --- a/archival/rpm.c +++ b/archival/rpm.c @@ -95,7 +95,7 @@ struct globals { int tagcount; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static void extract_cpio(int fd, const char *source_rpm) { diff --git a/console-tools/resize.c b/console-tools/resize.c index ed80aa082..a3342a195 100644 --- a/console-tools/resize.c +++ b/console-tools/resize.c @@ -19,6 +19,7 @@ #define ESC "\033" #define old_termios_p ((struct termios*)bb_common_bufsiz1) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static void onintr(int sig UNUSED_PARAM) @@ -34,6 +35,8 @@ int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) struct winsize w = { 0, 0, 0, 0 }; int ret; + INIT_G(); + /* We use _stderr_ in order to make resize usable * in shell backticks (those redirect stdout away from tty). * NB: other versions of resize open "/dev/tty" diff --git a/coreutils/dd.c b/coreutils/dd.c index a5b8882a0..4dc302926 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c @@ -111,6 +111,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ /* we have to zero it out because of NOEXEC */ \ memset(&G, 0, sizeof(G)); \ } while (0) diff --git a/coreutils/du.c b/coreutils/du.c index 3d6777670..1240bcbbc 100644 --- a/coreutils/du.c +++ b/coreutils/du.c @@ -87,7 +87,7 @@ struct globals { dev_t dir_dev; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static void print(unsigned long long size, const char *filename) diff --git a/coreutils/expr.c b/coreutils/expr.c index 59a66d9c5..ce6b2d189 100644 --- a/coreutils/expr.c +++ b/coreutils/expr.c @@ -101,7 +101,7 @@ struct globals { char **args; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) /* forward declarations */ static VALUE *eval(void); diff --git a/coreutils/ls.c b/coreutils/ls.c index e8c3e0490..344b4e61e 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -368,6 +368,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ /* we have to zero it out because of NOEXEC */ \ memset(&G, 0, sizeof(G)); \ IF_FEATURE_AUTOWIDTH(G_terminal_width = TERMINAL_WIDTH;) \ diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 1e252caf0..c8a654165 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c @@ -217,6 +217,7 @@ enum { G_pseudo_offset = 0 }; #endif #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ G.bytes_per_block = 32; \ } while (0) diff --git a/coreutils/tail.c b/coreutils/tail.c index cdc9fb66a..39f87679e 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c @@ -56,7 +56,7 @@ struct globals { bool exitcode; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static void tail_xprint_header(const char *fmt, const char *filename) { diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index a5e53576c..c671b9252 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c @@ -100,7 +100,7 @@ struct globals { #define names (G.names) #define cur (G.cur ) #define cmd (G.cmd ) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(G)) / sizeof(cmd[0]) - 1 }; diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 6b8d53b13..3625ffee8 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c @@ -200,6 +200,7 @@ struct globals { #define user_id (G.user_id ) #define signal_nr (G.signal_nr ) #define INIT_G() do { \ + setup_common_bufsiz(); \ user_id = -1; \ signal_nr = 15; \ } while (0) diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index b534568c2..59514a1a6 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c @@ -172,6 +172,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ } while (0) diff --git a/editors/sed.c b/editors/sed.c index 330190e78..ed48de17f 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -164,6 +164,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ G.sed_cmd_tail = &G.sed_cmd_head; \ } while (0) diff --git a/findutils/find.c b/findutils/find.c index 32d830337..d71c69782 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -424,6 +424,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ /* we have to zero it out because of NOEXEC */ \ memset(&G, 0, sizeof(G)); \ diff --git a/findutils/grep.c b/findutils/grep.c index a669ac80b..b072cd441 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -204,6 +204,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ } while (0) #define max_matches (G.max_matches ) diff --git a/findutils/xargs.c b/findutils/xargs.c index bfbd94960..ae01a49be 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c @@ -103,6 +103,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \ IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \ IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\n';) \ diff --git a/init/bootchartd.c b/init/bootchartd.c index 5101b28ae..7f511e650 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c @@ -117,7 +117,7 @@ struct globals { char jiffy_line[COMMON_BUFSIZE]; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static void dump_file(FILE *fp, const char *filename) { diff --git a/loginutils/login.c b/loginutils/login.c index ea7c5a23d..94b6c45db 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -140,7 +140,7 @@ struct globals { struct termios tty_attrs; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) #if ENABLE_FEATURE_NOLOGIN diff --git a/miscutils/crond.c b/miscutils/crond.c index 8536d43c5..f96c96ee7 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c @@ -143,6 +143,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ G.log_level = 8; \ G.crontab_dir_name = CRONTABS; \ } while (0) diff --git a/miscutils/dc.c b/miscutils/dc.c index 3fbb89f5b..4d92bc3d0 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c @@ -53,6 +53,7 @@ enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof( #define base (G.base ) #define stack (G.stack ) #define INIT_G() do { \ + setup_common_bufsiz(); \ base = 10; \ } while (0) diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index 9e141de2f..b4c5876d4 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c @@ -432,6 +432,7 @@ struct globals { #define hwif_ctrl (G.hwif_ctrl ) #define hwif_irq (G.hwif_irq ) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ } while (0) diff --git a/networking/arp.c b/networking/arp.c index 5f7818663..9381eb53a 100644 --- a/networking/arp.c +++ b/networking/arp.c @@ -76,6 +76,7 @@ struct globals { #define device (G.device ) #define hw_set (G.hw_set ) #define INIT_G() do { \ + setup_common_bufsiz(); \ device = ""; \ } while (0) diff --git a/networking/arping.c b/networking/arping.c index 52f5ba51f..6b0de4de2 100644 --- a/networking/arping.c +++ b/networking/arping.c @@ -77,6 +77,7 @@ struct globals { #define brd_recv (G.brd_recv ) #define req_recv (G.req_recv ) #define INIT_G() do { \ + setup_common_bufsiz(); \ count = -1; \ } while (0) diff --git a/networking/ftpd.c b/networking/ftpd.c index 8553a28f5..360d1e6be 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c @@ -126,6 +126,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ /* Moved to main */ \ /*strcpy(G.msg_ok + 4, MSG_OK );*/ \ /*strcpy(G.msg_err + 4, MSG_ERR);*/ \ diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index 61bc45c4e..91fb4569a 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c @@ -71,6 +71,7 @@ enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) }; #define do_continue (G.do_continue ) #define buf (G.buf ) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ } while (0) diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 399ff6b5d..25b04c9d7 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -131,7 +131,7 @@ struct globals { char *shell; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static const char keywords_up_down[] ALIGN1 = diff --git a/networking/inetd.c b/networking/inetd.c index aa35ffa2b..8d44b5198 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -350,6 +350,7 @@ enum { LINE_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line) }; #define allsock (G.allsock ) #define line (G.line ) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ rlim_ofile_cur = OPEN_MAX; \ global_queuelen = 128; \ diff --git a/networking/ping.c b/networking/ping.c index 761660979..cfe682646 100644 --- a/networking/ping.c +++ b/networking/ping.c @@ -188,7 +188,7 @@ struct globals { char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static void noresp(int ign UNUSED_PARAM) { @@ -398,6 +398,7 @@ struct globals { #define pingaddr (G.pingaddr ) #define rcvd_tbl (G.rcvd_tbl ) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ datalen = DEFDATALEN; \ timeout = MAXWAIT; \ diff --git a/networking/slattach.c b/networking/slattach.c index d9d8fe7b8..2d1305e32 100644 --- a/networking/slattach.c +++ b/networking/slattach.c @@ -39,7 +39,7 @@ struct globals { #define handle (G.handle ) #define saved_disc (G.saved_disc ) #define saved_state (G.saved_state ) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) /* diff --git a/networking/tc.c b/networking/tc.c index 1372ca081..d0bcbdeaa 100644 --- a/networking/tc.c +++ b/networking/tc.c @@ -71,6 +71,7 @@ struct globals { #define filter_prio (G.filter_prio) #define filter_proto (G.filter_proto) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ } while (0) diff --git a/networking/tcpudp.c b/networking/tcpudp.c index 624973042..31bc70459 100644 --- a/networking/tcpudp.c +++ b/networking/tcpudp.c @@ -101,6 +101,7 @@ struct globals { #define env_cur (G.env_cur ) #define env_var (G.env_var ) #define INIT_G() do { \ + setup_common_bufsiz(); \ cmax = 30; \ env_cur = &env_var[0]; \ } while (0) diff --git a/networking/telnet.c b/networking/telnet.c index 2946bc831..d2daf5c8c 100644 --- a/networking/telnet.c +++ b/networking/telnet.c @@ -111,6 +111,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ } while (0) diff --git a/networking/telnetd.c b/networking/telnetd.c index 13d5a8f64..13c36aa46 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c @@ -85,6 +85,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ G.loginpath = "/bin/login"; \ G.issuefile = "/etc/issue.net"; \ } while (0) diff --git a/networking/tftp.c b/networking/tftp.c index 8aeb79aca..e879c4674 100644 --- a/networking/tftp.c +++ b/networking/tftp.c @@ -131,6 +131,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ } while (0) diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c index 1722a85de..f52a0cf88 100644 --- a/networking/udhcp/dhcprelay.c +++ b/networking/udhcp/dhcprelay.c @@ -34,6 +34,7 @@ struct xid_item { } FIX_ALIASING; #define dhcprelay_xid_list (*(struct xid_item*)bb_common_bufsiz1) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client) { @@ -257,6 +258,8 @@ int dhcprelay_main(int argc, char **argv) int num_sockets, max_socket; uint32_t our_nip; + INIT_G(); + server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_BROADCAST); server_addr.sin_port = htons(SERVER_PORT); diff --git a/networking/zcip.c b/networking/zcip.c index 79643458c..47f3216a0 100644 --- a/networking/zcip.c +++ b/networking/zcip.c @@ -92,7 +92,7 @@ struct globals { uint32_t localnet_ip; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) /** diff --git a/procps/free.c b/procps/free.c index 9fde64b64..fca9a2242 100644 --- a/procps/free.c +++ b/procps/free.c @@ -37,7 +37,7 @@ struct globals { #endif } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static unsigned long long scale(unsigned long d) diff --git a/procps/fuser.c b/procps/fuser.c index 2cda0f9d7..6dac852ed 100644 --- a/procps/fuser.c +++ b/procps/fuser.c @@ -46,6 +46,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ G.mypid = getpid(); \ G.killsig = SIGKILL; \ } while (0) diff --git a/procps/ps.c b/procps/ps.c index 65d62e256..08dfce12e 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -153,7 +153,7 @@ struct globals { #define buffer (G.buffer ) #define terminal_width (G.terminal_width ) #define kernel_HZ (G.kernel_HZ ) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) #if ENABLE_FEATURE_PS_TIME /* for ELF executables, notes are pushed before environment and args */ diff --git a/procps/top.c b/procps/top.c index 1c42b249c..640bcdc6d 100644 --- a/procps/top.c +++ b/procps/top.c @@ -202,6 +202,7 @@ enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) }; #define total_pcpu (G.total_pcpu ) #define line_buf (G.line_buf ) #define INIT_G() do { \ + setup_common_bufsiz(); \ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \ } while (0) diff --git a/runit/runsv.c b/runit/runsv.c index 8833f4c96..e0e31508a 100644 --- a/runit/runsv.c +++ b/runit/runsv.c @@ -115,6 +115,7 @@ struct globals { #define dir (G.dir ) #define svd (G.svd ) #define INIT_G() do { \ + setup_common_bufsiz(); \ pidchanged = 1; \ } while (0) diff --git a/runit/runsvdir.c b/runit/runsvdir.c index 49c8f5b48..2b7927542 100644 --- a/runit/runsvdir.c +++ b/runit/runsvdir.c @@ -93,7 +93,7 @@ struct globals { #define logpipe (G.logpipe ) #define pfd (G.pfd ) #define stamplog (G.stamplog ) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static void fatal2_cannot(const char *m1, const char *m2) { diff --git a/runit/sv.c b/runit/sv.c index e83a29781..2a256a6b4 100644 --- a/runit/sv.c +++ b/runit/sv.c @@ -207,7 +207,7 @@ struct globals { #define tstart (G.tstart ) #define tnow (G.tnow ) #define svstatus (G.svstatus ) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) #define str_equal(s,t) (!strcmp((s), (t))) diff --git a/scripts/generate_BUFSIZ.sh b/scripts/generate_BUFSIZ.sh index afe9eee1e..bb0738641 100755 --- a/scripts/generate_BUFSIZ.sh +++ b/scripts/generate_BUFSIZ.sh @@ -111,4 +111,6 @@ fi if test $OLD != $REM; then echo "Space in _end[] is $REM bytes. Rerun make to use larger COMMON_BUFSIZE." +else + echo "COMMON_BUFSIZE = $REM bytes" fi diff --git a/selinux/setfiles.c b/selinux/setfiles.c index 441345ae9..51a7e63bd 100644 --- a/selinux/setfiles.c +++ b/selinux/setfiles.c @@ -80,6 +80,7 @@ struct globals { #define G (*(struct globals*)bb_common_bufsiz1) void BUG_setfiles_globals_too_big(void); #define INIT_G() do { \ + setup_common_bufsiz(); \ if (sizeof(G) > COMMON_BUFSIZE) \ BUG_setfiles_globals_too_big(); \ /* memset(&G, 0, sizeof(G)); - already is */ \ diff --git a/sysklogd/logread.c b/sysklogd/logread.c index ebd7f8b2c..5b999730a 100644 --- a/sysklogd/logread.c +++ b/sysklogd/logread.c @@ -73,6 +73,7 @@ struct globals { #define SMrdn (G.SMrdn) #define shbuf (G.shbuf) #define INIT_G() do { \ + setup_common_bufsiz(); \ memcpy(SMrup, init_sem, sizeof(init_sem)); \ } while (0) diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 7473b1855..37514eb54 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -288,6 +288,7 @@ struct globals { } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) #define INIT_G() do { \ + setup_common_bufsiz(); \ IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.maj = -1;) \ IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.mode = 0660;) \ } while (0) diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c index f9451792b..dcb53f008 100644 --- a/util-linux/mkswap.c +++ b/util-linux/mkswap.c @@ -76,6 +76,7 @@ struct swap_header_v1 { #define NWORDS 129 #define hdr ((struct swap_header_v1*)bb_common_bufsiz1) +#define INIT_G() do { setup_common_bufsiz(); } while (0) struct BUG_sizes { char swap_header_v1_wrong[sizeof(*hdr) != (NWORDS * 4) ? -1 : 1]; @@ -93,6 +94,8 @@ int mkswap_main(int argc UNUSED_PARAM, char **argv) off_t len; const char *label = ""; + INIT_G(); + opt_complementary = "-1"; /* at least one param */ /* TODO: -p PAGESZ, -U UUID */ getopt32(argv, "L:", &label); diff --git a/util-linux/more.c b/util-linux/more.c index 58be3ac3b..95cbdd994 100644 --- a/util-linux/more.c +++ b/util-linux/more.c @@ -33,10 +33,10 @@ struct globals { struct termios new_settings; } FIX_ALIASING; #define G (*(struct globals*)bb_common_bufsiz1) -#define INIT_G() ((void)0) #define initial_settings (G.initial_settings) #define new_settings (G.new_settings ) #define cin_fileno (G.cin_fileno ) +#define INIT_G() do { setup_common_bufsiz(); } while (0) #define setTermSettings(fd, argp) \ do { \ diff --git a/util-linux/mount.c b/util-linux/mount.c index e5c85feff..244f4fa27 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -457,7 +457,7 @@ enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_b #endif #define fslist (G.fslist ) #define getmntent_buf (G.getmntent_buf ) -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) #if ENABLE_FEATURE_MTAB_SUPPORT /* diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index 43228a6ba..6713852e5 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c @@ -72,7 +72,7 @@ struct globals { #define save_g_flags() ((void)0) #define restore_g_flags() ((void)0) #endif -#define INIT_G() do { } while (0) +#define INIT_G() do { setup_common_bufsiz(); } while (0) #define do_swapoff (applet_name[5] == 'f') diff --git a/util-linux/uevent.c b/util-linux/uevent.c index 58668fa5d..b98fe6160 100644 --- a/util-linux/uevent.c +++ b/util-linux/uevent.c @@ -31,6 +31,7 @@ #define BUFFER_SIZE 16*1024 #define env ((char **)bb_common_bufsiz1) +#define INIT_G() do { setup_common_bufsiz(); } while (0) enum { MAX_ENV = COMMON_BUFSIZE / sizeof(env[0]) - 1, }; @@ -46,6 +47,8 @@ int uevent_main(int argc UNUSED_PARAM, char **argv) struct sockaddr_nl sa; int fd; + INIT_G(); + argv++; // Subscribe for UEVENT kernel messages -- cgit v1.2.3-55-g6feb From 9de2e5a22213842da5b116723392de88de9ed419 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 21 Apr 2016 18:38:51 +0200 Subject: *: hopefully all setup_common_bufsiz() are in place Signed-off-by: Denys Vlasenko --- archival/tar.c | 2 ++ console-tools/dumpkmap.c | 1 + coreutils/catv.c | 4 +++- coreutils/cksum.c | 6 +++--- coreutils/date.c | 6 +++--- coreutils/split.c | 2 ++ coreutils/stat.c | 7 +++---- coreutils/sum.c | 4 +++- coreutils/tee.c | 6 +++--- editors/diff.c | 1 + editors/ed.c | 8 ++++---- miscutils/chat.c | 3 ++- miscutils/conspy.c | 7 ++++--- miscutils/fbsplash.c | 7 ++++--- miscutils/inotifyd.c | 6 +++--- miscutils/less.c | 7 ++++--- miscutils/microcom.c | 6 +++--- networking/httpd.c | 1 + networking/isrv_identd.c | 7 ++++--- networking/libiproute/ipaddress.c | 5 ++++- networking/libiproute/ipneigh.c | 3 +++ networking/libiproute/iproute.c | 3 +++ networking/nc.c | 3 ++- procps/nmeter.c | 9 ++++----- runit/svlogd.c | 4 ++-- sysklogd/klogd.c | 7 ++++--- sysklogd/logger.c | 2 ++ util-linux/script.c | 10 +++++----- util-linux/umount.c | 1 + 29 files changed, 83 insertions(+), 55 deletions(-) (limited to 'runit') diff --git a/archival/tar.c b/archival/tar.c index caf4363de..346a9404e 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -162,6 +162,7 @@ #define block_buf bb_common_bufsiz1 +#define INIT_G() do { setup_common_bufsiz(); } while (0) #if ENABLE_FEATURE_TAR_CREATE @@ -964,6 +965,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv) #if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM llist_t *excludes = NULL; #endif + INIT_G(); /* Initialise default values */ tar_handle = init_handle(); diff --git a/console-tools/dumpkmap.c b/console-tools/dumpkmap.c index 6412dffc8..b6fd466dc 100644 --- a/console-tools/dumpkmap.c +++ b/console-tools/dumpkmap.c @@ -38,6 +38,7 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv) struct kbentry ke; int i, j, fd; #define flags bb_common_bufsiz1 + setup_common_bufsiz(); /* When user accidentally runs "dumpkmap FILE" * instead of "dumpkmap >FILE", we'd dump binary stuff to tty. diff --git a/coreutils/catv.c b/coreutils/catv.c index 801d2451d..0e71368a5 100644 --- a/coreutils/catv.c +++ b/coreutils/catv.c @@ -49,6 +49,9 @@ int catv_main(int argc UNUSED_PARAM, char **argv) /* Read from stdin if there's nothing else to do. */ if (!argv[0]) *--argv = (char*)"-"; + +#define read_buf bb_common_bufsiz1 + setup_common_bufsiz(); do { fd = open_or_warn_stdin(*argv); if (fd < 0) { @@ -58,7 +61,6 @@ int catv_main(int argc UNUSED_PARAM, char **argv) for (;;) { int i, res; -#define read_buf bb_common_bufsiz1 res = read(fd, read_buf, COMMON_BUFSIZE); if (res < 0) retval = EXIT_FAILURE; diff --git a/coreutils/cksum.c b/coreutils/cksum.c index d8351e7c6..8a8a39f68 100644 --- a/coreutils/cksum.c +++ b/coreutils/cksum.c @@ -33,6 +33,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv) argv++; #endif + setup_common_bufsiz(); do { int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input); @@ -43,9 +44,8 @@ int cksum_main(int argc UNUSED_PARAM, char **argv) crc = 0; length = 0; -#define read_buf bb_common_bufsiz1 -#define sizeof_read_buf COMMON_BUFSIZE - while ((bytes_read = safe_read(fd, read_buf, sizeof_read_buf)) > 0) { +#define read_buf bb_common_bufsiz1 + while ((bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE)) > 0) { length += bytes_read; crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table); } diff --git a/coreutils/date.c b/coreutils/date.c index 59b4b8f2a..ff3214d85 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -368,8 +368,8 @@ int date_main(int argc UNUSED_PARAM, char **argv) } #endif -#define date_buf bb_common_bufsiz1 -#define sizeof_date_buf COMMON_BUFSIZE +#define date_buf bb_common_bufsiz1 + setup_common_bufsiz(); if (*fmt_dt2str == '\0') { /* With no format string, just print a blank line */ date_buf[0] = '\0'; @@ -379,7 +379,7 @@ int date_main(int argc UNUSED_PARAM, char **argv) fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S"; } /* Generate output string */ - strftime(date_buf, sizeof_date_buf, fmt_dt2str, &tm_time); + strftime(date_buf, COMMON_BUFSIZE, fmt_dt2str, &tm_time); } puts(date_buf); diff --git a/coreutils/split.c b/coreutils/split.c index b2da74e27..e67c3de66 100644 --- a/coreutils/split.c +++ b/coreutils/split.c @@ -79,6 +79,8 @@ int split_main(int argc UNUSED_PARAM, char **argv) ssize_t bytes_read, to_write; char *src; + setup_common_bufsiz(); + opt_complementary = "?2:a+"; /* max 2 args; -a N */ opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len); diff --git a/coreutils/stat.c b/coreutils/stat.c index 78df9c948..ddcfcf2d7 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c @@ -158,10 +158,9 @@ static const char *human_time(time_t t) /* coreutils 6.3 compat: */ /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/ -#define buf bb_common_bufsiz1 -#define sizeof_buf COMMON_BUFSIZE - - strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof_buf, &t), ".000000000"); +#define buf bb_common_bufsiz1 + setup_common_bufsiz(); + strcpy(strftime_YYYYMMDDHHMMSS(buf, COMMON_BUFSIZE, &t), ".000000000"); return buf; #undef buf } diff --git a/coreutils/sum.c b/coreutils/sum.c index cc6677221..ec9ed2a11 100644 --- a/coreutils/sum.c +++ b/coreutils/sum.c @@ -31,12 +31,14 @@ enum { SUM_BSD, PRINT_NAME, SUM_SYSV }; /* Return 1 if successful. */ static unsigned sum_file(const char *file, unsigned type) { -#define buf bb_common_bufsiz1 unsigned long long total_bytes = 0; int fd, r; /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ unsigned s = 0; +#define buf bb_common_bufsiz1 + setup_common_bufsiz(); + fd = open_or_warn_stdin(file); if (fd == -1) return 0; diff --git a/coreutils/tee.c b/coreutils/tee.c index a0e177cbc..a68e9446f 100644 --- a/coreutils/tee.c +++ b/coreutils/tee.c @@ -37,8 +37,8 @@ int tee_main(int argc, char **argv) //TODO: make unconditional #if ENABLE_FEATURE_TEE_USE_BLOCK_IO ssize_t c; -# define buf bb_common_bufsiz1 -# define sizeof_buf COMMON_BUFSIZE +# define buf bb_common_bufsiz1 + setup_common_bufsiz(); #else int c; #endif @@ -81,7 +81,7 @@ int tee_main(int argc, char **argv) /* names[0] will be filled later */ #if ENABLE_FEATURE_TEE_USE_BLOCK_IO - while ((c = safe_read(STDIN_FILENO, buf, sizeof_buf)) > 0) { + while ((c = safe_read(STDIN_FILENO, buf, COMMON_BUFSIZE)) > 0) { fp = files; do fwrite(buf, 1, c, *fp); diff --git a/editors/diff.c b/editors/diff.c index 3c8e9074a..ff269360f 100644 --- a/editors/diff.c +++ b/editors/diff.c @@ -749,6 +749,7 @@ static int diffreg(char *file[2]) fp[i] = fdopen(fd, "r"); } + setup_common_bufsiz(); while (1) { const size_t sz = COMMON_BUFSIZE / 2; char *const buf0 = bb_common_bufsiz1; diff --git a/editors/ed.c b/editors/ed.c index 8da7b1dd5..c028b78cb 100644 --- a/editors/ed.c +++ b/editors/ed.c @@ -33,12 +33,11 @@ typedef struct LINE { } LINE; -#define searchString bb_common_bufsiz1 -#define sizeof_searchString COMMON_BUFSIZE +#define searchString bb_common_bufsiz1 enum { - USERSIZE = sizeof_searchString > 1024 ? 1024 - : sizeof_searchString - 1, /* max line length typed in by user */ + USERSIZE = COMMON_BUFSIZE > 1024 ? 1024 + : COMMON_BUFSIZE - 1, /* max line length typed in by user */ INITBUF_SIZE = 1024, /* initial buffer size */ }; @@ -68,6 +67,7 @@ struct globals { #define lines (G.lines ) #define marks (G.marks ) #define INIT_G() do { \ + setup_common_bufsiz(); \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ } while (0) diff --git a/miscutils/chat.c b/miscutils/chat.c index 25850dd20..6b429f2a6 100644 --- a/miscutils/chat.c +++ b/miscutils/chat.c @@ -286,9 +286,10 @@ int chat_main(int argc UNUSED_PARAM, char **argv) && poll(&pfd, 1, timeout) > 0 && (pfd.revents & POLLIN) ) { -#define buf bb_common_bufsiz1 llist_t *l; ssize_t delta; +#define buf bb_common_bufsiz1 + setup_common_bufsiz(); // read next char from device if (safe_read(STDIN_FILENO, buf+buf_len, 1) > 0) { diff --git a/miscutils/conspy.c b/miscutils/conspy.c index 0d96a5f9a..f6468c116 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c @@ -364,8 +364,6 @@ int conspy_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int conspy_main(int argc UNUSED_PARAM, char **argv) { char tty_name[sizeof(DEV_TTY "NN")]; -#define keybuf bb_common_bufsiz1 -#define sizeof_keybuf COMMON_BUFSIZE struct termios termbuf; unsigned opts; unsigned ttynum; @@ -384,6 +382,9 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) applet_long_options = getopt_longopts; #endif +#define keybuf bb_common_bufsiz1 + setup_common_bufsiz(); + INIT_G(); strcpy(G.vcsa_name, DEV_VCSA); @@ -515,7 +516,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) default: // Read the keys pressed k = keybuf + G.key_count; - bytes_read = read(G.kbd_fd, k, sizeof_keybuf - G.key_count); + bytes_read = read(G.kbd_fd, k, COMMON_BUFSIZE - G.key_count); if (bytes_read < 0) goto abort; diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index b26ad2c15..3ddf8a242 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c @@ -373,12 +373,13 @@ static void fb_drawimage(void) * - A raster of Width * Height pixels in triplets of rgb * in pure binary by 1 or 2 bytes. (we support only 1 byte) */ -#define concat_buf bb_common_bufsiz1 -#define sizeof_concat_buf COMMON_BUFSIZE +#define concat_buf bb_common_bufsiz1 + setup_common_bufsiz(); + read_ptr = concat_buf; while (1) { int w, h, max_color_val; - int rem = concat_buf + sizeof_concat_buf - read_ptr; + int rem = concat_buf + COMMON_BUFSIZE - read_ptr; if (rem < 2 || fgets(read_ptr, rem, theme_file) == NULL ) { diff --git a/miscutils/inotifyd.c b/miscutils/inotifyd.c index 1d28e8f99..52db08ada 100644 --- a/miscutils/inotifyd.c +++ b/miscutils/inotifyd.c @@ -162,10 +162,10 @@ int inotifyd_main(int argc, char **argv) // read out all pending events // (NB: len must be int, not ssize_t or long!) +#define eventbuf bb_common_bufsiz1 + setup_common_bufsiz(); xioctl(pfd.fd, FIONREAD, &len); -#define eventbuf bb_common_bufsiz1 -#define sizeof_eventbuf COMMON_BUFSIZE - ie = buf = (len <= sizeof_eventbuf) ? eventbuf : xmalloc(len); + ie = buf = (len <= COMMON_BUFSIZE) ? eventbuf : xmalloc(len); len = full_read(pfd.fd, buf, len); // process events. N.B. events may vary in length while (len > 0) { diff --git a/miscutils/less.c b/miscutils/less.c index 94ecf1686..d7076dbbc 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -440,8 +440,6 @@ static int at_end(void) */ static void read_lines(void) { -#define readbuf bb_common_bufsiz1 -#define sizeof_readbuf COMMON_BUFSIZE char *current_line, *p; int w = width; char last_terminated = terminated; @@ -451,6 +449,9 @@ static void read_lines(void) unsigned old_max_fline = max_fline; #endif +#define readbuf bb_common_bufsiz1 + setup_common_bufsiz(); + /* (careful: max_fline can be -1) */ if (max_fline + 1 > MAXLINES) return; @@ -482,7 +483,7 @@ static void read_lines(void) time_t t; errno = 0; - eof_error = safe_read(STDIN_FILENO, readbuf, sizeof_readbuf); + eof_error = safe_read(STDIN_FILENO, readbuf, COMMON_BUFSIZE); if (errno != EAGAIN) break; t = time(NULL); diff --git a/miscutils/microcom.c b/miscutils/microcom.c index 5eb2e6743..d9e8f9187 100644 --- a/miscutils/microcom.c +++ b/miscutils/microcom.c @@ -156,11 +156,11 @@ int microcom_main(int argc UNUSED_PARAM, char **argv) skip_write: ; } if (pfd[0].revents) { -#define iobuf bb_common_bufsiz1 -#define sizeof_iobuf COMMON_BUFSIZE ssize_t len; +#define iobuf bb_common_bufsiz1 + setup_common_bufsiz(); // read from device -> write to stdout - len = safe_read(sfd, iobuf, sizeof_iobuf); + len = safe_read(sfd, iobuf, COMMON_BUFSIZE); if (len > 0) full_write(STDOUT_FILENO, iobuf, len); else { diff --git a/networking/httpd.c b/networking/httpd.c index ef90770ac..abe83a458 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -370,6 +370,7 @@ enum { # define content_gzip 0 #endif #define INIT_G() do { \ + setup_common_bufsiz(); \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \ IF_FEATURE_HTTPD_RANGES(range_start = -1;) \ diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c index f63ed8ee4..8a15926e5 100644 --- a/networking/isrv_identd.c +++ b/networking/isrv_identd.c @@ -29,8 +29,7 @@ typedef struct identd_buf_t { char buf[64 - sizeof(int)]; } identd_buf_t; -#define bogouser bb_common_bufsiz1 -#define sizeof_bogouser COMMON_BUFSIZE +#define bogouser bb_common_bufsiz1 static int new_peer(isrv_state_t *state, int fd) { @@ -117,10 +116,12 @@ int fakeidentd_main(int argc UNUSED_PARAM, char **argv) unsigned opt; int fd; + setup_common_bufsiz(); + opt = getopt32(argv, "fiwb:", &bind_address); strcpy(bogouser, "nobody"); if (argv[optind]) - strncpy(bogouser, argv[optind], sizeof_bogouser - 1); + strncpy(bogouser, argv[optind], COMMON_BUFSIZE - 1); /* Daemonize if no -f and no -i and no -w */ if (!(opt & OPT_fiw)) diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 2c0f514c7..d9e099607 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -41,7 +41,7 @@ struct filter_t { typedef struct filter_t filter_t; #define G_filter (*(filter_t*)bb_common_bufsiz1) - +#define INIT_G() do { setup_common_bufsiz(); } while (0) static void print_link_flags(unsigned flags, unsigned mdown) { @@ -745,6 +745,9 @@ int FAST_FUNC do_ipaddr(char **argv) /* 0 1 2 3 4 5 6 7 8 */ "add\0""change\0""chg\0""replace\0""delete\0""list\0""show\0""lst\0""flush\0"; int cmd = 2; + + INIT_G(); + if (*argv) { cmd = index_in_substrings(commands, *argv); if (cmd < 0) diff --git a/networking/libiproute/ipneigh.c b/networking/libiproute/ipneigh.c index 151d3d109..d2028b7b6 100644 --- a/networking/libiproute/ipneigh.c +++ b/networking/libiproute/ipneigh.c @@ -42,6 +42,7 @@ struct filter_t { typedef struct filter_t filter_t; #define G_filter (*(filter_t*)bb_common_bufsiz1) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static int flush_update(void) { @@ -339,6 +340,8 @@ int FAST_FUNC do_ipneigh(char **argv) /*0-1*/ "show\0" "flush\0"; int command_num; + INIT_G(); + if (!*argv) return ipneigh_list_or_flush(argv, 0); diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index 34d4f4758..e674e9a0d 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c @@ -45,6 +45,7 @@ struct filter_t { typedef struct filter_t filter_t; #define G_filter (*(filter_t*)bb_common_bufsiz1) +#define INIT_G() do { setup_common_bufsiz(); } while (0) static int flush_update(void) { @@ -903,6 +904,8 @@ int FAST_FUNC do_iproute(char **argv) unsigned flags = 0; int cmd = RTM_NEWROUTE; + INIT_G(); + if (!*argv) return iproute_list_or_flush(argv, 0); diff --git a/networking/nc.c b/networking/nc.c index 50edee450..13a9b48a8 100644 --- a/networking/nc.c +++ b/networking/nc.c @@ -239,6 +239,8 @@ int nc_main(int argc, char **argv) FD_SET(cfd, &readfds); FD_SET(STDIN_FILENO, &readfds); +#define iobuf bb_common_bufsiz1 + setup_common_bufsiz(); for (;;) { int fd; int ofd; @@ -249,7 +251,6 @@ int nc_main(int argc, char **argv) if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0) bb_perror_msg_and_die("select"); -#define iobuf bb_common_bufsiz1 fd = STDIN_FILENO; while (1) { if (FD_ISSET(fd, &testfds)) { diff --git a/procps/nmeter.c b/procps/nmeter.c index efa3d553d..3eac2d3b2 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -109,16 +109,15 @@ struct globals { #define proc_meminfo (G.proc_meminfo ) #define proc_diskstats (G.proc_diskstats ) #define proc_sys_fs_filenr (G.proc_sys_fs_filenr) +#define outbuf bb_common_bufsiz1 #define INIT_G() do { \ + setup_common_bufsiz(); \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ cur_outbuf = outbuf; \ G.final_char = '\n'; \ G.deltanz = G.delta = 1000000; \ } while (0) -#define outbuf bb_common_bufsiz1 -#define sizeof_outbuf COMMON_BUFSIZE - static inline void reset_outbuf(void) { cur_outbuf = outbuf; @@ -141,7 +140,7 @@ static void print_outbuf(void) static void put(const char *s) { char *p = cur_outbuf; - int sz = outbuf + sizeof_outbuf - p; + int sz = outbuf + COMMON_BUFSIZE - p; while (*s && --sz >= 0) *p++ = *s++; cur_outbuf = p; @@ -149,7 +148,7 @@ static void put(const char *s) static void put_c(char c) { - if (cur_outbuf < outbuf + sizeof_outbuf) + if (cur_outbuf < outbuf + COMMON_BUFSIZE) *cur_outbuf++ = c; } diff --git a/runit/svlogd.c b/runit/svlogd.c index 09efdb695..7cae81cb2 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c @@ -234,7 +234,9 @@ struct globals { #define blocked_sigset (G.blocked_sigset) #define fl_flag_0 (G.fl_flag_0 ) #define dirn (G.dirn ) +#define line bb_common_bufsiz1 #define INIT_G() do { \ + setup_common_bufsiz(); \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ linemax = 1000; \ /*buflen = 1024;*/ \ @@ -242,8 +244,6 @@ struct globals { replace = ""; \ } while (0) -#define line bb_common_bufsiz1 - #define FATAL "fatal: " #define WARNING "warning: " diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index 845c49a5e..4db72110d 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c @@ -146,10 +146,9 @@ static void klogd_close(void) #endif -#define log_buffer bb_common_bufsiz1 -#define sizeof_log_buffer COMMON_BUFSIZE +#define log_buffer bb_common_bufsiz1 enum { - KLOGD_LOGBUF_SIZE = sizeof_log_buffer, + KLOGD_LOGBUF_SIZE = COMMON_BUFSIZE, OPT_LEVEL = (1 << 0), OPT_FOREGROUND = (1 << 1), }; @@ -175,6 +174,8 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) int opt; int used; + setup_common_bufsiz(); + opt = getopt32(argv, "c:n", &opt_c); if (opt & OPT_LEVEL) { /* Valid levels are between 1 and 8 */ diff --git a/sysklogd/logger.c b/sysklogd/logger.c index b3ca85703..f9eafeb25 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c @@ -99,6 +99,8 @@ int logger_main(int argc UNUSED_PARAM, char **argv) int opt; int i = 0; + setup_common_bufsiz(); + /* Fill out the name string early (may be overwritten later) */ str_t = uid2uname_utoa(geteuid()); diff --git a/util-linux/script.c b/util-linux/script.c index 6195161bc..86475c1f1 100644 --- a/util-linux/script.c +++ b/util-linux/script.c @@ -109,12 +109,12 @@ int script_main(int argc UNUSED_PARAM, char **argv) if (child_pid) { /* parent */ -#define buf bb_common_bufsiz1 -#define sizeof_buf COMMON_BUFSIZE struct pollfd pfd[2]; int outfd, count, loop; double oldtime = ENABLE_SCRIPTREPLAY ? time(NULL) : 0; smallint fd_count = 2; +#define buf bb_common_bufsiz1 + setup_common_bufsiz(); outfd = xopen(fname, mode); pfd[0].fd = pty; @@ -136,7 +136,7 @@ int script_main(int argc UNUSED_PARAM, char **argv) } if (pfd[0].revents) { errno = 0; - count = safe_read(pty, buf, sizeof_buf); + count = safe_read(pty, buf, COMMON_BUFSIZE); if (count <= 0 && errno != EAGAIN) { /* err/eof from pty: exit */ goto restore; @@ -159,7 +159,7 @@ int script_main(int argc UNUSED_PARAM, char **argv) } } if (pfd[1].revents) { - count = safe_read(STDIN_FILENO, buf, sizeof_buf); + count = safe_read(STDIN_FILENO, buf, COMMON_BUFSIZE); if (count <= 0) { /* err/eof from stdin: don't read stdin anymore */ pfd[1].revents = 0; @@ -178,7 +178,7 @@ int script_main(int argc UNUSED_PARAM, char **argv) * (util-linux's script doesn't do this. buggy :) */ loop = 999; /* pty is in O_NONBLOCK mode, we exit as soon as buffer is empty */ - while (--loop && (count = safe_read(pty, buf, sizeof_buf)) > 0) { + while (--loop && (count = safe_read(pty, buf, COMMON_BUFSIZE)) > 0) { full_write(STDOUT_FILENO, buf, count); full_write(outfd, buf, count); } diff --git a/util-linux/umount.c b/util-linux/umount.c index be0300394..91da69674 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c @@ -103,6 +103,7 @@ int umount_main(int argc UNUSED_PARAM, char **argv) if (opt & OPT_ALL) bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file); } else { + setup_common_bufsiz(); while (getmntent_r(fp, &me, bb_common_bufsiz1, COMMON_BUFSIZE)) { /* Match fstype if passed */ if (!match_fstype(&me, fstype)) -- cgit v1.2.3-55-g6feb