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 <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2016-04-21 16:26:30 +02:00
parent 5598bdf0d3
commit e6a2f4cc5a
91 changed files with 414 additions and 131 deletions

View File

@ -610,7 +610,8 @@ quiet_cmd_busybox__ ?= LINK $@
"$(LDFLAGS) $(EXTRA_LDFLAGS)" \
"$(core-y)" \
"$(libs-y)" \
"$(LDLIBS)"
"$(LDLIBS)" \
&& $(srctree)/scripts/generate_BUFSIZ.sh include/common_bufsiz.h
# Generate System.map
quiet_cmd_sysmap = SYSMAP
@ -844,12 +845,15 @@ export CPPFLAGS_busybox.lds += -P -C -U$(ARCH)
# Split autoconf.h into include/linux/config/*
quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h
cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs include/bbconfigopts.h include/bbconfigopts_bz2.h
quiet_cmd_gen_common_bufsiz = GEN include/common_bufsiz.h
cmd_gen_common_bufsiz = $(srctree)/scripts/generate_BUFSIZ.sh include/common_bufsiz.h
quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/*
cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config
#bbox# piggybacked generation of few .h files
include/config/MARKER: scripts/basic/split-include include/autoconf.h
$(call cmd,split_autoconf)
$(call cmd,gen_bbconfigopts)
$(call cmd,gen_common_bufsiz)
@touch $@
# Generate some files
@ -965,6 +969,7 @@ CLEAN_FILES += busybox busybox_unstripped* busybox.links \
MRPROPER_DIRS += include/config include2
MRPROPER_FILES += .config .config.old include/asm .version .old_version \
include/NUM_APPLETS.h \
include/common_bufsiz.h \
include/autoconf.h \
include/bbconfigopts.h \
include/bbconfigopts_bz2.h \

View File

@ -11,6 +11,7 @@
* Only supports new ASCII and CRC formats
*/
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
//config:config CPIO
@ -170,7 +171,7 @@ enum {
struct globals {
struct bb_uidgid_t owner_ugid;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
void BUG_cpio_globals_too_big(void);
#define INIT_G() do { \
G.owner_ugid.uid = -1L; \

View File

@ -71,6 +71,7 @@
//usage: "\n -F Don't store or verify checksum"
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
#include "liblzo_interface.h"
@ -443,7 +444,7 @@ struct globals {
chksum_t chksum_in;
chksum_t chksum_out;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
//#define G (*ptr_to_globals)
//#define INIT_G() do {

View File

@ -29,6 +29,7 @@
//usage: "\n -qpc List config files"
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
#include "rpm.h"
@ -93,7 +94,7 @@ struct globals {
rpm_index **mytags;
int tagcount;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
static void extract_cpio(int fd, const char *source_rpm)

View File

@ -146,6 +146,7 @@
#include <fnmatch.h>
#include "libbb.h"
#include "common_bufsiz.h"
#include "bb_archive.h"
/* FIXME: Stop using this non-standard feature */
#ifndef FNM_LEADING_DIR

View File

@ -18,6 +18,7 @@
//usage: "$ dumpkmap > keymap\n"
#include "libbb.h"
#include "common_bufsiz.h"
/* From <linux/kd.h> */
struct kbentry {

View File

@ -14,10 +14,11 @@
//usage: "Resize the screen"
#include "libbb.h"
#include "common_bufsiz.h"
#define ESC "\033"
#define old_termios_p ((struct termios*)&bb_common_bufsiz1)
#define old_termios_p ((struct termios*)bb_common_bufsiz1)
static void
onintr(int sig UNUSED_PARAM)

View File

@ -19,6 +19,7 @@
//usage: "\n -v Don't use ^x or M-x escapes"
#include "libbb.h"
#include "common_bufsiz.h"
#define CATV_OPT_e (1<<0)
#define CATV_OPT_t (1<<1)

View File

@ -13,6 +13,7 @@
//usage: "Calculate the CRC32 checksums of FILES"
#include "libbb.h"
#include "common_bufsiz.h"
/* This is a NOEXEC applet. Be very careful! */
@ -42,8 +43,9 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
crc = 0;
length = 0;
#define read_buf bb_common_bufsiz1
while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 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) {
length += bytes_read;
crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
}

View File

@ -138,6 +138,7 @@
//usage: "Wed Apr 12 18:52:41 MDT 2000\n"
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_FEATURE_DATE_NANO
# include <sys/syscall.h>
#endif
@ -367,7 +368,8 @@ int date_main(int argc UNUSED_PARAM, char **argv)
}
#endif
#define date_buf bb_common_bufsiz1
#define date_buf bb_common_bufsiz1
#define sizeof_date_buf COMMON_BUFSIZE
if (*fmt_dt2str == '\0') {
/* With no format string, just print a blank line */
date_buf[0] = '\0';
@ -377,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, sizeof_date_buf, fmt_dt2str, &tm_time);
}
puts(date_buf);

View File

@ -91,6 +91,7 @@
//usage: "4+0 records out\n"
#include "libbb.h"
#include "common_bufsiz.h"
/* This is a NOEXEC applet. Be very careful! */
@ -108,7 +109,7 @@ struct globals {
#endif
int flags;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \

View File

@ -58,6 +58,7 @@
//usage: "2417 .\n"
#include "libbb.h"
#include "common_bufsiz.h"
enum {
OPT_a_files_too = (1 << 0),
@ -85,7 +86,7 @@ struct globals {
int du_depth;
dev_t dir_dev;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)

View File

@ -61,6 +61,7 @@
//usage: "of characters matched or 0."
#include "libbb.h"
#include "common_bufsiz.h"
#include "xregex.h"
#if ENABLE_EXPR_MATH_SUPPORT_64
@ -99,7 +100,7 @@ typedef struct valinfo VALUE;
struct globals {
char **args;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
/* forward declarations */

View File

@ -93,6 +93,7 @@
//usage: )
#include "libbb.h"
#include "common_bufsiz.h"
#include "unicode.h"
@ -365,7 +366,7 @@ struct globals {
time_t current_time_t;
#endif
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \

View File

@ -20,6 +20,7 @@
/* #include "libbb.h" - done in od.c */
#include "common_bufsiz.h"
#define assert(a) ((void)0)
@ -214,7 +215,7 @@ struct globals {
#if !ENABLE_LONG_OPTS
enum { G_pseudo_offset = 0 };
#endif
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
G.bytes_per_block = 32; \

View File

@ -22,6 +22,7 @@
//usage: "$ cat TODO | split -a 2 -l 2 TODO_\n"
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_FEATURE_SPLIT_FANCY
static const struct suffix_mult split_suffixes[] = {

View File

@ -103,6 +103,7 @@
//usage: )
#include "libbb.h"
#include "common_bufsiz.h"
enum {
OPT_TERSE = (1 << 0),
@ -157,9 +158,10 @@ 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 buf bb_common_bufsiz1
#define sizeof_buf COMMON_BUFSIZE
strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &t), ".000000000");
strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof_buf, &t), ".000000000");
return buf;
#undef buf
}

View File

@ -32,6 +32,7 @@
//usage: "\n [SETTING] See manpage"
#include "libbb.h"
#include "common_bufsiz.h"
#ifndef _POSIX_VDISABLE
# define _POSIX_VDISABLE ((unsigned char) 0)
@ -775,7 +776,7 @@ struct globals {
unsigned current_col;
char buf[10];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.device_name = bb_msg_standard_input; \
G.max_col = 80; \

View File

@ -21,6 +21,7 @@
//usage: "\n -s Use System V sum algorithm (512byte blocks)"
#include "libbb.h"
#include "common_bufsiz.h"
enum { SUM_BSD, PRINT_NAME, SUM_SYSV };
@ -41,7 +42,7 @@ static unsigned sum_file(const char *file, unsigned type)
return 0;
while (1) {
size_t bytes_read = safe_read(fd, buf, BUFSIZ);
size_t bytes_read = safe_read(fd, buf, COMMON_BUFSIZE);
if ((ssize_t)bytes_read <= 0) {
r = (fd && close(fd) != 0);

View File

@ -49,12 +49,13 @@
//usage: "nameserver 10.0.0.1\n"
#include "libbb.h"
#include "common_bufsiz.h"
struct globals {
bool from_top;
bool exitcode;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
static void tail_xprint_header(const char *fmt, const char *filename)

View File

@ -23,6 +23,7 @@
//usage: "Hello\n"
#include "libbb.h"
#include "common_bufsiz.h"
int tee_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int tee_main(int argc, char **argv)
@ -36,7 +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 buf bb_common_bufsiz1
# define sizeof_buf COMMON_BUFSIZE
#else
int c;
#endif
@ -79,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, sizeof_buf)) > 0) {
fp = files;
do
fwrite(buf, 1, c, *fp);

View File

@ -89,13 +89,14 @@
//usage: "+ shutdown -h +4m"
#include "libbb.h"
#include "common_bufsiz.h"
struct globals {
char **names;
int cur;
char *cmd[2 /* using 1 provokes compiler warning */];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define names (G.names)
#define cur (G.cur )
#define cmd (G.cmd )

View File

@ -153,6 +153,7 @@ Misc options:
/* Override ENABLE_FEATURE_PIDFILE */
#define WANT_PIDFILE 1
#include "libbb.h"
#include "common_bufsiz.h"
struct pid_list {
struct pid_list *next;
@ -191,7 +192,7 @@ struct globals {
int user_id;
smallint signal_nr;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define userspec (G.userspec )
#define cmdname (G.cmdname )
#define execname (G.execname )

View File

@ -60,6 +60,7 @@
//usage: "\n -t TYPE List of filesystem types to check"
#include "libbb.h"
#include "common_bufsiz.h"
/* "progress indicator" code is somewhat buggy and ext[23] specific.
* We should be filesystem agnostic. IOW: there should be a well-defined
@ -169,7 +170,7 @@ struct globals {
struct fs_info *filesys_last;
struct fsck_instance *instance_list;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)

View File

@ -125,6 +125,7 @@
//usage: "\n -w Ignore all whitespace"
#include "libbb.h"
#include "common_bufsiz.h"
#if 0
# define dbg_error_msg(...) bb_error_msg(__VA_ARGS__)

View File

@ -23,6 +23,7 @@
//usage:#define ed_full_usage ""
#include "libbb.h"
#include "common_bufsiz.h"
typedef struct LINE {
struct LINE *next;
@ -32,11 +33,12 @@ typedef struct LINE {
} LINE;
#define searchString bb_common_bufsiz1
#define searchString bb_common_bufsiz1
#define sizeof_searchString COMMON_BUFSIZE
enum {
USERSIZE = sizeof(searchString) > 1024 ? 1024
: sizeof(searchString) - 1, /* max line length typed in by user */
USERSIZE = sizeof_searchString > 1024 ? 1024
: sizeof_searchString - 1, /* max line length typed in by user */
INITBUF_SIZE = 1024, /* initial buffer size */
};

View File

@ -86,6 +86,7 @@
//usage: "bar\n"
#include "libbb.h"
#include "common_bufsiz.h"
#include "xregex.h"
#if 0
@ -161,7 +162,7 @@ struct globals {
int len; /* Space allocated */
} pipeline;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
G.sed_cmd_tail = &G.sed_cmd_head; \

View File

@ -342,6 +342,7 @@
#include <fnmatch.h>
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_FEATURE_FIND_REGEX
# include "xregex.h"
#endif
@ -421,7 +422,7 @@ struct globals {
recurse_flags_t recurse_flags;
IF_FEATURE_FIND_EXEC_PLUS(unsigned max_argv_len;)
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
/* we have to zero it out because of NOEXEC */ \

View File

@ -58,6 +58,7 @@
//config: Print the specified number of context lines (-C).
#include "libbb.h"
#include "common_bufsiz.h"
#include "xregex.h"
@ -201,7 +202,7 @@ struct globals {
llist_t *pattern_head; /* growable list of patterns to match */
const char *cur_file; /* the current file we are reading */
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)

View File

@ -66,6 +66,7 @@
//kbuild:lib-$(CONFIG_XARGS) += xargs.o
#include "libbb.h"
#include "common_bufsiz.h"
/* This is a NOEXEC applet. Be very careful! */
@ -100,7 +101,7 @@ struct globals {
const char *eof_str;
int idx;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \
IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \

View File

@ -1827,10 +1827,6 @@ extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr
extern const int const_int_0;
//extern const int const_int_1;
/* Providing hard guarantee on minimum size (think of BUFSIZ == 128) */
enum { COMMON_BUFSIZE = (BUFSIZ >= 256*sizeof(void*) ? BUFSIZ+1 : 256*sizeof(void*)) };
extern char bb_common_bufsiz1[COMMON_BUFSIZE];
/* This struct is deliberately not defined. */
/* See docs/keep_data_small.txt */
struct globals;

View File

@ -47,6 +47,7 @@
//config: and /etc/bootchartd.conf files.
#include "libbb.h"
#include "common_bufsiz.h"
/* After libbb.h, since it needs sys/types.h on some systems */
#include <sys/utsname.h>
@ -115,7 +116,7 @@
struct globals {
char jiffy_line[COMMON_BUFSIZE];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
static void dump_file(FILE *fp, const char *filename)

74
libbb/common_bufsiz.c Normal file
View File

@ -0,0 +1,74 @@
/* vi: set sw=4 ts=4: */
/*
* Utility routines.
*
* Copyright (C) 2016 Denys Vlasenko
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config FEATURE_USE_BSS_TAIL
//config: bool "Use the end of BSS page"
//config: default n
//config: help
//config: Attempt to reclaim a small unused part of BSS.
//config:
//config: Executables have the following parts:
//config: = read-only executable code and constants, also known as "text"
//config: = read-write data
//config: = non-initialized (zeroed on demand) data, also known as "bss"
//config:
//config: At link time, "text" is padded to a full page. At runtime, all "text"
//config: pages are mapped RO and executable.
//config: "Data" starts on the next page boundary, but is not padded
//config: to a full page at the end. "Bss" starts wherever "data" ends.
//config: At runtime, "data" pages are mapped RW and they are file-backed
//config: (this includes a small portion of "bss" which may live in the last
//config: partial page of "data").
//config: Pages which are fully in "bss" are mapped to anonymous memory.
//config:
//config: "Bss" end is usually not page-aligned. There is an unused space
//config: in the last page. Linker marks its start with the "_end" symbol.
//config:
//config: This option will attempt to use that space for bb_common_bufsiz1[]
//config: array. If it fits after _end, it will be used, and COMMON_BUFSIZE
//config: will be enlarged from its guaranteed minimum size of 1 kbyte.
//config: This may require recompilation a second time, since value of _end
//config: is known only after final link.
//config:
//config: If you are getting a build error like this:
//config: appletlib.c:(.text.main+0xd): undefined reference to '_end'
//config: disable this option.
//kbuild:lib-y += common_bufsiz.o
#include "libbb.h"
#include "common_bufsiz.h"
#if !ENABLE_FEATURE_USE_BSS_TAIL
/* We use it for "global" data via *(struct global*)bb_common_bufsiz1.
* Since gcc insists on aligning struct global's members, it would be a pity
* (and an alignment fault on some CPUs) to mess it up. */
char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));
#else
# ifndef setup_common_bufsiz
/*
* It is not a "((void)0)" macro. It means we have to provide this function.
*/
char* bb_common_bufsiz1;
char* setup_common_bufsiz(void)
{
if (!bb_common_bufsiz1)
bb_common_bufsiz1 = xzalloc(COMMON_BUFSIZE);
return bb_common_bufsiz1;
}
# else
# ifndef bb_common_bufsiz1
/* bb_common_bufsiz1[] is not aliased to _end[] */
char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));
# endif
# endif
#endif

View File

@ -59,8 +59,3 @@ const char bb_path_wtmp_file[] ALIGN1 =
# error unknown path to wtmp file
# endif
#endif
/* We use it for "global" data via *(struct global*)&bb_common_bufsiz1.
* Since gcc insists on aligning struct global's members, it would be a pity
* (and an alignment fault on some CPUs) to mess it up. */
char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));

View File

@ -62,6 +62,7 @@
//usage: "\n -p Preserve environment"
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
#include <sys/resource.h>
@ -138,7 +139,7 @@ enum {
struct globals {
struct termios tty_attrs;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)

View File

@ -17,6 +17,7 @@
//usage: "chat '' ATZ OK ATD123456 CONNECT '' ogin: pppuser word: ppppass '~'"
#include "libbb.h"
#include "common_bufsiz.h"
// default timeout: 45 sec
#define DEFAULT_CHAT_TIMEOUT 45*1000

View File

@ -42,6 +42,7 @@
//usage: "\n -y LINE Starting line"
#include "libbb.h"
#include "common_bufsiz.h"
#include <sys/kd.h>
#define ESC "\033"
@ -363,7 +364,8 @@ 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 keybuf bb_common_bufsiz1
#define sizeof_keybuf COMMON_BUFSIZE
struct termios termbuf;
unsigned opts;
unsigned ttynum;
@ -513,7 +515,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, sizeof_keybuf - G.key_count);
if (bytes_read < 0)
goto abort;

View File

@ -60,6 +60,7 @@
//usage: "\n -c DIR Cron dir. Default:"CONFIG_FEATURE_CROND_DIR"/crontabs"
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
/* glibc frees previous setenv'ed value when we do next setenv()
@ -140,7 +141,7 @@ struct globals {
char *env_var_logname;
#endif
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.log_level = 8; \
G.crontab_dir_name = CRONTABS; \

View File

@ -4,6 +4,7 @@
*/
#include "libbb.h"
#include "common_bufsiz.h"
#include <math.h>
//usage:#define dc_trivial_usage
@ -47,7 +48,7 @@ struct globals {
double stack[1];
} FIX_ALIASING;
enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof(double) };
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define pointer (G.pointer )
#define base (G.base )
#define stack (G.stack )

View File

@ -34,6 +34,7 @@
//usage: "\n commands: 'NN' (% for progress bar) or 'exit'"
#include "libbb.h"
#include "common_bufsiz.h"
#include <linux/fb.h>
/* If you want logging messages on /tmp/fbsplash.log... */
@ -372,11 +373,12 @@ 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 concat_buf bb_common_bufsiz1
#define sizeof_concat_buf COMMON_BUFSIZE
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 + sizeof_concat_buf - read_ptr;
if (rem < 2
|| fgets(read_ptr, rem, theme_file) == NULL
) {

View File

@ -63,6 +63,7 @@
//usage: "\n -z Reread partition table"
#include "libbb.h"
#include "common_bufsiz.h"
/* must be _after_ libbb.h: */
#include <linux/hdreg.h>
#include <sys/mount.h>
@ -367,7 +368,7 @@ struct globals {
unsigned char flushcache[4] = { WIN_FLUSHCACHE, 0, 0, 0 };
#endif
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define get_identity (G.get_identity )
#define get_geom (G.get_geom )
#define do_flush (G.do_flush )

View File

@ -60,6 +60,7 @@
*/
#include "libbb.h"
#include "common_bufsiz.h"
#include <linux/i2c.h>
#include <linux/i2c-dev.h>

View File

@ -56,6 +56,7 @@
//usage: "\nWhen x event happens for all FILEs, inotifyd exits."
#include "libbb.h"
#include "common_bufsiz.h"
#include <sys/inotify.h>
static const char mask_names[] ALIGN1 =
@ -162,8 +163,9 @@ int inotifyd_main(int argc, char **argv)
// read out all pending events
// (NB: len must be int, not ssize_t or long!)
xioctl(pfd.fd, FIONREAD, &len);
#define eventbuf bb_common_bufsiz1
ie = buf = (len <= sizeof(eventbuf)) ? eventbuf : xmalloc(len);
#define eventbuf bb_common_bufsiz1
#define sizeof_eventbuf COMMON_BUFSIZE
ie = buf = (len <= sizeof_eventbuf) ? eventbuf : xmalloc(len);
len = full_read(pfd.fd, buf, len);
// process events. N.B. events may vary in length
while (len > 0) {

View File

@ -127,6 +127,7 @@
#include <sched.h> /* sched_yield() */
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_FEATURE_LESS_REGEXP
#include "xregex.h"
#endif
@ -439,7 +440,8 @@ static int at_end(void)
*/
static void read_lines(void)
{
#define readbuf bb_common_bufsiz1
#define readbuf bb_common_bufsiz1
#define sizeof_readbuf COMMON_BUFSIZE
char *current_line, *p;
int w = width;
char last_terminated = terminated;
@ -480,7 +482,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, sizeof_readbuf);
if (errno != EAGAIN)
break;
t = time(NULL);

View File

@ -19,6 +19,7 @@
//usage: "\n -X Disable special meaning of NUL and Ctrl-X from stdin"
#include "libbb.h"
#include "common_bufsiz.h"
// set raw tty mode
static void xget1(int fd, struct termios *t, struct termios *oldt)
@ -155,10 +156,11 @@ int microcom_main(int argc UNUSED_PARAM, char **argv)
skip_write: ;
}
if (pfd[0].revents) {
#define iobuf bb_common_bufsiz1
#define iobuf bb_common_bufsiz1
#define sizeof_iobuf COMMON_BUFSIZE
ssize_t len;
// read from device -> write to stdout
len = safe_read(sfd, iobuf, sizeof(iobuf));
len = safe_read(sfd, iobuf, sizeof_iobuf);
if (len > 0)
full_write(STDOUT_FILENO, iobuf, len);
else {

View File

@ -32,6 +32,7 @@
//usage: "\n -H HWTYPE Hardware address type"
#include "libbb.h"
#include "common_bufsiz.h"
#include "inet_common.h"
#include <arpa/inet.h>
@ -69,7 +70,7 @@ struct globals {
const char *device; /* current device */
smallint hw_set; /* flag if hw-type was set (-H) */
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define ap (G.ap )
#define hw (G.hw )
#define device (G.device )

View File

@ -28,6 +28,7 @@
#include <netpacket/packet.h>
#include "libbb.h"
#include "common_bufsiz.h"
/* We don't expect to see 1000+ seconds delay, unsigned is enough */
#define MONOTONIC_US() ((unsigned)monotonic_us())
@ -60,7 +61,7 @@ struct globals {
unsigned brd_recv;
unsigned req_recv;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define src (G.src )
#define dst (G.dst )
#define me (G.me )

View File

@ -29,6 +29,7 @@
//usage: "\n DIR Change root to this directory"
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
#include <netinet/tcp.h>
@ -123,7 +124,7 @@ struct globals {
char msg_ok [(sizeof("NNN " MSG_OK ) + 3) & 0xfffc];
char msg_err[(sizeof("NNN " MSG_ERR) + 3) & 0xfffc];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
/* Moved to main */ \
/*strcpy(G.msg_ok + 4, MSG_OK );*/ \

View File

@ -50,6 +50,7 @@
//usage: )
#include "libbb.h"
#include "common_bufsiz.h"
struct globals {
const char *user;
@ -60,7 +61,7 @@ struct globals {
int do_continue;
char buf[4]; /* actually [BUFSZ] */
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) };
#define user (G.user )
#define password (G.password )

View File

@ -125,6 +125,7 @@
//usage: "\n -d STRING URL decode STRING"
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_PAM
/* PAM may include <locale.h>. We may need to undefine bbox's stub define: */
# undef setlocale
@ -307,7 +308,8 @@ struct globals {
Htaccess *script_i; /* config script interpreters */
#endif
char *iobuf; /* [IOBUF_SIZE] */
#define hdr_buf bb_common_bufsiz1
#define hdr_buf bb_common_bufsiz1
#define sizeof_hdr_buf COMMON_BUFSIZE
char *hdr_ptr;
int hdr_cnt;
#if ENABLE_FEATURE_HTTPD_ERROR_PAGES
@ -1066,7 +1068,7 @@ static int get_line(void)
alarm(HEADER_READ_TIMEOUT);
while (1) {
if (hdr_cnt <= 0) {
hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof(hdr_buf));
hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf);
if (hdr_cnt <= 0)
break;
hdr_ptr = hdr_buf;
@ -1191,9 +1193,9 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post
/* We expect data, prev data portion is eaten by CGI
* and there *is* data to read from the peer
* (POSTDATA) */
//count = post_len > (int)sizeof(hdr_buf) ? (int)sizeof(hdr_buf) : post_len;
//count = post_len > (int)sizeof_hdr_buf ? (int)sizeof_hdr_buf : post_len;
//count = safe_read(STDIN_FILENO, hdr_buf, count);
count = safe_read(STDIN_FILENO, hdr_buf, sizeof(hdr_buf));
count = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf);
if (count > 0) {
hdr_cnt = count;
hdr_ptr = hdr_buf;

View File

@ -44,6 +44,7 @@
//usage: "\n -f Force de/configuration"
#include "libbb.h"
#include "common_bufsiz.h"
/* After libbb.h, since it needs sys/types.h on some systems */
#include <sys/utsname.h>
#include <fnmatch.h>
@ -129,7 +130,7 @@ struct globals {
const char *startup_PATH;
char *shell;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)

View File

@ -170,6 +170,7 @@
#include <sys/un.h>
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_FEATURE_INETD_RPC
# if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_RPC__)
@ -327,7 +328,7 @@ struct globals {
/* Used in next_line(), and as scratch read buffer */
char line[256]; /* _at least_ 256, see LINE_SIZE */
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
enum { LINE_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line) };
#define rlim_ofile_cur (G.rlim_ofile_cur )
#define rlim_ofile (G.rlim_ofile )

View File

@ -18,6 +18,7 @@
//usage: "\n STRING Ident answer string (default: nobody)"
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
#include "isrv.h"
@ -28,7 +29,8 @@ typedef struct identd_buf_t {
char buf[64 - sizeof(int)];
} identd_buf_t;
#define bogouser bb_common_bufsiz1
#define bogouser bb_common_bufsiz1
#define sizeof_bogouser COMMON_BUFSIZE
static int new_peer(isrv_state_t *state, int fd)
{
@ -118,7 +120,7 @@ int fakeidentd_main(int argc UNUSED_PARAM, char **argv)
opt = getopt32(argv, "fiwb:", &bind_address);
strcpy(bogouser, "nobody");
if (argv[optind])
strncpy(bogouser, argv[optind], sizeof(bogouser) - 1);
strncpy(bogouser, argv[optind], sizeof_bogouser - 1);
/* Daemonize if no -f and no -i and no -w */
if (!(opt & OPT_fiw))

View File

@ -13,6 +13,7 @@
#include <net/if_arp.h>
#include "ip_common.h" /* #include "libbb.h" is inside */
#include "common_bufsiz.h"
#include "rt_names.h"
#include "utils.h"
@ -39,7 +40,7 @@ struct filter_t {
} FIX_ALIASING;
typedef struct filter_t filter_t;
#define G_filter (*(filter_t*)&bb_common_bufsiz1)
#define G_filter (*(filter_t*)bb_common_bufsiz1)
static void print_link_flags(unsigned flags, unsigned mdown)

View File

@ -8,6 +8,7 @@
*/
#include "ip_common.h" /* #include "libbb.h" is inside */
#include "common_bufsiz.h"
#include "rt_names.h"
#include "utils.h"
#include <linux/neighbour.h>
@ -40,7 +41,7 @@ struct filter_t {
} FIX_ALIASING;
typedef struct filter_t filter_t;
#define G_filter (*(filter_t*)&bb_common_bufsiz1)
#define G_filter (*(filter_t*)bb_common_bufsiz1)
static int flush_update(void)
{

View File

@ -11,6 +11,7 @@
*/
#include "ip_common.h" /* #include "libbb.h" is inside */
#include "common_bufsiz.h"
#include "rt_names.h"
#include "utils.h"
@ -43,7 +44,7 @@ struct filter_t {
} FIX_ALIASING;
typedef struct filter_t filter_t;
#define G_filter (*(filter_t*)&bb_common_bufsiz1)
#define G_filter (*(filter_t*)bb_common_bufsiz1)
static int flush_update(void)
{

View File

@ -8,6 +8,7 @@
*/
#include "libbb.h"
#include "common_bufsiz.h"
//config:config NC
//config: bool "nc"
@ -252,7 +253,7 @@ int nc_main(int argc, char **argv)
fd = STDIN_FILENO;
while (1) {
if (FD_ISSET(fd, &testfds)) {
nread = safe_read(fd, iobuf, sizeof(iobuf));
nread = safe_read(fd, iobuf, COMMON_BUFSIZE);
if (fd == cfd) {
if (nread < 1)
exit(EXIT_SUCCESS);

View File

@ -28,6 +28,7 @@
#include <net/if.h>
#include <netinet/ip_icmp.h>
#include "libbb.h"
#include "common_bufsiz.h"
#ifdef __BIONIC__
/* should be in netinet/ip_icmp.h */
@ -186,7 +187,7 @@ struct globals {
char *hostname;
char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)
static void noresp(int ign UNUSED_PARAM)
@ -378,7 +379,7 @@ struct globals {
} pingaddr;
unsigned char rcvd_tbl[MAX_DUP_CHK / 8];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define if_index (G.if_index )
#define source_lsa (G.source_lsa )
#define str_I (G.str_I )

View File

@ -27,6 +27,7 @@
//usage: "\n -F Disable RTS/CTS flow control"
#include "libbb.h"
#include "common_bufsiz.h"
#include "libiproute/utils.h" /* invarg_1_to_2() */
struct globals {
@ -34,7 +35,7 @@ struct globals {
int saved_disc;
struct termios saved_state;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define handle (G.handle )
#define saved_disc (G.saved_disc )
#define saved_state (G.saved_state )

View File

@ -29,6 +29,7 @@
//usage: "filter show [ dev STRING ] [ root | parent CLASSID ]"
#include "libbb.h"
#include "common_bufsiz.h"
#include "libiproute/utils.h"
#include "libiproute/ip_common.h"
@ -63,7 +64,7 @@ struct globals {
uint32_t filter_prio;
uint32_t filter_proto;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define filter_ifindex (G.filter_ifindex)
#define filter_qdisc (G.filter_qdisc)
#define filter_parent (G.filter_parent)

View File

@ -67,6 +67,7 @@
//usage: "\n -v Verbose"
#include "libbb.h"
#include "common_bufsiz.h"
/* Wants <limits.h> etc, thus included after libbb.h: */
#ifdef __linux__
@ -91,7 +92,7 @@ struct globals {
char **env_cur;
char *env_var[1]; /* actually bigger */
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define verbose (G.verbose )
#define max_per_host (G.max_per_host)
#define cur_per_host (G.cur_per_host)

View File

@ -39,6 +39,7 @@
#include <arpa/telnet.h>
#include <netinet/in.h>
#include "libbb.h"
#include "common_bufsiz.h"
#ifdef __BIONIC__
/* should be in arpa/telnet.h */
@ -108,7 +109,7 @@ struct globals {
struct termios termios_def;
struct termios termios_raw;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)

View File

@ -44,6 +44,7 @@
#define DEBUG 0
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
#if DEBUG
@ -82,7 +83,7 @@ struct globals {
const char *issuefile;
int maxfd;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.loginpath = "/bin/login"; \
G.issuefile = "/etc/issue.net"; \

View File

@ -51,6 +51,7 @@
//usage: "\n -l Log to syslog (inetd mode requires this)"
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
#if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT
@ -128,7 +129,7 @@ struct globals {
bb_progress_t pmt;
#endif
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)
@ -757,7 +758,8 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv)
{
len_and_sockaddr *our_lsa;
len_and_sockaddr *peer_lsa;
char *local_file, *mode, *user_opt;
char *mode, *user_opt;
char *local_file = local_file;
const char *error_msg;
int opt, result, opcode;
IF_FEATURE_TFTP_BLOCKSIZE(int blksize = TFTP_BLKSIZE_DEFAULT;)

View File

@ -9,6 +9,7 @@
#define UDHCP_COMMON_H 1
#include "libbb.h"
#include "common_bufsiz.h"
#include <netinet/udp.h>
#include <netinet/ip.h>

View File

@ -57,7 +57,7 @@ struct server_config_t {
struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */
} FIX_ALIASING;
#define server_config (*(struct server_config_t*)&bb_common_bufsiz1)
#define server_config (*(struct server_config_t*)bb_common_bufsiz1)
/* client_config sits in 2nd half of bb_common_bufsiz1 */
#if ENABLE_FEATURE_UDHCP_PORT

View File

@ -33,7 +33,7 @@ struct xid_item {
struct xid_item *next;
} FIX_ALIASING;
#define dhcprelay_xid_list (*(struct xid_item*)&bb_common_bufsiz1)
#define dhcprelay_xid_list (*(struct xid_item*)bb_common_bufsiz1)
static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client)
{

View File

@ -57,33 +57,35 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg)
struct config_keyword {
const char *keyword;
int (*handler)(const char *line, void *var) FAST_FUNC;
void *var;
unsigned ofs;
const char *def;
};
#define OFS(field) offsetof(struct server_config_t, field)
static const struct config_keyword keywords[] = {
/* keyword handler variable address default */
{"start" , udhcp_str2nip , &server_config.start_ip , "192.168.0.20"},
{"end" , udhcp_str2nip , &server_config.end_ip , "192.168.0.254"},
{"interface" , read_str , &server_config.interface , "eth0"},
{"start" , udhcp_str2nip , OFS(start_ip ), "192.168.0.20"},
{"end" , udhcp_str2nip , OFS(end_ip ), "192.168.0.254"},
{"interface" , read_str , OFS(interface ), "eth0"},
/* Avoid "max_leases value not sane" warning by setting default
* to default_end_ip - default_start_ip + 1: */
{"max_leases" , read_u32 , &server_config.max_leases , "235"},
{"auto_time" , read_u32 , &server_config.auto_time , "7200"},
{"decline_time" , read_u32 , &server_config.decline_time , "3600"},
{"conflict_time", read_u32 , &server_config.conflict_time, "3600"},
{"offer_time" , read_u32 , &server_config.offer_time , "60"},
{"min_lease" , read_u32 , &server_config.min_lease_sec, "60"},
{"lease_file" , read_str , &server_config.lease_file , LEASES_FILE},
{"pidfile" , read_str , &server_config.pidfile , "/var/run/udhcpd.pid"},
{"siaddr" , udhcp_str2nip , &server_config.siaddr_nip , "0.0.0.0"},
{"max_leases" , read_u32 , OFS(max_leases ), "235"},
{"auto_time" , read_u32 , OFS(auto_time ), "7200"},
{"decline_time" , read_u32 , OFS(decline_time ), "3600"},
{"conflict_time", read_u32 , OFS(conflict_time), "3600"},
{"offer_time" , read_u32 , OFS(offer_time ), "60"},
{"min_lease" , read_u32 , OFS(min_lease_sec), "60"},
{"lease_file" , read_str , OFS(lease_file ), LEASES_FILE},
{"pidfile" , read_str , OFS(pidfile ), "/var/run/udhcpd.pid"},
{"siaddr" , udhcp_str2nip , OFS(siaddr_nip ), "0.0.0.0"},
/* keywords with no defaults must be last! */
{"option" , udhcp_str2optset, &server_config.options , ""},
{"opt" , udhcp_str2optset, &server_config.options , ""},
{"notify_file" , read_str , &server_config.notify_file , NULL},
{"sname" , read_str , &server_config.sname , NULL},
{"boot_file" , read_str , &server_config.boot_file , NULL},
{"static_lease" , read_staticlease, &server_config.static_leases, ""},
{"option" , udhcp_str2optset, OFS(options ), ""},
{"opt" , udhcp_str2optset, OFS(options ), ""},
{"notify_file" , read_str , OFS(notify_file ), NULL},
{"sname" , read_str , OFS(sname ), NULL},
{"boot_file" , read_str , OFS(boot_file ), NULL},
{"static_lease" , read_staticlease, OFS(static_leases), ""},
};
enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 };
@ -95,17 +97,17 @@ void FAST_FUNC read_config(const char *file)
char *token[2];
for (i = 0; i < KWS_WITH_DEFAULTS; i++)
keywords[i].handler(keywords[i].def, keywords[i].var);
keywords[i].handler(keywords[i].def, (char*)&server_config + keywords[i].ofs);
parser = config_open(file);
while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
if (strcasecmp(token[0], k->keyword) == 0) {
if (!k->handler(token[1], k->var)) {
if (!k->handler(token[1], (char*)&server_config + k->ofs)) {
bb_error_msg("can't parse line %u in %s",
parser->lineno, file);
/* reset back to the default value */
k->handler(k->def, k->var);
k->handler(k->def, (char*)&server_config + k->ofs);
}
break;
}

View File

@ -40,6 +40,7 @@
//usage: "\nexits only on I/O errors (link down etc)"
#include "libbb.h"
#include "common_bufsiz.h"
#include <netinet/ether.h>
#include <net/if.h>
#include <net/if_arp.h>
@ -90,7 +91,7 @@ struct globals {
struct ether_addr our_ethaddr;
uint32_t localnet_ip;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)

View File

@ -22,6 +22,7 @@
//usage: "Total: 386144 257128 129016\n"
#include "libbb.h"
#include "common_bufsiz.h"
#ifdef __linux__
# include <sys/sysinfo.h>
#endif
@ -35,7 +36,7 @@ struct globals {
# define G_unit_steps 10
#endif
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { } while (0)

View File

@ -18,6 +18,7 @@
//usage: "\n -SIGNAL Signal to send (default: KILL)"
#include "libbb.h"
#include "common_bufsiz.h"
#define MAX_LINE 255
@ -43,7 +44,7 @@ struct globals {
smallint kill_failed;
int killsig;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
G.mypid = getpid(); \
G.killsig = SIGKILL; \

View File

@ -53,6 +53,7 @@
// totalswap=134209536, freeswap=134209536, procs=157})
#include "libbb.h"
#include "common_bufsiz.h"
typedef unsigned long long ullong;
@ -115,8 +116,8 @@ struct globals {
G.deltanz = G.delta = 1000000; \
} while (0)
// We depend on this being a char[], not char* - we take sizeof() of it
#define outbuf bb_common_bufsiz1
#define outbuf bb_common_bufsiz1
#define sizeof_outbuf COMMON_BUFSIZE
static inline void reset_outbuf(void)
{
@ -140,7 +141,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 + sizeof_outbuf - p;
while (*s && --sz >= 0)
*p++ = *s++;
cur_outbuf = p;
@ -148,7 +149,7 @@ static void put(const char *s)
static void put_c(char c)
{
if (cur_outbuf < outbuf + sizeof(outbuf))
if (cur_outbuf < outbuf + sizeof_outbuf)
*cur_outbuf++ = c;
}

View File

@ -62,6 +62,7 @@
//usage: " 2990 andersen andersen R ps\n"
#include "libbb.h"
#include "common_bufsiz.h"
#ifdef __linux__
# include <sys/sysinfo.h>
#endif
@ -144,7 +145,7 @@ struct globals {
unsigned long seconds_since_boot;
#endif
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define out (G.out )
#define out_cnt (G.out_cnt )
#define print_header (G.print_header )

View File

@ -105,6 +105,7 @@
//config: Enable 's' in top (gives lots of memory info).
#include "libbb.h"
#include "common_bufsiz.h"
typedef struct top_status_t {
@ -183,7 +184,7 @@ struct globals {
char line_buf[80];
}; //FIX_ALIASING; - large code growth
enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) };
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define top (G.top )
#define ntop (G.ntop )
#define sort_field (G.sort_field )

View File

@ -45,6 +45,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sys/file.h>
#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 )

View File

@ -57,6 +57,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sys/file.h>
#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 )

View File

@ -189,6 +189,7 @@ Exit Codes
#include <sys/file.h>
#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 )

View File

@ -155,6 +155,7 @@ log message, you can use a pattern like this instead
#include <sys/file.h>
#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;
}

114
scripts/generate_BUFSIZ.sh Executable file
View File

@ -0,0 +1,114 @@
#!/bin/sh
# Called from top-level directory a-la
#
# scripts/generate_BUFSIZ.sh include/common_bufsiz.h
. ./.config || exit 1
debug=false
common_bufsiz_h=$1
test x"$NM" = x"" && NM="${CONFIG_CROSS_COMPILER_PREFIX}nm"
test x"$CC" = x"" && CC="${CONFIG_CROSS_COMPILER_PREFIX}gcc"
regenerate() {
cat >"$1.$$"
test -f "$1" && diff "$1.$$" "$1" >/dev/null && rm "$1.$$" && return
mv "$1.$$" "$1"
}
generate_std_and_exit() {
$debug && echo "Default: bb_common_bufsiz1[] in bss"
{
echo "enum { COMMON_BUFSIZE = 1024 };"
echo "extern char bb_common_bufsiz1[];"
echo "#define setup_common_bufsiz() ((void)0)"
} | regenerate "$common_bufsiz_h"
exit 0
}
# User does not want any funky stuff?
test x"$CONFIG_FEATURE_USE_BSS_TAIL" = x"y" || generate_std_and_exit
test -f busybox_unstripped || {
# We did not try anything yet
$debug && echo "Will try to fit bb_common_bufsiz1[] into _end[]"
{
echo "enum { COMMON_BUFSIZE = 1024 };"
echo "extern char _end[]; /* linker-provided label */"
echo "#define bb_common_bufsiz1 _end"
echo "#define setup_common_bufsiz() ((void)0)"
} | regenerate "$common_bufsiz_h"
echo 1024 >"$common_bufsiz_h.BUFSIZE"
exit 0
}
# Get _end address
END=`$NM busybox_unstripped | grep ' . _end$'| cut -d' ' -f1`
test x"$END" = x"" && generate_std_and_exit
$debug && echo "END:0x$END $((0x$END))"
END=$((0x$END))
# Get PAGE_SIZE
echo "\
#include <sys/user.h>
#if defined(PAGE_SIZE) && PAGE_SIZE > 0
char page_size[PAGE_SIZE];
#else
char page_size[1];
#endif
" >page_size_$$.c
$CC -c "page_size_$$.c" || generate_std_and_exit
PAGE_SIZE=`$NM --size-sort "page_size_$$.o" | cut -d' ' -f1`
rm "page_size_$$.c" "page_size_$$.o"
test x"$PAGE_SIZE" = x"" && generate_std_and_exit
$debug && echo "PAGE_SIZE:0x$PAGE_SIZE $((0x$PAGE_SIZE))"
PAGE_SIZE=$((0x$PAGE_SIZE))
test $PAGE_SIZE -lt 1024 && generate_std_and_exit
# How much space between _end[] and next page?
PAGE_MASK=$((PAGE_SIZE-1))
REM=$(( (-END) & PAGE_MASK ))
$debug && echo "REM:$REM"
if test $REM -lt 1024; then
# _end[] has no enough space for bb_common_bufsiz1[],
# users will need to malloc it.
{
echo "enum { COMMON_BUFSIZE = 1024 };"
echo "extern char *bb_common_bufsiz1;"
echo "void setup_common_bufsiz(void);"
} | regenerate "$common_bufsiz_h"
# Check that we aren't left with a buggy binary:
if test -f "$common_bufsiz_h.BUFSIZE"; then
rm "$common_bufsiz_h.BUFSIZE"
echo "Warning! Space in _end[] is too small ($REM bytes)!"
echo "Rerun make to build a binary which doesn't use it!"
exit 1
fi
exit 0
fi
# _end[] has REM bytes for bb_common_bufsiz1[]
OLD=1024
test -f "$common_bufsiz_h.BUFSIZE" && OLD=`cat "$common_bufsiz_h.BUFSIZE"`
$debug && echo "OLD:$OLD"
{
echo "enum { COMMON_BUFSIZE = $REM };"
echo "extern char _end[]; /* linker-provided label */"
echo "#define bb_common_bufsiz1 _end"
echo "#define setup_common_bufsiz() ((void)0)"
} | regenerate "$common_bufsiz_h"
echo $REM >"$common_bufsiz_h.BUFSIZE"
# Check that code did not grow too much and thus _end[] did not shink:
if test $OLD -gt $REM; then
echo "Warning! Space in _end[] has decreased from $OLD to $REM bytes!"
echo "Rerun make!"
exit 1
fi
if test $OLD != $REM; then
echo "Space in _end[] is $REM bytes. Rerun make to use larger COMMON_BUFSIZE."
fi

View File

@ -77,7 +77,7 @@ struct globals {
int nerr;
struct edir excludeArray[MAX_EXCLUDES];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
void BUG_setfiles_globals_too_big(void);
#define INIT_G() do { \
if (sizeof(G) > COMMON_BUFSIZE) \

View File

@ -58,6 +58,7 @@
//usage: "\n -n Run in foreground"
#include "libbb.h"
#include "common_bufsiz.h"
#include <syslog.h>
@ -145,9 +146,10 @@ static void klogd_close(void)
#endif
#define log_buffer bb_common_bufsiz1
#define log_buffer bb_common_bufsiz1
#define sizeof_log_buffer COMMON_BUFSIZE
enum {
KLOGD_LOGBUF_SIZE = sizeof(log_buffer),
KLOGD_LOGBUF_SIZE = sizeof_log_buffer,
OPT_LEVEL = (1 << 0),
OPT_FOREGROUND = (1 << 1),
};

View File

@ -42,6 +42,7 @@
//usage: "\n -F Same as -f, but dump buffer first"
#include "libbb.h"
#include "common_bufsiz.h"
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
@ -67,7 +68,7 @@ struct globals {
struct sembuf SMrdn[2]; // {1, 0}, {0, +1, SEM_UNDO}
struct shbuf_ds *shbuf;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define SMrup (G.SMrup)
#define SMrdn (G.SMrdn)
#define shbuf (G.shbuf)

View File

@ -8,6 +8,7 @@
*/
#include "libbb.h"
#include "common_bufsiz.h"
#define SYSLOG_NAMES
#define SYSLOG_NAMES_CONST
#include <syslog.h>

View File

@ -97,6 +97,7 @@
//usage: "If /dev/mdev.log file exists, debug log will be appended to it."
#include "libbb.h"
#include "common_bufsiz.h"
#include "xregex.h"
/* "mdev -s" scans /sys/class/xxx, looking for directories which have dev
@ -285,7 +286,7 @@ struct globals {
struct rule cur_rule;
char timestr[sizeof("HH:MM:SS.123456")];
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define INIT_G() do { \
IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.maj = -1;) \
IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.mode = 0660;) \

View File

@ -13,6 +13,7 @@
//usage: "\n -L LBL Label"
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_SELINUX
static void mkswap_selinux_setcontext(int fd, const char *path)

View File

@ -23,6 +23,7 @@
//usage: "$ dmesg | more\n"
#include "libbb.h"
#include "common_bufsiz.h"
/* Support for FEATURE_USE_TERMIOS */

View File

@ -223,6 +223,7 @@
#define BB_MS_INVERTED_VALUE (1u << 31)
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_FEATURE_MOUNT_LABEL
# include "volume_id.h"
#else
@ -447,7 +448,7 @@ struct globals {
char getmntent_buf[1];
} FIX_ALIASING;
enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_buf) };
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define nfs_mount_version (G.nfs_mount_version)
#if ENABLE_FEATURE_MOUNT_VERBOSE
#define verbose (G.verbose )

View File

@ -23,6 +23,7 @@
//usage: )
#include "libbb.h"
#include "common_bufsiz.h"
int script_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int script_main(int argc UNUSED_PARAM, char **argv)
@ -108,7 +109,8 @@ int script_main(int argc UNUSED_PARAM, char **argv)
if (child_pid) {
/* parent */
#define buf bb_common_bufsiz1
#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;
@ -134,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, sizeof_buf);
if (count <= 0 && errno != EAGAIN) {
/* err/eof from pty: exit */
goto restore;
@ -157,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, sizeof_buf);
if (count <= 0) {
/* err/eof from stdin: don't read stdin anymore */
pfd[1].revents = 0;
@ -176,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, sizeof_buf)) > 0) {
full_write(STDOUT_FILENO, buf, count);
full_write(outfd, buf, count);
}

View File

@ -28,6 +28,7 @@
//usage: "\n -a Stop swapping on all swap devices"
#include "libbb.h"
#include "common_bufsiz.h"
#include <mntent.h>
#ifndef __BIONIC__
# include <sys/swap.h>
@ -62,7 +63,7 @@
struct globals {
int flags;
} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define G (*(struct globals*)bb_common_bufsiz1)
#define g_flags (G.flags)
#define save_g_flags() int save_g_flags = g_flags
#define restore_g_flags() g_flags = save_g_flags

View File

@ -25,11 +25,12 @@
//usage: "\n"" # uevent mdev & mdev -s"
#include "libbb.h"
#include "common_bufsiz.h"
#include <linux/netlink.h>
#define BUFFER_SIZE 16*1024
#define env ((char **)&bb_common_bufsiz1)
#define env ((char **)bb_common_bufsiz1)
enum {
MAX_ENV = COMMON_BUFSIZE / sizeof(env[0]) - 1,
};

View File

@ -34,6 +34,7 @@
# define MNT_DETACH 0x00000002
#endif
#include "libbb.h"
#include "common_bufsiz.h"
#if defined(__dietlibc__)
// TODO: This does not belong here.
@ -102,7 +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 {
while (getmntent_r(fp, &me, bb_common_bufsiz1, sizeof(bb_common_bufsiz1))) {
while (getmntent_r(fp, &me, bb_common_bufsiz1, COMMON_BUFSIZE)) {
/* Match fstype if passed */
if (!match_fstype(&me, fstype))
continue;