*: hopefully all setup_common_bufsiz() are in place

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2016-04-21 18:38:51 +02:00
parent 47cfbf32fd
commit 9de2e5a222
29 changed files with 83 additions and 55 deletions

View File

@ -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();

View File

@ -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.

View File

@ -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;

View File

@ -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);
@ -44,8 +45,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
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) {
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);
}

View File

@ -369,7 +369,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
#endif
#define date_buf bb_common_bufsiz1
#define sizeof_date_buf COMMON_BUFSIZE
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);

View File

@ -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);

View File

@ -159,9 +159,8 @@ static const char *human_time(time_t t)
/*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");
setup_common_bufsiz();
strcpy(strftime_YYYYMMDDHHMMSS(buf, COMMON_BUFSIZE, &t), ".000000000");
return buf;
#undef buf
}

View File

@ -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;

View File

@ -38,7 +38,7 @@ int tee_main(int argc, char **argv)
#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
ssize_t c;
# define buf bb_common_bufsiz1
# define sizeof_buf COMMON_BUFSIZE
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);

View File

@ -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;

View File

@ -34,11 +34,10 @@ typedef struct LINE {
#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 = 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)

View File

@ -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) {

View File

@ -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;

View File

@ -374,11 +374,12 @@ static void fb_drawimage(void)
* 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
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
) {

View File

@ -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!)
xioctl(pfd.fd, FIONREAD, &len);
#define eventbuf bb_common_bufsiz1
#define sizeof_eventbuf COMMON_BUFSIZE
ie = buf = (len <= sizeof_eventbuf) ? eventbuf : xmalloc(len);
setup_common_bufsiz();
xioctl(pfd.fd, FIONREAD, &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) {

View File

@ -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);

View File

@ -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 {

View File

@ -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;) \

View File

@ -30,7 +30,6 @@ typedef struct identd_buf_t {
} identd_buf_t;
#define bogouser bb_common_bufsiz1
#define sizeof_bogouser COMMON_BUFSIZE
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))

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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)) {

View File

@ -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;
}

View File

@ -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: "

View File

@ -147,9 +147,8 @@ static void klogd_close(void)
#endif
#define log_buffer bb_common_bufsiz1
#define sizeof_log_buffer COMMON_BUFSIZE
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 */

View File

@ -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());

View File

@ -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);
}

View File

@ -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))