diff options
author | Ron Yorston <rmy@pobox.com> | 2016-05-16 09:33:03 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2016-05-16 09:33:03 +0100 |
commit | 35d2f5bccb0f3dde600702ebcdb5424d4d50be4a (patch) | |
tree | 6e0ff0341c69839e268459a199682628bae734ed | |
parent | 248a2600a2f4b442101ad568d1994b908bb28d4b (diff) | |
parent | f2559e5c2b7bd2c5fa0dd8e88d0a931da92a23af (diff) | |
download | busybox-w32-35d2f5bccb0f3dde600702ebcdb5424d4d50be4a.tar.gz busybox-w32-35d2f5bccb0f3dde600702ebcdb5424d4d50be4a.tar.bz2 busybox-w32-35d2f5bccb0f3dde600702ebcdb5424d4d50be4a.zip |
Merge branch 'busybox' into merge
128 files changed, 858 insertions, 295 deletions
@@ -612,7 +612,8 @@ quiet_cmd_busybox__ ?= LINK $@ | |||
612 | "$(LDFLAGS) $(EXTRA_LDFLAGS)" \ | 612 | "$(LDFLAGS) $(EXTRA_LDFLAGS)" \ |
613 | "$(core-y)" \ | 613 | "$(core-y)" \ |
614 | "$(libs-y)" \ | 614 | "$(libs-y)" \ |
615 | "$(LDLIBS)" | 615 | "$(LDLIBS)" \ |
616 | && $(srctree)/scripts/generate_BUFSIZ.sh --post include/common_bufsiz.h | ||
616 | 617 | ||
617 | # Generate System.map | 618 | # Generate System.map |
618 | quiet_cmd_sysmap = SYSMAP | 619 | quiet_cmd_sysmap = SYSMAP |
@@ -846,12 +847,15 @@ export CPPFLAGS_busybox.lds += -P -C -U$(ARCH) | |||
846 | # Split autoconf.h into include/linux/config/* | 847 | # Split autoconf.h into include/linux/config/* |
847 | quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h | 848 | quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h |
848 | cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs include/bbconfigopts.h include/bbconfigopts_bz2.h | 849 | cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs include/bbconfigopts.h include/bbconfigopts_bz2.h |
850 | quiet_cmd_gen_common_bufsiz = GEN include/common_bufsiz.h | ||
851 | cmd_gen_common_bufsiz = $(srctree)/scripts/generate_BUFSIZ.sh include/common_bufsiz.h | ||
849 | quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/* | 852 | quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/* |
850 | cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config | 853 | cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config |
851 | #bbox# piggybacked generation of few .h files | 854 | #bbox# piggybacked generation of few .h files |
852 | include/config/MARKER: scripts/basic/split-include include/autoconf.h | 855 | include/config/MARKER: scripts/basic/split-include include/autoconf.h |
853 | $(call cmd,split_autoconf) | 856 | $(call cmd,split_autoconf) |
854 | $(call cmd,gen_bbconfigopts) | 857 | $(call cmd,gen_bbconfigopts) |
858 | $(call cmd,gen_common_bufsiz) | ||
855 | @touch $@ | 859 | @touch $@ |
856 | 860 | ||
857 | # Generate some files | 861 | # Generate some files |
@@ -967,6 +971,7 @@ CLEAN_FILES += busybox$(EXEEXT) busybox_unstripped* busybox.links \ | |||
967 | MRPROPER_DIRS += include/config include2 | 971 | MRPROPER_DIRS += include/config include2 |
968 | MRPROPER_FILES += .config .config.old include/asm .version .old_version \ | 972 | MRPROPER_FILES += .config .config.old include/asm .version .old_version \ |
969 | include/NUM_APPLETS.h \ | 973 | include/NUM_APPLETS.h \ |
974 | include/common_bufsiz.h \ | ||
970 | include/autoconf.h \ | 975 | include/autoconf.h \ |
971 | include/bbconfigopts.h \ | 976 | include/bbconfigopts.h \ |
972 | include/bbconfigopts_bz2.h \ | 977 | include/bbconfigopts_bz2.h \ |
diff --git a/archival/cpio.c b/archival/cpio.c index 30f66d1f7..d0cedd35c 100644 --- a/archival/cpio.c +++ b/archival/cpio.c | |||
@@ -11,6 +11,7 @@ | |||
11 | * Only supports new ASCII and CRC formats | 11 | * Only supports new ASCII and CRC formats |
12 | */ | 12 | */ |
13 | #include "libbb.h" | 13 | #include "libbb.h" |
14 | #include "common_bufsiz.h" | ||
14 | #include "bb_archive.h" | 15 | #include "bb_archive.h" |
15 | 16 | ||
16 | //config:config CPIO | 17 | //config:config CPIO |
@@ -170,9 +171,10 @@ enum { | |||
170 | struct globals { | 171 | struct globals { |
171 | struct bb_uidgid_t owner_ugid; | 172 | struct bb_uidgid_t owner_ugid; |
172 | } FIX_ALIASING; | 173 | } FIX_ALIASING; |
173 | #define G (*(struct globals*)&bb_common_bufsiz1) | 174 | #define G (*(struct globals*)bb_common_bufsiz1) |
174 | void BUG_cpio_globals_too_big(void); | 175 | void BUG_cpio_globals_too_big(void); |
175 | #define INIT_G() do { \ | 176 | #define INIT_G() do { \ |
177 | setup_common_bufsiz(); \ | ||
176 | G.owner_ugid.uid = -1L; \ | 178 | G.owner_ugid.uid = -1L; \ |
177 | G.owner_ugid.gid = -1L; \ | 179 | G.owner_ugid.gid = -1L; \ |
178 | } while (0) | 180 | } while (0) |
diff --git a/archival/libarchive/common.c b/archival/libarchive/common.c index dd69d2222..389cb7856 100644 --- a/archival/libarchive/common.c +++ b/archival/libarchive/common.c | |||
@@ -6,4 +6,4 @@ | |||
6 | #include "libbb.h" | 6 | #include "libbb.h" |
7 | #include "bb_archive.h" | 7 | #include "bb_archive.h" |
8 | 8 | ||
9 | const char cpio_TRAILER[] = "TRAILER!!!"; | 9 | const char cpio_TRAILER[] ALIGN1 = "TRAILER!!!"; |
diff --git a/archival/lzop.c b/archival/lzop.c index a5fc01941..202de4d03 100644 --- a/archival/lzop.c +++ b/archival/lzop.c | |||
@@ -71,6 +71,7 @@ | |||
71 | //usage: "\n -F Don't store or verify checksum" | 71 | //usage: "\n -F Don't store or verify checksum" |
72 | 72 | ||
73 | #include "libbb.h" | 73 | #include "libbb.h" |
74 | #include "common_bufsiz.h" | ||
74 | #include "bb_archive.h" | 75 | #include "bb_archive.h" |
75 | #include "liblzo_interface.h" | 76 | #include "liblzo_interface.h" |
76 | 77 | ||
@@ -443,8 +444,8 @@ struct globals { | |||
443 | chksum_t chksum_in; | 444 | chksum_t chksum_in; |
444 | chksum_t chksum_out; | 445 | chksum_t chksum_out; |
445 | } FIX_ALIASING; | 446 | } FIX_ALIASING; |
446 | #define G (*(struct globals*)&bb_common_bufsiz1) | 447 | #define G (*(struct globals*)bb_common_bufsiz1) |
447 | #define INIT_G() do { } while (0) | 448 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
448 | //#define G (*ptr_to_globals) | 449 | //#define G (*ptr_to_globals) |
449 | //#define INIT_G() do { | 450 | //#define INIT_G() do { |
450 | // SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); | 451 | // SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); |
@@ -895,7 +896,7 @@ static NOINLINE int lzo_decompress(const header_t *h) | |||
895 | * chksum_out | 896 | * chksum_out |
896 | * The rest is identical. | 897 | * The rest is identical. |
897 | */ | 898 | */ |
898 | static const unsigned char lzop_magic[9] = { | 899 | static const unsigned char lzop_magic[9] ALIGN1 = { |
899 | 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a | 900 | 0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a |
900 | }; | 901 | }; |
901 | 902 | ||
diff --git a/archival/rpm.c b/archival/rpm.c index 105394481..83160f975 100644 --- a/archival/rpm.c +++ b/archival/rpm.c | |||
@@ -29,6 +29,7 @@ | |||
29 | //usage: "\n -qpc List config files" | 29 | //usage: "\n -qpc List config files" |
30 | 30 | ||
31 | #include "libbb.h" | 31 | #include "libbb.h" |
32 | #include "common_bufsiz.h" | ||
32 | #include "bb_archive.h" | 33 | #include "bb_archive.h" |
33 | #include "rpm.h" | 34 | #include "rpm.h" |
34 | 35 | ||
@@ -93,8 +94,8 @@ struct globals { | |||
93 | rpm_index **mytags; | 94 | rpm_index **mytags; |
94 | int tagcount; | 95 | int tagcount; |
95 | } FIX_ALIASING; | 96 | } FIX_ALIASING; |
96 | #define G (*(struct globals*)&bb_common_bufsiz1) | 97 | #define G (*(struct globals*)bb_common_bufsiz1) |
97 | #define INIT_G() do { } while (0) | 98 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
98 | 99 | ||
99 | static void extract_cpio(int fd, const char *source_rpm) | 100 | static void extract_cpio(int fd, const char *source_rpm) |
100 | { | 101 | { |
diff --git a/archival/tar.c b/archival/tar.c index adb0b934f..c88957734 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -146,6 +146,7 @@ | |||
146 | 146 | ||
147 | #include <fnmatch.h> | 147 | #include <fnmatch.h> |
148 | #include "libbb.h" | 148 | #include "libbb.h" |
149 | #include "common_bufsiz.h" | ||
149 | #include "bb_archive.h" | 150 | #include "bb_archive.h" |
150 | /* FIXME: Stop using this non-standard feature */ | 151 | /* FIXME: Stop using this non-standard feature */ |
151 | #ifndef FNM_LEADING_DIR | 152 | #ifndef FNM_LEADING_DIR |
@@ -161,6 +162,7 @@ | |||
161 | 162 | ||
162 | 163 | ||
163 | #define block_buf bb_common_bufsiz1 | 164 | #define block_buf bb_common_bufsiz1 |
165 | #define INIT_G() do { setup_common_bufsiz(); } while (0) | ||
164 | 166 | ||
165 | 167 | ||
166 | #if ENABLE_FEATURE_TAR_CREATE | 168 | #if ENABLE_FEATURE_TAR_CREATE |
@@ -992,6 +994,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv) | |||
992 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM | 994 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM |
993 | llist_t *excludes = NULL; | 995 | llist_t *excludes = NULL; |
994 | #endif | 996 | #endif |
997 | INIT_G(); | ||
995 | 998 | ||
996 | /* Initialise default values */ | 999 | /* Initialise default values */ |
997 | tar_handle = init_handle(); | 1000 | tar_handle = init_handle(); |
diff --git a/archival/unzip.c b/archival/unzip.c index 203073434..27adb3420 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
@@ -48,6 +48,12 @@ | |||
48 | #pragma pack(2) | 48 | #pragma pack(2) |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | #if 0 | ||
52 | # define dbg(...) bb_error_msg(__VA_ARGS__) | ||
53 | #else | ||
54 | # define dbg(...) ((void)0) | ||
55 | #endif | ||
56 | |||
51 | enum { | 57 | enum { |
52 | #if BB_BIG_ENDIAN | 58 | #if BB_BIG_ENDIAN |
53 | ZIP_FILEHEADER_MAGIC = 0x504b0304, | 59 | ZIP_FILEHEADER_MAGIC = 0x504b0304, |
@@ -196,15 +202,17 @@ static uint32_t find_cdf_offset(void) | |||
196 | unsigned char *p; | 202 | unsigned char *p; |
197 | off_t end; | 203 | off_t end; |
198 | unsigned char *buf = xzalloc(PEEK_FROM_END); | 204 | unsigned char *buf = xzalloc(PEEK_FROM_END); |
205 | uint32_t found; | ||
199 | 206 | ||
200 | end = xlseek(zip_fd, 0, SEEK_END); | 207 | end = xlseek(zip_fd, 0, SEEK_END); |
201 | end -= PEEK_FROM_END; | 208 | end -= PEEK_FROM_END; |
202 | if (end < 0) | 209 | if (end < 0) |
203 | end = 0; | 210 | end = 0; |
204 | xlseek(zip_fd, end, SEEK_SET); | 211 | dbg("Looking for cdf_offset starting from 0x%"OFF_FMT"x", end); |
212 | xlseek(zip_fd, end, SEEK_SET); | ||
205 | full_read(zip_fd, buf, PEEK_FROM_END); | 213 | full_read(zip_fd, buf, PEEK_FROM_END); |
206 | 214 | ||
207 | cde_header.formatted.cdf_offset = BAD_CDF_OFFSET; | 215 | found = BAD_CDF_OFFSET; |
208 | p = buf; | 216 | p = buf; |
209 | while (p <= buf + PEEK_FROM_END - CDE_HEADER_LEN - 4) { | 217 | while (p <= buf + PEEK_FROM_END - CDE_HEADER_LEN - 4) { |
210 | if (*p != 'P') { | 218 | if (*p != 'P') { |
@@ -223,14 +231,25 @@ static uint32_t find_cdf_offset(void) | |||
223 | /* | 231 | /* |
224 | * I've seen .ZIP files with seemingly valid CDEs | 232 | * I've seen .ZIP files with seemingly valid CDEs |
225 | * where cdf_offset points past EOF - ?? | 233 | * where cdf_offset points past EOF - ?? |
226 | * Ignore such CDEs: | 234 | * This check ignores such CDEs: |
227 | */ | 235 | */ |
228 | if (cde_header.formatted.cdf_offset < end + (p - buf)) | 236 | if (cde_header.formatted.cdf_offset < end + (p - buf)) { |
229 | break; | 237 | found = cde_header.formatted.cdf_offset; |
230 | cde_header.formatted.cdf_offset = BAD_CDF_OFFSET; | 238 | dbg("Possible cdf_offset:0x%x at 0x%"OFF_FMT"x", |
239 | (unsigned)found, end + (p-3 - buf)); | ||
240 | dbg(" cdf_offset+cdf_size:0x%x", | ||
241 | (unsigned)(found + SWAP_LE32(cde_header.formatted.cdf_size))); | ||
242 | /* | ||
243 | * We do not "break" here because only the last CDE is valid. | ||
244 | * I've seen a .zip archive which contained a .zip file, | ||
245 | * uncompressed, and taking the first CDE was using | ||
246 | * the CDE inside that file! | ||
247 | */ | ||
248 | } | ||
231 | } | 249 | } |
232 | free(buf); | 250 | free(buf); |
233 | return cde_header.formatted.cdf_offset; | 251 | dbg("Found cdf_offset:0x%x", (unsigned)found); |
252 | return found; | ||
234 | }; | 253 | }; |
235 | 254 | ||
236 | static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr) | 255 | static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr) |
@@ -243,15 +262,22 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr) | |||
243 | cdf_offset = find_cdf_offset(); | 262 | cdf_offset = find_cdf_offset(); |
244 | 263 | ||
245 | if (cdf_offset != BAD_CDF_OFFSET) { | 264 | if (cdf_offset != BAD_CDF_OFFSET) { |
265 | dbg("Reading CDF at 0x%x", (unsigned)cdf_offset); | ||
246 | xlseek(zip_fd, cdf_offset + 4, SEEK_SET); | 266 | xlseek(zip_fd, cdf_offset + 4, SEEK_SET); |
247 | xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN); | 267 | xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN); |
248 | FIX_ENDIANNESS_CDF(*cdf_ptr); | 268 | FIX_ENDIANNESS_CDF(*cdf_ptr); |
269 | dbg(" file_name_length:%u extra_field_length:%u file_comment_length:%u", | ||
270 | (unsigned)cdf_ptr->formatted.file_name_length, | ||
271 | (unsigned)cdf_ptr->formatted.extra_field_length, | ||
272 | (unsigned)cdf_ptr->formatted.file_comment_length | ||
273 | ); | ||
249 | cdf_offset += 4 + CDF_HEADER_LEN | 274 | cdf_offset += 4 + CDF_HEADER_LEN |
250 | + cdf_ptr->formatted.file_name_length | 275 | + cdf_ptr->formatted.file_name_length |
251 | + cdf_ptr->formatted.extra_field_length | 276 | + cdf_ptr->formatted.extra_field_length |
252 | + cdf_ptr->formatted.file_comment_length; | 277 | + cdf_ptr->formatted.file_comment_length; |
253 | } | 278 | } |
254 | 279 | ||
280 | dbg("Returning file position to 0x%"OFF_FMT"x", org); | ||
255 | xlseek(zip_fd, org, SEEK_SET); | 281 | xlseek(zip_fd, org, SEEK_SET); |
256 | return cdf_offset; | 282 | return cdf_offset; |
257 | }; | 283 | }; |
@@ -464,7 +490,7 @@ int unzip_main(int argc, char **argv) | |||
464 | if (overwrite == O_PROMPT) | 490 | if (overwrite == O_PROMPT) |
465 | overwrite = O_NEVER; | 491 | overwrite = O_NEVER; |
466 | } else { | 492 | } else { |
467 | static const char extn[][5] = { ".zip", ".ZIP" }; | 493 | static const char extn[][5] ALIGN1 = { ".zip", ".ZIP" }; |
468 | char *ext = src_fn + strlen(src_fn); | 494 | char *ext = src_fn + strlen(src_fn); |
469 | int src_fd; | 495 | int src_fd; |
470 | 496 | ||
@@ -491,11 +517,11 @@ int unzip_main(int argc, char **argv) | |||
491 | printf("Archive: %s\n", src_fn); | 517 | printf("Archive: %s\n", src_fn); |
492 | if (listing) { | 518 | if (listing) { |
493 | puts(verbose ? | 519 | puts(verbose ? |
494 | " Length Method Size Ratio Date Time CRC-32 Name\n" | 520 | " Length Method Size Cmpr Date Time CRC-32 Name\n" |
495 | "-------- ------ ------- ----- ---- ---- ------ ----" | 521 | "-------- ------ ------- ---- ---------- ----- -------- ----" |
496 | : | 522 | : |
497 | " Length Date Time Name\n" | 523 | " Length Date Time Name\n" |
498 | " -------- ---- ---- ----" | 524 | "--------- ---------- ----- ----" |
499 | ); | 525 | ); |
500 | } | 526 | } |
501 | } | 527 | } |
@@ -535,11 +561,14 @@ int unzip_main(int argc, char **argv) | |||
535 | /* Check magic number */ | 561 | /* Check magic number */ |
536 | xread(zip_fd, &magic, 4); | 562 | xread(zip_fd, &magic, 4); |
537 | /* Central directory? It's at the end, so exit */ | 563 | /* Central directory? It's at the end, so exit */ |
538 | if (magic == ZIP_CDF_MAGIC) | 564 | if (magic == ZIP_CDF_MAGIC) { |
565 | dbg("got ZIP_CDF_MAGIC"); | ||
539 | break; | 566 | break; |
567 | } | ||
540 | #if ENABLE_DESKTOP | 568 | #if ENABLE_DESKTOP |
541 | /* Data descriptor? It was a streaming file, go on */ | 569 | /* Data descriptor? It was a streaming file, go on */ |
542 | if (magic == ZIP_DD_MAGIC) { | 570 | if (magic == ZIP_DD_MAGIC) { |
571 | dbg("got ZIP_DD_MAGIC"); | ||
543 | /* skip over duplicate crc32, cmpsize and ucmpsize */ | 572 | /* skip over duplicate crc32, cmpsize and ucmpsize */ |
544 | unzip_skip(3 * 4); | 573 | unzip_skip(3 * 4); |
545 | continue; | 574 | continue; |
@@ -547,6 +576,7 @@ int unzip_main(int argc, char **argv) | |||
547 | #endif | 576 | #endif |
548 | if (magic != ZIP_FILEHEADER_MAGIC) | 577 | if (magic != ZIP_FILEHEADER_MAGIC) |
549 | bb_error_msg_and_die("invalid zip magic %08X", (int)magic); | 578 | bb_error_msg_and_die("invalid zip magic %08X", (int)magic); |
579 | dbg("got ZIP_FILEHEADER_MAGIC"); | ||
550 | 580 | ||
551 | /* Read the file header */ | 581 | /* Read the file header */ |
552 | xread(zip_fd, zip_header.raw, ZIP_HEADER_LEN); | 582 | xread(zip_fd, zip_header.raw, ZIP_HEADER_LEN); |
@@ -590,6 +620,11 @@ int unzip_main(int argc, char **argv) | |||
590 | bb_error_msg_and_die("can't find file table"); | 620 | bb_error_msg_and_die("can't find file table"); |
591 | } | 621 | } |
592 | #endif | 622 | #endif |
623 | dbg("File cmpsize:0x%x extra_len:0x%x ucmpsize:0x%x", | ||
624 | (unsigned)zip_header.formatted.cmpsize, | ||
625 | (unsigned)zip_header.formatted.extra_len, | ||
626 | (unsigned)zip_header.formatted.ucmpsize | ||
627 | ); | ||
593 | 628 | ||
594 | /* Read filename */ | 629 | /* Read filename */ |
595 | free(dst_fn); | 630 | free(dst_fn); |
@@ -610,40 +645,55 @@ int unzip_main(int argc, char **argv) | |||
610 | } else { | 645 | } else { |
611 | if (listing) { | 646 | if (listing) { |
612 | /* List entry */ | 647 | /* List entry */ |
613 | unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); | 648 | char dtbuf[sizeof("mm-dd-yyyy hh:mm")]; |
649 | sprintf(dtbuf, "%02u-%02u-%04u %02u:%02u", | ||
650 | (zip_header.formatted.moddate >> 5) & 0xf, // mm: 0x01e0 | ||
651 | (zip_header.formatted.moddate) & 0x1f, // dd: 0x001f | ||
652 | (zip_header.formatted.moddate >> 9) + 1980, // yy: 0xfe00 | ||
653 | (zip_header.formatted.modtime >> 11), // hh: 0xf800 | ||
654 | (zip_header.formatted.modtime >> 5) & 0x3f // mm: 0x07e0 | ||
655 | // seconds/2 are not shown, encoded in ----------- 0x001f | ||
656 | ); | ||
614 | if (!verbose) { | 657 | if (!verbose) { |
615 | // " Length Date Time Name\n" | 658 | // " Length Date Time Name\n" |
616 | // " -------- ---- ---- ----" | 659 | // "--------- ---------- ----- ----" |
617 | printf( "%9u %02u-%02u-%02u %02u:%02u %s\n", | 660 | printf( "%9u " "%s " "%s\n", |
618 | (unsigned)zip_header.formatted.ucmpsize, | 661 | (unsigned)zip_header.formatted.ucmpsize, |
619 | (dostime & 0x01e00000) >> 21, | 662 | dtbuf, |
620 | (dostime & 0x001f0000) >> 16, | ||
621 | (((dostime & 0xfe000000) >> 25) + 1980) % 100, | ||
622 | (dostime & 0x0000f800) >> 11, | ||
623 | (dostime & 0x000007e0) >> 5, | ||
624 | dst_fn); | 663 | dst_fn); |
625 | total_usize += zip_header.formatted.ucmpsize; | ||
626 | } else { | 664 | } else { |
627 | unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize; | 665 | unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize; |
666 | if ((int32_t)percents < 0) | ||
667 | percents = 0; /* happens if ucmpsize < cmpsize */ | ||
628 | percents = percents * 100; | 668 | percents = percents * 100; |
629 | if (zip_header.formatted.ucmpsize) | 669 | if (zip_header.formatted.ucmpsize) |
630 | percents /= zip_header.formatted.ucmpsize; | 670 | percents /= zip_header.formatted.ucmpsize; |
631 | // " Length Method Size Ratio Date Time CRC-32 Name\n" | 671 | // " Length Method Size Cmpr Date Time CRC-32 Name\n" |
632 | // "-------- ------ ------- ----- ---- ---- ------ ----" | 672 | // "-------- ------ ------- ---- ---------- ----- -------- ----" |
633 | printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n", | 673 | printf( "%8u %s" "%9u%4u%% " "%s " "%08x " "%s\n", |
634 | (unsigned)zip_header.formatted.ucmpsize, | 674 | (unsigned)zip_header.formatted.ucmpsize, |
675 | zip_header.formatted.method == 0 ? "Stored" : "Defl:N", /* Defl is method 8 */ | ||
676 | /* TODO: show other methods? | ||
677 | * 1 - Shrunk | ||
678 | * 2 - Reduced with compression factor 1 | ||
679 | * 3 - Reduced with compression factor 2 | ||
680 | * 4 - Reduced with compression factor 3 | ||
681 | * 5 - Reduced with compression factor 4 | ||
682 | * 6 - Imploded | ||
683 | * 7 - Reserved for Tokenizing compression algorithm | ||
684 | * 9 - Deflate64 | ||
685 | * 10 - PKWARE Data Compression Library Imploding | ||
686 | * 11 - Reserved by PKWARE | ||
687 | * 12 - BZIP2 | ||
688 | */ | ||
635 | (unsigned)zip_header.formatted.cmpsize, | 689 | (unsigned)zip_header.formatted.cmpsize, |
636 | (unsigned)percents, | 690 | (unsigned)percents, |
637 | (dostime & 0x01e00000) >> 21, | 691 | dtbuf, |
638 | (dostime & 0x001f0000) >> 16, | ||
639 | (((dostime & 0xfe000000) >> 25) + 1980) % 100, | ||
640 | (dostime & 0x0000f800) >> 11, | ||
641 | (dostime & 0x000007e0) >> 5, | ||
642 | zip_header.formatted.crc32, | 692 | zip_header.formatted.crc32, |
643 | dst_fn); | 693 | dst_fn); |
644 | total_usize += zip_header.formatted.ucmpsize; | ||
645 | total_size += zip_header.formatted.cmpsize; | 694 | total_size += zip_header.formatted.cmpsize; |
646 | } | 695 | } |
696 | total_usize += zip_header.formatted.ucmpsize; | ||
647 | i = 'n'; | 697 | i = 'n'; |
648 | } else if (dst_fd == STDOUT_FILENO) { | 698 | } else if (dst_fd == STDOUT_FILENO) { |
649 | /* Extracting to STDOUT */ | 699 | /* Extracting to STDOUT */ |
@@ -746,21 +796,25 @@ int unzip_main(int argc, char **argv) | |||
746 | 796 | ||
747 | if (listing && quiet <= 1) { | 797 | if (listing && quiet <= 1) { |
748 | if (!verbose) { | 798 | if (!verbose) { |
749 | // " Length Date Time Name\n" | 799 | // " Length Date Time Name\n" |
750 | // " -------- ---- ---- ----" | 800 | // "--------- ---------- ----- ----" |
751 | printf( " -------- -------\n" | 801 | printf( " --------%21s" "-------\n" |
752 | "%9lu" " %u files\n", | 802 | "%9lu%21s" "%u files\n", |
753 | total_usize, total_entries); | 803 | "", |
804 | total_usize, "", total_entries); | ||
754 | } else { | 805 | } else { |
755 | unsigned long percents = total_usize - total_size; | 806 | unsigned long percents = total_usize - total_size; |
807 | if ((long)percents < 0) | ||
808 | percents = 0; /* happens if usize < size */ | ||
756 | percents = percents * 100; | 809 | percents = percents * 100; |
757 | if (total_usize) | 810 | if (total_usize) |
758 | percents /= total_usize; | 811 | percents /= total_usize; |
759 | // " Length Method Size Ratio Date Time CRC-32 Name\n" | 812 | // " Length Method Size Cmpr Date Time CRC-32 Name\n" |
760 | // "-------- ------ ------- ----- ---- ---- ------ ----" | 813 | // "-------- ------ ------- ---- ---------- ----- -------- ----" |
761 | printf( "-------- ------- --- -------\n" | 814 | printf( "-------- ------- ----%28s" "----\n" |
762 | "%8lu" "%17lu%4u%% %u files\n", | 815 | "%8lu" "%17lu%4u%%%28s" "%u files\n", |
763 | total_usize, total_size, (unsigned)percents, | 816 | "", |
817 | total_usize, total_size, (unsigned)percents, "", | ||
764 | total_entries); | 818 | total_entries); |
765 | } | 819 | } |
766 | } | 820 | } |
diff --git a/console-tools/dumpkmap.c b/console-tools/dumpkmap.c index bf8d690da..b6fd466dc 100644 --- a/console-tools/dumpkmap.c +++ b/console-tools/dumpkmap.c | |||
@@ -18,6 +18,7 @@ | |||
18 | //usage: "$ dumpkmap > keymap\n" | 18 | //usage: "$ dumpkmap > keymap\n" |
19 | 19 | ||
20 | #include "libbb.h" | 20 | #include "libbb.h" |
21 | #include "common_bufsiz.h" | ||
21 | 22 | ||
22 | /* From <linux/kd.h> */ | 23 | /* From <linux/kd.h> */ |
23 | struct kbentry { | 24 | struct kbentry { |
@@ -37,6 +38,7 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv) | |||
37 | struct kbentry ke; | 38 | struct kbentry ke; |
38 | int i, j, fd; | 39 | int i, j, fd; |
39 | #define flags bb_common_bufsiz1 | 40 | #define flags bb_common_bufsiz1 |
41 | setup_common_bufsiz(); | ||
40 | 42 | ||
41 | /* When user accidentally runs "dumpkmap FILE" | 43 | /* When user accidentally runs "dumpkmap FILE" |
42 | * instead of "dumpkmap >FILE", we'd dump binary stuff to tty. | 44 | * instead of "dumpkmap >FILE", we'd dump binary stuff to tty. |
diff --git a/console-tools/resize.c b/console-tools/resize.c index 4b0d63a03..a3342a195 100644 --- a/console-tools/resize.c +++ b/console-tools/resize.c | |||
@@ -14,10 +14,12 @@ | |||
14 | //usage: "Resize the screen" | 14 | //usage: "Resize the screen" |
15 | 15 | ||
16 | #include "libbb.h" | 16 | #include "libbb.h" |
17 | #include "common_bufsiz.h" | ||
17 | 18 | ||
18 | #define ESC "\033" | 19 | #define ESC "\033" |
19 | 20 | ||
20 | #define old_termios_p ((struct termios*)&bb_common_bufsiz1) | 21 | #define old_termios_p ((struct termios*)bb_common_bufsiz1) |
22 | #define INIT_G() do { setup_common_bufsiz(); } while (0) | ||
21 | 23 | ||
22 | static void | 24 | static void |
23 | onintr(int sig UNUSED_PARAM) | 25 | onintr(int sig UNUSED_PARAM) |
@@ -33,6 +35,8 @@ int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
33 | struct winsize w = { 0, 0, 0, 0 }; | 35 | struct winsize w = { 0, 0, 0, 0 }; |
34 | int ret; | 36 | int ret; |
35 | 37 | ||
38 | INIT_G(); | ||
39 | |||
36 | /* We use _stderr_ in order to make resize usable | 40 | /* We use _stderr_ in order to make resize usable |
37 | * in shell backticks (those redirect stdout away from tty). | 41 | * in shell backticks (those redirect stdout away from tty). |
38 | * NB: other versions of resize open "/dev/tty" | 42 | * NB: other versions of resize open "/dev/tty" |
diff --git a/coreutils/catv.c b/coreutils/catv.c index 6bb73ba63..0e71368a5 100644 --- a/coreutils/catv.c +++ b/coreutils/catv.c | |||
@@ -19,6 +19,7 @@ | |||
19 | //usage: "\n -v Don't use ^x or M-x escapes" | 19 | //usage: "\n -v Don't use ^x or M-x escapes" |
20 | 20 | ||
21 | #include "libbb.h" | 21 | #include "libbb.h" |
22 | #include "common_bufsiz.h" | ||
22 | 23 | ||
23 | #define CATV_OPT_e (1<<0) | 24 | #define CATV_OPT_e (1<<0) |
24 | #define CATV_OPT_t (1<<1) | 25 | #define CATV_OPT_t (1<<1) |
@@ -48,6 +49,9 @@ int catv_main(int argc UNUSED_PARAM, char **argv) | |||
48 | /* Read from stdin if there's nothing else to do. */ | 49 | /* Read from stdin if there's nothing else to do. */ |
49 | if (!argv[0]) | 50 | if (!argv[0]) |
50 | *--argv = (char*)"-"; | 51 | *--argv = (char*)"-"; |
52 | |||
53 | #define read_buf bb_common_bufsiz1 | ||
54 | setup_common_bufsiz(); | ||
51 | do { | 55 | do { |
52 | fd = open_or_warn_stdin(*argv); | 56 | fd = open_or_warn_stdin(*argv); |
53 | if (fd < 0) { | 57 | if (fd < 0) { |
@@ -57,7 +61,6 @@ int catv_main(int argc UNUSED_PARAM, char **argv) | |||
57 | for (;;) { | 61 | for (;;) { |
58 | int i, res; | 62 | int i, res; |
59 | 63 | ||
60 | #define read_buf bb_common_bufsiz1 | ||
61 | res = read(fd, read_buf, COMMON_BUFSIZE); | 64 | res = read(fd, read_buf, COMMON_BUFSIZE); |
62 | if (res < 0) | 65 | if (res < 0) |
63 | retval = EXIT_FAILURE; | 66 | retval = EXIT_FAILURE; |
diff --git a/coreutils/cksum.c b/coreutils/cksum.c index ac0b0c319..8a8a39f68 100644 --- a/coreutils/cksum.c +++ b/coreutils/cksum.c | |||
@@ -13,6 +13,7 @@ | |||
13 | //usage: "Calculate the CRC32 checksums of FILES" | 13 | //usage: "Calculate the CRC32 checksums of FILES" |
14 | 14 | ||
15 | #include "libbb.h" | 15 | #include "libbb.h" |
16 | #include "common_bufsiz.h" | ||
16 | 17 | ||
17 | /* This is a NOEXEC applet. Be very careful! */ | 18 | /* This is a NOEXEC applet. Be very careful! */ |
18 | 19 | ||
@@ -32,6 +33,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv) | |||
32 | argv++; | 33 | argv++; |
33 | #endif | 34 | #endif |
34 | 35 | ||
36 | setup_common_bufsiz(); | ||
35 | do { | 37 | do { |
36 | int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input); | 38 | int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input); |
37 | 39 | ||
@@ -43,7 +45,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv) | |||
43 | length = 0; | 45 | length = 0; |
44 | 46 | ||
45 | #define read_buf bb_common_bufsiz1 | 47 | #define read_buf bb_common_bufsiz1 |
46 | while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) { | 48 | while ((bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE)) > 0) { |
47 | length += bytes_read; | 49 | length += bytes_read; |
48 | crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table); | 50 | crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table); |
49 | } | 51 | } |
diff --git a/coreutils/date.c b/coreutils/date.c index 7965775fe..ff3214d85 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
@@ -138,6 +138,7 @@ | |||
138 | //usage: "Wed Apr 12 18:52:41 MDT 2000\n" | 138 | //usage: "Wed Apr 12 18:52:41 MDT 2000\n" |
139 | 139 | ||
140 | #include "libbb.h" | 140 | #include "libbb.h" |
141 | #include "common_bufsiz.h" | ||
141 | #if ENABLE_FEATURE_DATE_NANO | 142 | #if ENABLE_FEATURE_DATE_NANO |
142 | # include <sys/syscall.h> | 143 | # include <sys/syscall.h> |
143 | #endif | 144 | #endif |
@@ -368,6 +369,7 @@ int date_main(int argc UNUSED_PARAM, char **argv) | |||
368 | #endif | 369 | #endif |
369 | 370 | ||
370 | #define date_buf bb_common_bufsiz1 | 371 | #define date_buf bb_common_bufsiz1 |
372 | setup_common_bufsiz(); | ||
371 | if (*fmt_dt2str == '\0') { | 373 | if (*fmt_dt2str == '\0') { |
372 | /* With no format string, just print a blank line */ | 374 | /* With no format string, just print a blank line */ |
373 | date_buf[0] = '\0'; | 375 | date_buf[0] = '\0'; |
@@ -377,7 +379,7 @@ int date_main(int argc UNUSED_PARAM, char **argv) | |||
377 | fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S"; | 379 | fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S"; |
378 | } | 380 | } |
379 | /* Generate output string */ | 381 | /* Generate output string */ |
380 | strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time); | 382 | strftime(date_buf, COMMON_BUFSIZE, fmt_dt2str, &tm_time); |
381 | } | 383 | } |
382 | puts(date_buf); | 384 | puts(date_buf); |
383 | 385 | ||
diff --git a/coreutils/dd.c b/coreutils/dd.c index 7bd3e2084..00139773e 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -91,6 +91,7 @@ | |||
91 | //usage: "4+0 records out\n" | 91 | //usage: "4+0 records out\n" |
92 | 92 | ||
93 | #include "libbb.h" | 93 | #include "libbb.h" |
94 | #include "common_bufsiz.h" | ||
94 | 95 | ||
95 | /* This is a NOEXEC applet. Be very careful! */ | 96 | /* This is a NOEXEC applet. Be very careful! */ |
96 | 97 | ||
@@ -108,8 +109,9 @@ struct globals { | |||
108 | #endif | 109 | #endif |
109 | int flags; | 110 | int flags; |
110 | } FIX_ALIASING; | 111 | } FIX_ALIASING; |
111 | #define G (*(struct globals*)&bb_common_bufsiz1) | 112 | #define G (*(struct globals*)bb_common_bufsiz1) |
112 | #define INIT_G() do { \ | 113 | #define INIT_G() do { \ |
114 | setup_common_bufsiz(); \ | ||
113 | /* we have to zero it out because of NOEXEC */ \ | 115 | /* we have to zero it out because of NOEXEC */ \ |
114 | memset(&G, 0, sizeof(G)); \ | 116 | memset(&G, 0, sizeof(G)); \ |
115 | } while (0) | 117 | } while (0) |
diff --git a/coreutils/du.c b/coreutils/du.c index 1889c16bb..1240bcbbc 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
@@ -58,6 +58,7 @@ | |||
58 | //usage: "2417 .\n" | 58 | //usage: "2417 .\n" |
59 | 59 | ||
60 | #include "libbb.h" | 60 | #include "libbb.h" |
61 | #include "common_bufsiz.h" | ||
61 | 62 | ||
62 | enum { | 63 | enum { |
63 | OPT_a_files_too = (1 << 0), | 64 | OPT_a_files_too = (1 << 0), |
@@ -85,8 +86,8 @@ struct globals { | |||
85 | int du_depth; | 86 | int du_depth; |
86 | dev_t dir_dev; | 87 | dev_t dir_dev; |
87 | } FIX_ALIASING; | 88 | } FIX_ALIASING; |
88 | #define G (*(struct globals*)&bb_common_bufsiz1) | 89 | #define G (*(struct globals*)bb_common_bufsiz1) |
89 | #define INIT_G() do { } while (0) | 90 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
90 | 91 | ||
91 | 92 | ||
92 | static void print(unsigned long long size, const char *filename) | 93 | static void print(unsigned long long size, const char *filename) |
diff --git a/coreutils/expr.c b/coreutils/expr.c index c986f9327..ce6b2d189 100644 --- a/coreutils/expr.c +++ b/coreutils/expr.c | |||
@@ -61,6 +61,7 @@ | |||
61 | //usage: "of characters matched or 0." | 61 | //usage: "of characters matched or 0." |
62 | 62 | ||
63 | #include "libbb.h" | 63 | #include "libbb.h" |
64 | #include "common_bufsiz.h" | ||
64 | #include "xregex.h" | 65 | #include "xregex.h" |
65 | 66 | ||
66 | #if ENABLE_EXPR_MATH_SUPPORT_64 | 67 | #if ENABLE_EXPR_MATH_SUPPORT_64 |
@@ -99,8 +100,8 @@ typedef struct valinfo VALUE; | |||
99 | struct globals { | 100 | struct globals { |
100 | char **args; | 101 | char **args; |
101 | } FIX_ALIASING; | 102 | } FIX_ALIASING; |
102 | #define G (*(struct globals*)&bb_common_bufsiz1) | 103 | #define G (*(struct globals*)bb_common_bufsiz1) |
103 | #define INIT_G() do { } while (0) | 104 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
104 | 105 | ||
105 | /* forward declarations */ | 106 | /* forward declarations */ |
106 | static VALUE *eval(void); | 107 | static VALUE *eval(void); |
diff --git a/coreutils/ls.c b/coreutils/ls.c index 20bd61860..344b4e61e 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -93,6 +93,7 @@ | |||
93 | //usage: ) | 93 | //usage: ) |
94 | 94 | ||
95 | #include "libbb.h" | 95 | #include "libbb.h" |
96 | #include "common_bufsiz.h" | ||
96 | #include "unicode.h" | 97 | #include "unicode.h" |
97 | 98 | ||
98 | 99 | ||
@@ -365,8 +366,9 @@ struct globals { | |||
365 | time_t current_time_t; | 366 | time_t current_time_t; |
366 | #endif | 367 | #endif |
367 | } FIX_ALIASING; | 368 | } FIX_ALIASING; |
368 | #define G (*(struct globals*)&bb_common_bufsiz1) | 369 | #define G (*(struct globals*)bb_common_bufsiz1) |
369 | #define INIT_G() do { \ | 370 | #define INIT_G() do { \ |
371 | setup_common_bufsiz(); \ | ||
370 | /* we have to zero it out because of NOEXEC */ \ | 372 | /* we have to zero it out because of NOEXEC */ \ |
371 | memset(&G, 0, sizeof(G)); \ | 373 | memset(&G, 0, sizeof(G)); \ |
372 | IF_FEATURE_AUTOWIDTH(G_terminal_width = TERMINAL_WIDTH;) \ | 374 | IF_FEATURE_AUTOWIDTH(G_terminal_width = TERMINAL_WIDTH;) \ |
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 3e0423a3d..a5b3e99f7 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | 21 | ||
22 | /* #include "libbb.h" - done in od.c */ | 22 | /* #include "libbb.h" - done in od.c */ |
23 | #include "common_bufsiz.h" | ||
23 | #define assert(a) ((void)0) | 24 | #define assert(a) ((void)0) |
24 | 25 | ||
25 | 26 | ||
@@ -221,8 +222,9 @@ struct globals { | |||
221 | #if !ENABLE_LONG_OPTS | 222 | #if !ENABLE_LONG_OPTS |
222 | enum { G_pseudo_offset = 0 }; | 223 | enum { G_pseudo_offset = 0 }; |
223 | #endif | 224 | #endif |
224 | #define G (*(struct globals*)&bb_common_bufsiz1) | 225 | #define G (*(struct globals*)bb_common_bufsiz1) |
225 | #define INIT_G() do { \ | 226 | #define INIT_G() do { \ |
227 | setup_common_bufsiz(); \ | ||
226 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 228 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
227 | G.bytes_per_block = 32; \ | 229 | G.bytes_per_block = 32; \ |
228 | } while (0) | 230 | } while (0) |
diff --git a/coreutils/split.c b/coreutils/split.c index 1e1673efb..e67c3de66 100644 --- a/coreutils/split.c +++ b/coreutils/split.c | |||
@@ -22,6 +22,7 @@ | |||
22 | //usage: "$ cat TODO | split -a 2 -l 2 TODO_\n" | 22 | //usage: "$ cat TODO | split -a 2 -l 2 TODO_\n" |
23 | 23 | ||
24 | #include "libbb.h" | 24 | #include "libbb.h" |
25 | #include "common_bufsiz.h" | ||
25 | 26 | ||
26 | #if ENABLE_FEATURE_SPLIT_FANCY | 27 | #if ENABLE_FEATURE_SPLIT_FANCY |
27 | static const struct suffix_mult split_suffixes[] = { | 28 | static const struct suffix_mult split_suffixes[] = { |
@@ -78,6 +79,8 @@ int split_main(int argc UNUSED_PARAM, char **argv) | |||
78 | ssize_t bytes_read, to_write; | 79 | ssize_t bytes_read, to_write; |
79 | char *src; | 80 | char *src; |
80 | 81 | ||
82 | setup_common_bufsiz(); | ||
83 | |||
81 | opt_complementary = "?2:a+"; /* max 2 args; -a N */ | 84 | opt_complementary = "?2:a+"; /* max 2 args; -a N */ |
82 | opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len); | 85 | opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len); |
83 | 86 | ||
diff --git a/coreutils/stat.c b/coreutils/stat.c index be2723d13..f608045d7 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c | |||
@@ -102,6 +102,7 @@ | |||
102 | //usage: ) | 102 | //usage: ) |
103 | 103 | ||
104 | #include "libbb.h" | 104 | #include "libbb.h" |
105 | #include "common_bufsiz.h" | ||
105 | 106 | ||
106 | enum { | 107 | enum { |
107 | OPT_TERSE = (1 << 0), | 108 | OPT_TERSE = (1 << 0), |
@@ -157,8 +158,8 @@ static const char *human_time(time_t t) | |||
157 | 158 | ||
158 | /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/ | 159 | /*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/ |
159 | #define buf bb_common_bufsiz1 | 160 | #define buf bb_common_bufsiz1 |
160 | 161 | setup_common_bufsiz(); | |
161 | strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &t), ".000000000"); | 162 | strcpy(strftime_YYYYMMDDHHMMSS(buf, COMMON_BUFSIZE, &t), ".000000000"); |
162 | return buf; | 163 | return buf; |
163 | #undef buf | 164 | #undef buf |
164 | } | 165 | } |
diff --git a/coreutils/stty.c b/coreutils/stty.c index b63b0b91a..52967ea8f 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c | |||
@@ -32,6 +32,7 @@ | |||
32 | //usage: "\n [SETTING] See manpage" | 32 | //usage: "\n [SETTING] See manpage" |
33 | 33 | ||
34 | #include "libbb.h" | 34 | #include "libbb.h" |
35 | #include "common_bufsiz.h" | ||
35 | 36 | ||
36 | #ifndef _POSIX_VDISABLE | 37 | #ifndef _POSIX_VDISABLE |
37 | # define _POSIX_VDISABLE ((unsigned char) 0) | 38 | # define _POSIX_VDISABLE ((unsigned char) 0) |
@@ -317,7 +318,7 @@ enum { | |||
317 | #define MI_ENTRY(N,T,F,B,M) N "\0" | 318 | #define MI_ENTRY(N,T,F,B,M) N "\0" |
318 | 319 | ||
319 | /* Mode names given on command line */ | 320 | /* Mode names given on command line */ |
320 | static const char mode_name[] = | 321 | static const char mode_name[] ALIGN1 = |
321 | MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ) | 322 | MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ) |
322 | MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ) | 323 | MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ) |
323 | MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 ) | 324 | MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 ) |
@@ -680,7 +681,7 @@ enum { | |||
680 | #define CI_ENTRY(n,s,o) n "\0" | 681 | #define CI_ENTRY(n,s,o) n "\0" |
681 | 682 | ||
682 | /* Name given on command line */ | 683 | /* Name given on command line */ |
683 | static const char control_name[] = | 684 | static const char control_name[] ALIGN1 = |
684 | CI_ENTRY("intr", CINTR, VINTR ) | 685 | CI_ENTRY("intr", CINTR, VINTR ) |
685 | CI_ENTRY("quit", CQUIT, VQUIT ) | 686 | CI_ENTRY("quit", CQUIT, VQUIT ) |
686 | CI_ENTRY("erase", CERASE, VERASE ) | 687 | CI_ENTRY("erase", CERASE, VERASE ) |
@@ -722,7 +723,7 @@ static const char control_name[] = | |||
722 | #undef CI_ENTRY | 723 | #undef CI_ENTRY |
723 | #define CI_ENTRY(n,s,o) { s, o }, | 724 | #define CI_ENTRY(n,s,o) { s, o }, |
724 | 725 | ||
725 | static const struct control_info control_info[] = { | 726 | static const struct control_info control_info[] ALIGN2 = { |
726 | /* This should be verbatim cut-n-paste copy of the above CI_ENTRYs */ | 727 | /* This should be verbatim cut-n-paste copy of the above CI_ENTRYs */ |
727 | CI_ENTRY("intr", CINTR, VINTR ) | 728 | CI_ENTRY("intr", CINTR, VINTR ) |
728 | CI_ENTRY("quit", CQUIT, VQUIT ) | 729 | CI_ENTRY("quit", CQUIT, VQUIT ) |
@@ -775,7 +776,7 @@ struct globals { | |||
775 | unsigned current_col; | 776 | unsigned current_col; |
776 | char buf[10]; | 777 | char buf[10]; |
777 | } FIX_ALIASING; | 778 | } FIX_ALIASING; |
778 | #define G (*(struct globals*)&bb_common_bufsiz1) | 779 | #define G (*(struct globals*)bb_common_bufsiz1) |
779 | #define INIT_G() do { \ | 780 | #define INIT_G() do { \ |
780 | G.device_name = bb_msg_standard_input; \ | 781 | G.device_name = bb_msg_standard_input; \ |
781 | G.max_col = 80; \ | 782 | G.max_col = 80; \ |
diff --git a/coreutils/sum.c b/coreutils/sum.c index deb068e10..ec9ed2a11 100644 --- a/coreutils/sum.c +++ b/coreutils/sum.c | |||
@@ -21,6 +21,7 @@ | |||
21 | //usage: "\n -s Use System V sum algorithm (512byte blocks)" | 21 | //usage: "\n -s Use System V sum algorithm (512byte blocks)" |
22 | 22 | ||
23 | #include "libbb.h" | 23 | #include "libbb.h" |
24 | #include "common_bufsiz.h" | ||
24 | 25 | ||
25 | enum { SUM_BSD, PRINT_NAME, SUM_SYSV }; | 26 | enum { SUM_BSD, PRINT_NAME, SUM_SYSV }; |
26 | 27 | ||
@@ -30,18 +31,20 @@ enum { SUM_BSD, PRINT_NAME, SUM_SYSV }; | |||
30 | /* Return 1 if successful. */ | 31 | /* Return 1 if successful. */ |
31 | static unsigned sum_file(const char *file, unsigned type) | 32 | static unsigned sum_file(const char *file, unsigned type) |
32 | { | 33 | { |
33 | #define buf bb_common_bufsiz1 | ||
34 | unsigned long long total_bytes = 0; | 34 | unsigned long long total_bytes = 0; |
35 | int fd, r; | 35 | int fd, r; |
36 | /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ | 36 | /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ |
37 | unsigned s = 0; | 37 | unsigned s = 0; |
38 | 38 | ||
39 | #define buf bb_common_bufsiz1 | ||
40 | setup_common_bufsiz(); | ||
41 | |||
39 | fd = open_or_warn_stdin(file); | 42 | fd = open_or_warn_stdin(file); |
40 | if (fd == -1) | 43 | if (fd == -1) |
41 | return 0; | 44 | return 0; |
42 | 45 | ||
43 | while (1) { | 46 | while (1) { |
44 | size_t bytes_read = safe_read(fd, buf, BUFSIZ); | 47 | size_t bytes_read = safe_read(fd, buf, COMMON_BUFSIZE); |
45 | 48 | ||
46 | if ((ssize_t)bytes_read <= 0) { | 49 | if ((ssize_t)bytes_read <= 0) { |
47 | r = (fd && close(fd) != 0); | 50 | r = (fd && close(fd) != 0); |
diff --git a/coreutils/tail.c b/coreutils/tail.c index e352ab627..39f87679e 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -49,13 +49,14 @@ | |||
49 | //usage: "nameserver 10.0.0.1\n" | 49 | //usage: "nameserver 10.0.0.1\n" |
50 | 50 | ||
51 | #include "libbb.h" | 51 | #include "libbb.h" |
52 | #include "common_bufsiz.h" | ||
52 | 53 | ||
53 | struct globals { | 54 | struct globals { |
54 | bool from_top; | 55 | bool from_top; |
55 | bool exitcode; | 56 | bool exitcode; |
56 | } FIX_ALIASING; | 57 | } FIX_ALIASING; |
57 | #define G (*(struct globals*)&bb_common_bufsiz1) | 58 | #define G (*(struct globals*)bb_common_bufsiz1) |
58 | #define INIT_G() do { } while (0) | 59 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
59 | 60 | ||
60 | static void tail_xprint_header(const char *fmt, const char *filename) | 61 | static void tail_xprint_header(const char *fmt, const char *filename) |
61 | { | 62 | { |
diff --git a/coreutils/tee.c b/coreutils/tee.c index 48cc0508f..a68e9446f 100644 --- a/coreutils/tee.c +++ b/coreutils/tee.c | |||
@@ -23,6 +23,7 @@ | |||
23 | //usage: "Hello\n" | 23 | //usage: "Hello\n" |
24 | 24 | ||
25 | #include "libbb.h" | 25 | #include "libbb.h" |
26 | #include "common_bufsiz.h" | ||
26 | 27 | ||
27 | int tee_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 28 | int tee_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
28 | int tee_main(int argc, char **argv) | 29 | int tee_main(int argc, char **argv) |
@@ -37,6 +38,7 @@ int tee_main(int argc, char **argv) | |||
37 | #if ENABLE_FEATURE_TEE_USE_BLOCK_IO | 38 | #if ENABLE_FEATURE_TEE_USE_BLOCK_IO |
38 | ssize_t c; | 39 | ssize_t c; |
39 | # define buf bb_common_bufsiz1 | 40 | # define buf bb_common_bufsiz1 |
41 | setup_common_bufsiz(); | ||
40 | #else | 42 | #else |
41 | int c; | 43 | int c; |
42 | #endif | 44 | #endif |
@@ -79,7 +81,7 @@ int tee_main(int argc, char **argv) | |||
79 | /* names[0] will be filled later */ | 81 | /* names[0] will be filled later */ |
80 | 82 | ||
81 | #if ENABLE_FEATURE_TEE_USE_BLOCK_IO | 83 | #if ENABLE_FEATURE_TEE_USE_BLOCK_IO |
82 | while ((c = safe_read(STDIN_FILENO, buf, sizeof(buf))) > 0) { | 84 | while ((c = safe_read(STDIN_FILENO, buf, COMMON_BUFSIZE)) > 0) { |
83 | fp = files; | 85 | fp = files; |
84 | do | 86 | do |
85 | fwrite(buf, 1, c, *fp); | 87 | fwrite(buf, 1, c, *fp); |
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index 13617c6e1..c671b9252 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c | |||
@@ -89,17 +89,18 @@ | |||
89 | //usage: "+ shutdown -h +4m" | 89 | //usage: "+ shutdown -h +4m" |
90 | 90 | ||
91 | #include "libbb.h" | 91 | #include "libbb.h" |
92 | #include "common_bufsiz.h" | ||
92 | 93 | ||
93 | struct globals { | 94 | struct globals { |
94 | char **names; | 95 | char **names; |
95 | int cur; | 96 | int cur; |
96 | char *cmd[2 /* using 1 provokes compiler warning */]; | 97 | char *cmd[2 /* using 1 provokes compiler warning */]; |
97 | } FIX_ALIASING; | 98 | } FIX_ALIASING; |
98 | #define G (*(struct globals*)&bb_common_bufsiz1) | 99 | #define G (*(struct globals*)bb_common_bufsiz1) |
99 | #define names (G.names) | 100 | #define names (G.names) |
100 | #define cur (G.cur ) | 101 | #define cur (G.cur ) |
101 | #define cmd (G.cmd ) | 102 | #define cmd (G.cmd ) |
102 | #define INIT_G() do { } while (0) | 103 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
103 | 104 | ||
104 | enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(G)) / sizeof(cmd[0]) - 1 }; | 105 | enum { NUM_CMD = (COMMON_BUFSIZE - sizeof(G)) / sizeof(cmd[0]) - 1 }; |
105 | 106 | ||
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index d7c730f45..3625ffee8 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
@@ -153,6 +153,7 @@ Misc options: | |||
153 | /* Override ENABLE_FEATURE_PIDFILE */ | 153 | /* Override ENABLE_FEATURE_PIDFILE */ |
154 | #define WANT_PIDFILE 1 | 154 | #define WANT_PIDFILE 1 |
155 | #include "libbb.h" | 155 | #include "libbb.h" |
156 | #include "common_bufsiz.h" | ||
156 | 157 | ||
157 | struct pid_list { | 158 | struct pid_list { |
158 | struct pid_list *next; | 159 | struct pid_list *next; |
@@ -191,7 +192,7 @@ struct globals { | |||
191 | int user_id; | 192 | int user_id; |
192 | smallint signal_nr; | 193 | smallint signal_nr; |
193 | } FIX_ALIASING; | 194 | } FIX_ALIASING; |
194 | #define G (*(struct globals*)&bb_common_bufsiz1) | 195 | #define G (*(struct globals*)bb_common_bufsiz1) |
195 | #define userspec (G.userspec ) | 196 | #define userspec (G.userspec ) |
196 | #define cmdname (G.cmdname ) | 197 | #define cmdname (G.cmdname ) |
197 | #define execname (G.execname ) | 198 | #define execname (G.execname ) |
@@ -199,6 +200,7 @@ struct globals { | |||
199 | #define user_id (G.user_id ) | 200 | #define user_id (G.user_id ) |
200 | #define signal_nr (G.signal_nr ) | 201 | #define signal_nr (G.signal_nr ) |
201 | #define INIT_G() do { \ | 202 | #define INIT_G() do { \ |
203 | setup_common_bufsiz(); \ | ||
202 | user_id = -1; \ | 204 | user_id = -1; \ |
203 | signal_nr = 15; \ | 205 | signal_nr = 15; \ |
204 | } while (0) | 206 | } while (0) |
diff --git a/e2fsprogs/e2fs_lib.c b/e2fsprogs/e2fs_lib.c index a6aec9484..6ce655be3 100644 --- a/e2fsprogs/e2fs_lib.c +++ b/e2fsprogs/e2fs_lib.c | |||
@@ -149,14 +149,14 @@ const uint32_t e2attr_flags_value[] = { | |||
149 | EXT2_TOPDIR_FL | 149 | EXT2_TOPDIR_FL |
150 | }; | 150 | }; |
151 | 151 | ||
152 | const char e2attr_flags_sname[] = | 152 | const char e2attr_flags_sname[] ALIGN1 = |
153 | #ifdef ENABLE_COMPRESSION | 153 | #ifdef ENABLE_COMPRESSION |
154 | "BZXE" | 154 | "BZXE" |
155 | #endif | 155 | #endif |
156 | "I" | 156 | "I" |
157 | "suSDiadAcjtT"; | 157 | "suSDiadAcjtT"; |
158 | 158 | ||
159 | static const char e2attr_flags_lname[] = | 159 | static const char e2attr_flags_lname[] ALIGN1 = |
160 | #ifdef ENABLE_COMPRESSION | 160 | #ifdef ENABLE_COMPRESSION |
161 | "Compressed_File" "\0" | 161 | "Compressed_File" "\0" |
162 | "Compressed_Dirty_File" "\0" | 162 | "Compressed_Dirty_File" "\0" |
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index 987d97528..59514a1a6 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c | |||
@@ -60,6 +60,7 @@ | |||
60 | //usage: "\n -t TYPE List of filesystem types to check" | 60 | //usage: "\n -t TYPE List of filesystem types to check" |
61 | 61 | ||
62 | #include "libbb.h" | 62 | #include "libbb.h" |
63 | #include "common_bufsiz.h" | ||
63 | 64 | ||
64 | /* "progress indicator" code is somewhat buggy and ext[23] specific. | 65 | /* "progress indicator" code is somewhat buggy and ext[23] specific. |
65 | * We should be filesystem agnostic. IOW: there should be a well-defined | 66 | * We should be filesystem agnostic. IOW: there should be a well-defined |
@@ -169,8 +170,9 @@ struct globals { | |||
169 | struct fs_info *filesys_last; | 170 | struct fs_info *filesys_last; |
170 | struct fsck_instance *instance_list; | 171 | struct fsck_instance *instance_list; |
171 | } FIX_ALIASING; | 172 | } FIX_ALIASING; |
172 | #define G (*(struct globals*)&bb_common_bufsiz1) | 173 | #define G (*(struct globals*)bb_common_bufsiz1) |
173 | #define INIT_G() do { \ | 174 | #define INIT_G() do { \ |
175 | setup_common_bufsiz(); \ | ||
174 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 176 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
175 | } while (0) | 177 | } while (0) |
176 | 178 | ||
diff --git a/editors/diff.c b/editors/diff.c index a892cfdf2..ff269360f 100644 --- a/editors/diff.c +++ b/editors/diff.c | |||
@@ -125,6 +125,7 @@ | |||
125 | //usage: "\n -w Ignore all whitespace" | 125 | //usage: "\n -w Ignore all whitespace" |
126 | 126 | ||
127 | #include "libbb.h" | 127 | #include "libbb.h" |
128 | #include "common_bufsiz.h" | ||
128 | 129 | ||
129 | #if 0 | 130 | #if 0 |
130 | # define dbg_error_msg(...) bb_error_msg(__VA_ARGS__) | 131 | # define dbg_error_msg(...) bb_error_msg(__VA_ARGS__) |
@@ -748,6 +749,7 @@ static int diffreg(char *file[2]) | |||
748 | fp[i] = fdopen(fd, "r"); | 749 | fp[i] = fdopen(fd, "r"); |
749 | } | 750 | } |
750 | 751 | ||
752 | setup_common_bufsiz(); | ||
751 | while (1) { | 753 | while (1) { |
752 | const size_t sz = COMMON_BUFSIZE / 2; | 754 | const size_t sz = COMMON_BUFSIZE / 2; |
753 | char *const buf0 = bb_common_bufsiz1; | 755 | char *const buf0 = bb_common_bufsiz1; |
diff --git a/editors/ed.c b/editors/ed.c index a4c419099..c028b78cb 100644 --- a/editors/ed.c +++ b/editors/ed.c | |||
@@ -23,6 +23,7 @@ | |||
23 | //usage:#define ed_full_usage "" | 23 | //usage:#define ed_full_usage "" |
24 | 24 | ||
25 | #include "libbb.h" | 25 | #include "libbb.h" |
26 | #include "common_bufsiz.h" | ||
26 | 27 | ||
27 | typedef struct LINE { | 28 | typedef struct LINE { |
28 | struct LINE *next; | 29 | struct LINE *next; |
@@ -35,8 +36,8 @@ typedef struct LINE { | |||
35 | #define searchString bb_common_bufsiz1 | 36 | #define searchString bb_common_bufsiz1 |
36 | 37 | ||
37 | enum { | 38 | enum { |
38 | USERSIZE = sizeof(searchString) > 1024 ? 1024 | 39 | USERSIZE = COMMON_BUFSIZE > 1024 ? 1024 |
39 | : sizeof(searchString) - 1, /* max line length typed in by user */ | 40 | : COMMON_BUFSIZE - 1, /* max line length typed in by user */ |
40 | INITBUF_SIZE = 1024, /* initial buffer size */ | 41 | INITBUF_SIZE = 1024, /* initial buffer size */ |
41 | }; | 42 | }; |
42 | 43 | ||
@@ -66,6 +67,7 @@ struct globals { | |||
66 | #define lines (G.lines ) | 67 | #define lines (G.lines ) |
67 | #define marks (G.marks ) | 68 | #define marks (G.marks ) |
68 | #define INIT_G() do { \ | 69 | #define INIT_G() do { \ |
70 | setup_common_bufsiz(); \ | ||
69 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 71 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
70 | } while (0) | 72 | } while (0) |
71 | 73 | ||
diff --git a/editors/sed.c b/editors/sed.c index a0c713f58..b629e060a 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -86,6 +86,7 @@ | |||
86 | //usage: "bar\n" | 86 | //usage: "bar\n" |
87 | 87 | ||
88 | #include "libbb.h" | 88 | #include "libbb.h" |
89 | #include "common_bufsiz.h" | ||
89 | #include "xregex.h" | 90 | #include "xregex.h" |
90 | 91 | ||
91 | #if 0 | 92 | #if 0 |
@@ -161,8 +162,9 @@ struct globals { | |||
161 | int len; /* Space allocated */ | 162 | int len; /* Space allocated */ |
162 | } pipeline; | 163 | } pipeline; |
163 | } FIX_ALIASING; | 164 | } FIX_ALIASING; |
164 | #define G (*(struct globals*)&bb_common_bufsiz1) | 165 | #define G (*(struct globals*)bb_common_bufsiz1) |
165 | #define INIT_G() do { \ | 166 | #define INIT_G() do { \ |
167 | setup_common_bufsiz(); \ | ||
166 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 168 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
167 | G.sed_cmd_tail = &G.sed_cmd_head; \ | 169 | G.sed_cmd_tail = &G.sed_cmd_head; \ |
168 | } while (0) | 170 | } while (0) |
@@ -216,23 +218,33 @@ static void cleanup_outname(void) | |||
216 | 218 | ||
217 | /* strcpy, replacing "\from" with 'to'. If to is NUL, replacing "\any" with 'any' */ | 219 | /* strcpy, replacing "\from" with 'to'. If to is NUL, replacing "\any" with 'any' */ |
218 | 220 | ||
219 | static void parse_escapes(char *dest, const char *string, int len, char from, char to) | 221 | static unsigned parse_escapes(char *dest, const char *string, int len, char from, char to) |
220 | { | 222 | { |
223 | char *d = dest; | ||
221 | int i = 0; | 224 | int i = 0; |
222 | 225 | ||
226 | if (len == -1) | ||
227 | len = strlen(string); | ||
228 | |||
223 | while (i < len) { | 229 | while (i < len) { |
224 | if (string[i] == '\\') { | 230 | if (string[i] == '\\') { |
225 | if (!to || string[i+1] == from) { | 231 | if (!to || string[i+1] == from) { |
226 | *dest++ = to ? to : string[i+1]; | 232 | if ((*d = to ? to : string[i+1]) == '\0') |
233 | return d - dest; | ||
227 | i += 2; | 234 | i += 2; |
235 | d++; | ||
228 | continue; | 236 | continue; |
229 | } | 237 | } |
230 | *dest++ = string[i++]; | 238 | i++; /* skip backslash in string[] */ |
239 | *d++ = '\\'; | ||
240 | /* fall through: copy next char verbatim */ | ||
231 | } | 241 | } |
232 | /* TODO: is it safe wrt a string with trailing '\\' ? */ | 242 | if ((*d = string[i++]) == '\0') |
233 | *dest++ = string[i++]; | 243 | return d - dest; |
244 | d++; | ||
234 | } | 245 | } |
235 | *dest = '\0'; | 246 | *d = '\0'; |
247 | return d - dest; | ||
236 | } | 248 | } |
237 | 249 | ||
238 | static char *copy_parsing_escapes(const char *string, int len) | 250 | static char *copy_parsing_escapes(const char *string, int len) |
@@ -243,9 +255,8 @@ static char *copy_parsing_escapes(const char *string, int len) | |||
243 | /* sed recognizes \n */ | 255 | /* sed recognizes \n */ |
244 | /* GNU sed also recognizes \t and \r */ | 256 | /* GNU sed also recognizes \t and \r */ |
245 | for (s = "\nn\tt\rr"; *s; s += 2) { | 257 | for (s = "\nn\tt\rr"; *s; s += 2) { |
246 | parse_escapes(dest, string, len, s[1], s[0]); | 258 | len = parse_escapes(dest, string, len, s[1], s[0]); |
247 | string = dest; | 259 | string = dest; |
248 | len = strlen(dest); | ||
249 | } | 260 | } |
250 | return dest; | 261 | return dest; |
251 | } | 262 | } |
@@ -471,7 +482,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr) | |||
471 | */ | 482 | */ |
472 | static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr) | 483 | static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr) |
473 | { | 484 | { |
474 | static const char cmd_letters[] = "saicrw:btTydDgGhHlnNpPqx={}"; | 485 | static const char cmd_letters[] ALIGN1 = "saicrw:btTydDgGhHlnNpPqx={}"; |
475 | enum { | 486 | enum { |
476 | IDX_s = 0, | 487 | IDX_s = 0, |
477 | IDX_a, | 488 | IDX_a, |
@@ -514,6 +525,8 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr) | |||
514 | } | 525 | } |
515 | /* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */ | 526 | /* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */ |
516 | else if (idx <= IDX_c) { /* a,i,c */ | 527 | else if (idx <= IDX_c) { /* a,i,c */ |
528 | unsigned len; | ||
529 | |||
517 | if (idx < IDX_c) { /* a,i */ | 530 | if (idx < IDX_c) { /* a,i */ |
518 | if (sed_cmd->end_line || sed_cmd->end_match) | 531 | if (sed_cmd->end_line || sed_cmd->end_match) |
519 | bb_error_msg_and_die("command '%c' uses only one address", sed_cmd->cmd); | 532 | bb_error_msg_and_die("command '%c' uses only one address", sed_cmd->cmd); |
@@ -527,10 +540,11 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr) | |||
527 | break; | 540 | break; |
528 | cmdstr++; | 541 | cmdstr++; |
529 | } | 542 | } |
530 | sed_cmd->string = xstrdup(cmdstr); | 543 | len = strlen(cmdstr); |
544 | sed_cmd->string = copy_parsing_escapes(cmdstr, len); | ||
545 | cmdstr += len; | ||
531 | /* "\anychar" -> "anychar" */ | 546 | /* "\anychar" -> "anychar" */ |
532 | parse_escapes(sed_cmd->string, sed_cmd->string, strlen(cmdstr), '\0', '\0'); | 547 | parse_escapes(sed_cmd->string, sed_cmd->string, -1, '\0', '\0'); |
533 | cmdstr += strlen(cmdstr); | ||
534 | } | 548 | } |
535 | /* handle file cmds: (r)ead */ | 549 | /* handle file cmds: (r)ead */ |
536 | else if (idx <= IDX_w) { /* r,w */ | 550 | else if (idx <= IDX_w) { /* r,w */ |
@@ -562,8 +576,8 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr) | |||
562 | 576 | ||
563 | cmdstr += parse_regex_delim(cmdstr, &match, &replace)+1; | 577 | cmdstr += parse_regex_delim(cmdstr, &match, &replace)+1; |
564 | /* \n already parsed, but \delimiter needs unescaping. */ | 578 | /* \n already parsed, but \delimiter needs unescaping. */ |
565 | parse_escapes(match, match, strlen(match), i, i); | 579 | parse_escapes(match, match, -1, i, i); |
566 | parse_escapes(replace, replace, strlen(replace), i, i); | 580 | parse_escapes(replace, replace, -1, i, i); |
567 | 581 | ||
568 | sed_cmd->string = xzalloc((strlen(match) + 1) * 2); | 582 | sed_cmd->string = xzalloc((strlen(match) + 1) * 2); |
569 | for (i = 0; match[i] && replace[i]; i++) { | 583 | for (i = 0; match[i] && replace[i]; i++) { |
@@ -942,13 +956,22 @@ static void puts_maybe_newline(char *s, FILE *file, char *last_puts_char, char l | |||
942 | *last_puts_char = lpc; | 956 | *last_puts_char = lpc; |
943 | } | 957 | } |
944 | 958 | ||
945 | static void flush_append(char *last_puts_char, char last_gets_char) | 959 | static void flush_append(char *last_puts_char) |
946 | { | 960 | { |
947 | char *data; | 961 | char *data; |
948 | 962 | ||
949 | /* Output appended lines. */ | 963 | /* Output appended lines. */ |
950 | while ((data = (char *)llist_pop(&G.append_head))) { | 964 | while ((data = (char *)llist_pop(&G.append_head)) != NULL) { |
951 | puts_maybe_newline(data, G.nonstdout, last_puts_char, last_gets_char); | 965 | /* Append command does not respect "nonterminated-ness" |
966 | * of last line. Try this: | ||
967 | * $ echo -n "woot" | sed -e '/woot/a woo' - | ||
968 | * woot | ||
969 | * woo | ||
970 | * (both lines are terminated with \n) | ||
971 | * Therefore we do not propagate "last_gets_char" here, | ||
972 | * pass '\n' instead: | ||
973 | */ | ||
974 | puts_maybe_newline(data, G.nonstdout, last_puts_char, '\n'); | ||
952 | free(data); | 975 | free(data); |
953 | } | 976 | } |
954 | } | 977 | } |
@@ -956,13 +979,13 @@ static void flush_append(char *last_puts_char, char last_gets_char) | |||
956 | /* Get next line of input from G.input_file_list, flushing append buffer and | 979 | /* Get next line of input from G.input_file_list, flushing append buffer and |
957 | * noting if we ran out of files without a newline on the last line we read. | 980 | * noting if we ran out of files without a newline on the last line we read. |
958 | */ | 981 | */ |
959 | static char *get_next_line(char *gets_char, char *last_puts_char, char last_gets_char) | 982 | static char *get_next_line(char *gets_char, char *last_puts_char) |
960 | { | 983 | { |
961 | char *temp = NULL; | 984 | char *temp = NULL; |
962 | int len; | 985 | int len; |
963 | char gc; | 986 | char gc; |
964 | 987 | ||
965 | flush_append(last_puts_char, last_gets_char); | 988 | flush_append(last_puts_char); |
966 | 989 | ||
967 | /* will be returned if last line in the file | 990 | /* will be returned if last line in the file |
968 | * doesn't end with either '\n' or '\0' */ | 991 | * doesn't end with either '\n' or '\0' */ |
@@ -1045,7 +1068,7 @@ static void process_files(void) | |||
1045 | int substituted; | 1068 | int substituted; |
1046 | 1069 | ||
1047 | /* Prime the pump */ | 1070 | /* Prime the pump */ |
1048 | next_line = get_next_line(&next_gets_char, &last_puts_char, '\n' /*last_gets_char*/); | 1071 | next_line = get_next_line(&next_gets_char, &last_puts_char); |
1049 | 1072 | ||
1050 | /* Go through every line in each file */ | 1073 | /* Go through every line in each file */ |
1051 | again: | 1074 | again: |
@@ -1059,7 +1082,7 @@ static void process_files(void) | |||
1059 | 1082 | ||
1060 | /* Read one line in advance so we can act on the last line, | 1083 | /* Read one line in advance so we can act on the last line, |
1061 | * the '$' address */ | 1084 | * the '$' address */ |
1062 | next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char); | 1085 | next_line = get_next_line(&next_gets_char, &last_puts_char); |
1063 | linenum++; | 1086 | linenum++; |
1064 | 1087 | ||
1065 | /* For every line, go through all the commands */ | 1088 | /* For every line, go through all the commands */ |
@@ -1286,7 +1309,7 @@ static void process_files(void) | |||
1286 | free(pattern_space); | 1309 | free(pattern_space); |
1287 | pattern_space = next_line; | 1310 | pattern_space = next_line; |
1288 | last_gets_char = next_gets_char; | 1311 | last_gets_char = next_gets_char; |
1289 | next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char); | 1312 | next_line = get_next_line(&next_gets_char, &last_puts_char); |
1290 | substituted = 0; | 1313 | substituted = 0; |
1291 | linenum++; | 1314 | linenum++; |
1292 | break; | 1315 | break; |
@@ -1322,7 +1345,7 @@ static void process_files(void) | |||
1322 | pattern_space[len] = '\n'; | 1345 | pattern_space[len] = '\n'; |
1323 | strcpy(pattern_space + len+1, next_line); | 1346 | strcpy(pattern_space + len+1, next_line); |
1324 | last_gets_char = next_gets_char; | 1347 | last_gets_char = next_gets_char; |
1325 | next_line = get_next_line(&next_gets_char, &last_puts_char, last_gets_char); | 1348 | next_line = get_next_line(&next_gets_char, &last_puts_char); |
1326 | linenum++; | 1349 | linenum++; |
1327 | break; | 1350 | break; |
1328 | } | 1351 | } |
@@ -1426,7 +1449,7 @@ static void process_files(void) | |||
1426 | 1449 | ||
1427 | /* Delete and such jump here. */ | 1450 | /* Delete and such jump here. */ |
1428 | discard_line: | 1451 | discard_line: |
1429 | flush_append(&last_puts_char, last_gets_char); | 1452 | flush_append(&last_puts_char /*,last_gets_char*/); |
1430 | free(pattern_space); | 1453 | free(pattern_space); |
1431 | 1454 | ||
1432 | goto again; | 1455 | goto again; |
@@ -1512,12 +1535,12 @@ int sed_main(int argc UNUSED_PARAM, char **argv) | |||
1512 | while (opt_f) { // -f | 1535 | while (opt_f) { // -f |
1513 | char *line; | 1536 | char *line; |
1514 | FILE *cmdfile; | 1537 | FILE *cmdfile; |
1515 | cmdfile = xfopen_for_read(llist_pop(&opt_f)); | 1538 | cmdfile = xfopen_stdin(llist_pop(&opt_f)); |
1516 | while ((line = xmalloc_fgetline(cmdfile)) != NULL) { | 1539 | while ((line = xmalloc_fgetline(cmdfile)) != NULL) { |
1517 | add_cmd(line); | 1540 | add_cmd(line); |
1518 | free(line); | 1541 | free(line); |
1519 | } | 1542 | } |
1520 | fclose(cmdfile); | 1543 | fclose_if_not_stdin(cmdfile); |
1521 | } | 1544 | } |
1522 | /* if we didn't get a pattern from -e or -f, use argv[0] */ | 1545 | /* if we didn't get a pattern from -e or -f, use argv[0] */ |
1523 | if (!(opt & 0x30)) { | 1546 | if (!(opt & 0x30)) { |
diff --git a/editors/vi.c b/editors/vi.c index 75ce8d396..243676d5f 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -251,7 +251,7 @@ enum { | |||
251 | // cmds modifying text[] | 251 | // cmds modifying text[] |
252 | // vda: removed "aAiIs" as they switch us into insert mode | 252 | // vda: removed "aAiIs" as they switch us into insert mode |
253 | // and remembering input for replay after them makes no sense | 253 | // and remembering input for replay after them makes no sense |
254 | static const char modifying_cmds[] = "cCdDJoOpPrRxX<>~"; | 254 | static const char modifying_cmds[] ALIGN1 = "cCdDJoOpPrRxX<>~"; |
255 | #endif | 255 | #endif |
256 | 256 | ||
257 | enum { | 257 | enum { |
diff --git a/findutils/find.c b/findutils/find.c index a0d4853de..d71c69782 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -342,6 +342,7 @@ | |||
342 | 342 | ||
343 | #include <fnmatch.h> | 343 | #include <fnmatch.h> |
344 | #include "libbb.h" | 344 | #include "libbb.h" |
345 | #include "common_bufsiz.h" | ||
345 | #if ENABLE_FEATURE_FIND_REGEX | 346 | #if ENABLE_FEATURE_FIND_REGEX |
346 | # include "xregex.h" | 347 | # include "xregex.h" |
347 | #endif | 348 | #endif |
@@ -421,8 +422,9 @@ struct globals { | |||
421 | recurse_flags_t recurse_flags; | 422 | recurse_flags_t recurse_flags; |
422 | IF_FEATURE_FIND_EXEC_PLUS(unsigned max_argv_len;) | 423 | IF_FEATURE_FIND_EXEC_PLUS(unsigned max_argv_len;) |
423 | } FIX_ALIASING; | 424 | } FIX_ALIASING; |
424 | #define G (*(struct globals*)&bb_common_bufsiz1) | 425 | #define G (*(struct globals*)bb_common_bufsiz1) |
425 | #define INIT_G() do { \ | 426 | #define INIT_G() do { \ |
427 | setup_common_bufsiz(); \ | ||
426 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 428 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
427 | /* we have to zero it out because of NOEXEC */ \ | 429 | /* we have to zero it out because of NOEXEC */ \ |
428 | memset(&G, 0, sizeof(G)); \ | 430 | memset(&G, 0, sizeof(G)); \ |
diff --git a/findutils/grep.c b/findutils/grep.c index 5ed3faab2..e956abbb8 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -58,6 +58,7 @@ | |||
58 | //config: Print the specified number of context lines (-C). | 58 | //config: Print the specified number of context lines (-C). |
59 | 59 | ||
60 | #include "libbb.h" | 60 | #include "libbb.h" |
61 | #include "common_bufsiz.h" | ||
61 | #include "xregex.h" | 62 | #include "xregex.h" |
62 | 63 | ||
63 | 64 | ||
@@ -209,8 +210,9 @@ struct globals { | |||
209 | llist_t *pattern_head; /* growable list of patterns to match */ | 210 | llist_t *pattern_head; /* growable list of patterns to match */ |
210 | const char *cur_file; /* the current file we are reading */ | 211 | const char *cur_file; /* the current file we are reading */ |
211 | } FIX_ALIASING; | 212 | } FIX_ALIASING; |
212 | #define G (*(struct globals*)&bb_common_bufsiz1) | 213 | #define G (*(struct globals*)bb_common_bufsiz1) |
213 | #define INIT_G() do { \ | 214 | #define INIT_G() do { \ |
215 | setup_common_bufsiz(); \ | ||
214 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 216 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
215 | } while (0) | 217 | } while (0) |
216 | #define max_matches (G.max_matches ) | 218 | #define max_matches (G.max_matches ) |
diff --git a/findutils/xargs.c b/findutils/xargs.c index 8b7ab7b6a..eca1185ec 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
@@ -69,6 +69,7 @@ | |||
69 | #include <conio.h> | 69 | #include <conio.h> |
70 | #endif | 70 | #endif |
71 | #include "libbb.h" | 71 | #include "libbb.h" |
72 | #include "common_bufsiz.h" | ||
72 | 73 | ||
73 | /* This is a NOEXEC applet. Be very careful! */ | 74 | /* This is a NOEXEC applet. Be very careful! */ |
74 | 75 | ||
@@ -103,8 +104,9 @@ struct globals { | |||
103 | const char *eof_str; | 104 | const char *eof_str; |
104 | int idx; | 105 | int idx; |
105 | } FIX_ALIASING; | 106 | } FIX_ALIASING; |
106 | #define G (*(struct globals*)&bb_common_bufsiz1) | 107 | #define G (*(struct globals*)bb_common_bufsiz1) |
107 | #define INIT_G() do { \ | 108 | #define INIT_G() do { \ |
109 | setup_common_bufsiz(); \ | ||
108 | G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \ | 110 | G.eof_str = NULL; /* need to clear by hand because we are NOEXEC applet */ \ |
109 | IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \ | 111 | IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.repl_str = "{}";) \ |
110 | IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\n';) \ | 112 | IF_FEATURE_XARGS_SUPPORT_REPL_STR(G.eol_ch = '\n';) \ |
diff --git a/include/.gitignore b/include/.gitignore index 9d9b6c499..75afff9ca 100644 --- a/include/.gitignore +++ b/include/.gitignore | |||
@@ -8,3 +8,4 @@ | |||
8 | /NUM_APPLETS.h | 8 | /NUM_APPLETS.h |
9 | /usage_compressed.h | 9 | /usage_compressed.h |
10 | /usage.h | 10 | /usage.h |
11 | /common_bufsiz.h* | ||
diff --git a/include/libbb.h b/include/libbb.h index ffe1504e1..9a7590edd 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1852,10 +1852,6 @@ extern const char bb_PATH_root_path[] ALIGN1; /* "PATH=/sbin:/usr/sbin:/bin:/usr | |||
1852 | extern const int const_int_0; | 1852 | extern const int const_int_0; |
1853 | //extern const int const_int_1; | 1853 | //extern const int const_int_1; |
1854 | 1854 | ||
1855 | |||
1856 | /* Providing hard guarantee on minimum size (think of BUFSIZ == 128) */ | ||
1857 | enum { COMMON_BUFSIZE = (BUFSIZ >= 256*sizeof(void*) ? BUFSIZ+1 : 256*sizeof(void*)) }; | ||
1858 | extern char bb_common_bufsiz1[COMMON_BUFSIZE]; | ||
1859 | /* This struct is deliberately not defined. */ | 1855 | /* This struct is deliberately not defined. */ |
1860 | /* See docs/keep_data_small.txt */ | 1856 | /* See docs/keep_data_small.txt */ |
1861 | struct globals; | 1857 | struct globals; |
diff --git a/init/bootchartd.c b/init/bootchartd.c index c7388c99e..92aaade0f 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c | |||
@@ -47,6 +47,7 @@ | |||
47 | //config: and /etc/bootchartd.conf files. | 47 | //config: and /etc/bootchartd.conf files. |
48 | 48 | ||
49 | #include "libbb.h" | 49 | #include "libbb.h" |
50 | #include "common_bufsiz.h" | ||
50 | /* After libbb.h, since it needs sys/types.h on some systems */ | 51 | /* After libbb.h, since it needs sys/types.h on some systems */ |
51 | #include <sys/utsname.h> | 52 | #include <sys/utsname.h> |
52 | 53 | ||
@@ -115,8 +116,8 @@ | |||
115 | struct globals { | 116 | struct globals { |
116 | char jiffy_line[COMMON_BUFSIZE]; | 117 | char jiffy_line[COMMON_BUFSIZE]; |
117 | } FIX_ALIASING; | 118 | } FIX_ALIASING; |
118 | #define G (*(struct globals*)&bb_common_bufsiz1) | 119 | #define G (*(struct globals*)bb_common_bufsiz1) |
119 | #define INIT_G() do { } while (0) | 120 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
120 | 121 | ||
121 | static void dump_file(FILE *fp, const char *filename) | 122 | static void dump_file(FILE *fp, const char *filename) |
122 | { | 123 | { |
@@ -193,7 +194,7 @@ static char *make_tempdir(void) | |||
193 | * Since we unmount it at once, we can mount it anywhere. | 194 | * Since we unmount it at once, we can mount it anywhere. |
194 | * Try a few locations which are likely ti exist. | 195 | * Try a few locations which are likely ti exist. |
195 | */ | 196 | */ |
196 | static const char dirs[] = "/mnt\0""/tmp\0""/boot\0""/proc\0"; | 197 | static const char dirs[] ALIGN1 = "/mnt\0""/tmp\0""/boot\0""/proc\0"; |
197 | const char *try_dir = dirs; | 198 | const char *try_dir = dirs; |
198 | while (mount("none", try_dir, "tmpfs", MS_SILENT, "size=16m") != 0) { | 199 | while (mount("none", try_dir, "tmpfs", MS_SILENT, "size=16m") != 0) { |
199 | try_dir += strlen(try_dir) + 1; | 200 | try_dir += strlen(try_dir) + 1; |
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 4a9d363dd..c528c8a2c 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -835,7 +835,8 @@ static int busybox_main(char **argv) | |||
835 | full_write2_str(a); | 835 | full_write2_str(a); |
836 | full_write2_str("\n"); | 836 | full_write2_str("\n"); |
837 | i++; | 837 | i++; |
838 | a += strlen(a) + 1; | 838 | while (*a++ != '\0') |
839 | continue; | ||
839 | } | 840 | } |
840 | return 0; | 841 | return 0; |
841 | } | 842 | } |
diff --git a/libbb/common_bufsiz.c b/libbb/common_bufsiz.c new file mode 100644 index 000000000..1a3585169 --- /dev/null +++ b/libbb/common_bufsiz.c | |||
@@ -0,0 +1,74 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Utility routines. | ||
4 | * | ||
5 | * Copyright (C) 2016 Denys Vlasenko | ||
6 | * | ||
7 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
8 | */ | ||
9 | //config:config FEATURE_USE_BSS_TAIL | ||
10 | //config: bool "Use the end of BSS page" | ||
11 | //config: default n | ||
12 | //config: help | ||
13 | //config: Attempt to reclaim a small unused part of BSS. | ||
14 | //config: | ||
15 | //config: Executables have the following parts: | ||
16 | //config: = read-only executable code and constants, also known as "text" | ||
17 | //config: = read-write data | ||
18 | //config: = non-initialized (zeroed on demand) data, also known as "bss" | ||
19 | //config: | ||
20 | //config: At link time, "text" is padded to a full page. At runtime, all "text" | ||
21 | //config: pages are mapped RO and executable. | ||
22 | //config: "Data" starts on the next page boundary, but is not padded | ||
23 | //config: to a full page at the end. "Bss" starts wherever "data" ends. | ||
24 | //config: At runtime, "data" pages are mapped RW and they are file-backed | ||
25 | //config: (this includes a small portion of "bss" which may live in the last | ||
26 | //config: partial page of "data"). | ||
27 | //config: Pages which are fully in "bss" are mapped to anonymous memory. | ||
28 | //config: | ||
29 | //config: "Bss" end is usually not page-aligned. There is an unused space | ||
30 | //config: in the last page. Linker marks its start with the "_end" symbol. | ||
31 | //config: | ||
32 | //config: This option will attempt to use that space for bb_common_bufsiz1[] | ||
33 | //config: array. If it fits after _end, it will be used, and COMMON_BUFSIZE | ||
34 | //config: will be enlarged from its guaranteed minimum size of 1 kbyte. | ||
35 | //config: This may require recompilation a second time, since value of _end | ||
36 | //config: is known only after final link. | ||
37 | //config: | ||
38 | //config: If you are getting a build error like this: | ||
39 | //config: appletlib.c:(.text.main+0xd): undefined reference to '_end' | ||
40 | //config: disable this option. | ||
41 | |||
42 | //kbuild:lib-y += common_bufsiz.o | ||
43 | |||
44 | #include "libbb.h" | ||
45 | #include "common_bufsiz.h" | ||
46 | |||
47 | #if !ENABLE_FEATURE_USE_BSS_TAIL | ||
48 | |||
49 | /* We use it for "global" data via *(struct global*)bb_common_bufsiz1. | ||
50 | * Since gcc insists on aligning struct global's members, it would be a pity | ||
51 | * (and an alignment fault on some CPUs) to mess it up. */ | ||
52 | char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long)); | ||
53 | |||
54 | #else | ||
55 | |||
56 | # ifndef setup_common_bufsiz | ||
57 | /* | ||
58 | * It is not defined as a dummy macro. | ||
59 | * It means we have to provide this function. | ||
60 | */ | ||
61 | char *const bb_common_bufsiz1 __attribute__ ((section (".data"))); | ||
62 | void setup_common_bufsiz(void) | ||
63 | { | ||
64 | if (!bb_common_bufsiz1) | ||
65 | *(char**)&bb_common_bufsiz1 = xzalloc(COMMON_BUFSIZE); | ||
66 | } | ||
67 | # else | ||
68 | # ifndef bb_common_bufsiz1 | ||
69 | /* bb_common_bufsiz1[] is not aliased to _end[] */ | ||
70 | char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long)); | ||
71 | # endif | ||
72 | # endif | ||
73 | |||
74 | #endif | ||
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index e7b9ddfa1..6c91f1794 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -829,12 +829,11 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
829 | if (type == FIND_EXE_ONLY) { | 829 | if (type == FIND_EXE_ONLY) { |
830 | const char *p = applet_names; | 830 | const char *p = applet_names; |
831 | 831 | ||
832 | i = 0; | 832 | while (*p) { |
833 | while (i < NUM_APPLETS) { | ||
834 | if (strncmp(pfind, p, pf_len) == 0) | 833 | if (strncmp(pfind, p, pf_len) == 0) |
835 | add_match(xstrdup(p)); | 834 | add_match(xstrdup(p)); |
836 | p += strlen(p) + 1; | 835 | while (*p++ != '\0') |
837 | i++; | 836 | continue; |
838 | } | 837 | } |
839 | } | 838 | } |
840 | #endif | 839 | #endif |
diff --git a/libbb/messages.c b/libbb/messages.c index 2aa3f175d..d74c237e7 100644 --- a/libbb/messages.c +++ b/libbb/messages.c | |||
@@ -61,8 +61,3 @@ const char bb_path_wtmp_file[] ALIGN1 = | |||
61 | # error unknown path to wtmp file | 61 | # error unknown path to wtmp file |
62 | # endif | 62 | # endif |
63 | #endif | 63 | #endif |
64 | |||
65 | /* We use it for "global" data via *(struct global*)&bb_common_bufsiz1. | ||
66 | * Since gcc insists on aligning struct global's members, it would be a pity | ||
67 | * (and an alignment fault on some CPUs) to mess it up. */ | ||
68 | char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long)); | ||
diff --git a/libbb/mode_string.c b/libbb/mode_string.c index f1afe7d61..934eb6dc7 100644 --- a/libbb/mode_string.c +++ b/libbb/mode_string.c | |||
@@ -87,9 +87,9 @@ const char* FAST_FUNC bb_mode_string(mode_t mode) | |||
87 | 87 | ||
88 | /* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C', | 88 | /* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C', |
89 | * and 'B' types don't appear to be available on linux. So I removed them. */ | 89 | * and 'B' types don't appear to be available on linux. So I removed them. */ |
90 | static const char type_chars[16] = "?pc?d?b?-?l?s???"; | 90 | static const char type_chars[16] ALIGN1 = "?pc?d?b?-?l?s???"; |
91 | /********************************** 0123456789abcdef */ | 91 | /********************************** 0123456789abcdef */ |
92 | static const char mode_chars[7] = "rwxSTst"; | 92 | static const char mode_chars[7] ALIGN1 = "rwxSTst"; |
93 | 93 | ||
94 | const char* FAST_FUNC bb_mode_string(mode_t mode) | 94 | const char* FAST_FUNC bb_mode_string(mode_t mode) |
95 | { | 95 | { |
diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c index dbc15e5fc..4cdc2de76 100644 --- a/libbb/pw_encrypt.c +++ b/libbb/pw_encrypt.c | |||
@@ -9,7 +9,7 @@ | |||
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
12 | /* static const uint8_t ascii64[] = | 12 | /* static const uint8_t ascii64[] ALIGN1 = |
13 | * "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | 13 | * "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
14 | */ | 14 | */ |
15 | 15 | ||
diff --git a/libbb/u_signal_names.c b/libbb/u_signal_names.c index 8c78f5e20..b49714f2a 100644 --- a/libbb/u_signal_names.c +++ b/libbb/u_signal_names.c | |||
@@ -19,7 +19,7 @@ | |||
19 | /* Believe it or not, but some arches have more than 32 SIGs! | 19 | /* Believe it or not, but some arches have more than 32 SIGs! |
20 | * HPPA: SIGSTKFLT == 36. */ | 20 | * HPPA: SIGSTKFLT == 36. */ |
21 | 21 | ||
22 | static const char signals[][7] = { | 22 | static const char signals[][7] ALIGN1 = { |
23 | // SUSv3 says kill must support these, and specifies the numerical values, | 23 | // SUSv3 says kill must support these, and specifies the numerical values, |
24 | // http://www.opengroup.org/onlinepubs/009695399/utilities/kill.html | 24 | // http://www.opengroup.org/onlinepubs/009695399/utilities/kill.html |
25 | // {0, "EXIT"}, {1, "HUP"}, {2, "INT"}, {3, "QUIT"}, | 25 | // {0, "EXIT"}, {1, "HUP"}, {2, "INT"}, {3, "QUIT"}, |
diff --git a/loginutils/login.c b/loginutils/login.c index 4ebc18502..94b6c45db 100644 --- a/loginutils/login.c +++ b/loginutils/login.c | |||
@@ -62,6 +62,7 @@ | |||
62 | //usage: "\n -p Preserve environment" | 62 | //usage: "\n -p Preserve environment" |
63 | 63 | ||
64 | #include "libbb.h" | 64 | #include "libbb.h" |
65 | #include "common_bufsiz.h" | ||
65 | #include <syslog.h> | 66 | #include <syslog.h> |
66 | #include <sys/resource.h> | 67 | #include <sys/resource.h> |
67 | 68 | ||
@@ -138,8 +139,8 @@ enum { | |||
138 | struct globals { | 139 | struct globals { |
139 | struct termios tty_attrs; | 140 | struct termios tty_attrs; |
140 | } FIX_ALIASING; | 141 | } FIX_ALIASING; |
141 | #define G (*(struct globals*)&bb_common_bufsiz1) | 142 | #define G (*(struct globals*)bb_common_bufsiz1) |
142 | #define INIT_G() do { } while (0) | 143 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
143 | 144 | ||
144 | 145 | ||
145 | #if ENABLE_FEATURE_NOLOGIN | 146 | #if ENABLE_FEATURE_NOLOGIN |
diff --git a/miscutils/adjtimex.c b/miscutils/adjtimex.c index 534364a69..058aa9a5c 100644 --- a/miscutils/adjtimex.c +++ b/miscutils/adjtimex.c | |||
@@ -29,7 +29,7 @@ | |||
29 | # include <sys/timex.h> | 29 | # include <sys/timex.h> |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | static const uint16_t statlist_bit[] = { | 32 | static const uint16_t statlist_bit[] ALIGN2 = { |
33 | STA_PLL, | 33 | STA_PLL, |
34 | STA_PPSFREQ, | 34 | STA_PPSFREQ, |
35 | STA_PPSTIME, | 35 | STA_PPSTIME, |
@@ -45,7 +45,7 @@ static const uint16_t statlist_bit[] = { | |||
45 | STA_CLOCKERR, | 45 | STA_CLOCKERR, |
46 | 0 | 46 | 0 |
47 | }; | 47 | }; |
48 | static const char statlist_name[] = | 48 | static const char statlist_name[] ALIGN1 = |
49 | "PLL" "\0" | 49 | "PLL" "\0" |
50 | "PPSFREQ" "\0" | 50 | "PPSFREQ" "\0" |
51 | "PPSTIME" "\0" | 51 | "PPSTIME" "\0" |
@@ -61,7 +61,7 @@ static const char statlist_name[] = | |||
61 | "CLOCKERR" | 61 | "CLOCKERR" |
62 | ; | 62 | ; |
63 | 63 | ||
64 | static const char ret_code_descript[] = | 64 | static const char ret_code_descript[] ALIGN1 = |
65 | "clock synchronized" "\0" | 65 | "clock synchronized" "\0" |
66 | "insert leap second" "\0" | 66 | "insert leap second" "\0" |
67 | "delete leap second" "\0" | 67 | "delete leap second" "\0" |
diff --git a/miscutils/chat.c b/miscutils/chat.c index bd2abc24a..6b429f2a6 100644 --- a/miscutils/chat.c +++ b/miscutils/chat.c | |||
@@ -17,6 +17,7 @@ | |||
17 | //usage: "chat '' ATZ OK ATD123456 CONNECT '' ogin: pppuser word: ppppass '~'" | 17 | //usage: "chat '' ATZ OK ATD123456 CONNECT '' ogin: pppuser word: ppppass '~'" |
18 | 18 | ||
19 | #include "libbb.h" | 19 | #include "libbb.h" |
20 | #include "common_bufsiz.h" | ||
20 | 21 | ||
21 | // default timeout: 45 sec | 22 | // default timeout: 45 sec |
22 | #define DEFAULT_CHAT_TIMEOUT 45*1000 | 23 | #define DEFAULT_CHAT_TIMEOUT 45*1000 |
@@ -285,9 +286,10 @@ int chat_main(int argc UNUSED_PARAM, char **argv) | |||
285 | && poll(&pfd, 1, timeout) > 0 | 286 | && poll(&pfd, 1, timeout) > 0 |
286 | && (pfd.revents & POLLIN) | 287 | && (pfd.revents & POLLIN) |
287 | ) { | 288 | ) { |
288 | #define buf bb_common_bufsiz1 | ||
289 | llist_t *l; | 289 | llist_t *l; |
290 | ssize_t delta; | 290 | ssize_t delta; |
291 | #define buf bb_common_bufsiz1 | ||
292 | setup_common_bufsiz(); | ||
291 | 293 | ||
292 | // read next char from device | 294 | // read next char from device |
293 | if (safe_read(STDIN_FILENO, buf+buf_len, 1) > 0) { | 295 | if (safe_read(STDIN_FILENO, buf+buf_len, 1) > 0) { |
diff --git a/miscutils/conspy.c b/miscutils/conspy.c index 1a46a4340..f6468c116 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c | |||
@@ -42,6 +42,7 @@ | |||
42 | //usage: "\n -y LINE Starting line" | 42 | //usage: "\n -y LINE Starting line" |
43 | 43 | ||
44 | #include "libbb.h" | 44 | #include "libbb.h" |
45 | #include "common_bufsiz.h" | ||
45 | #include <sys/kd.h> | 46 | #include <sys/kd.h> |
46 | 47 | ||
47 | #define ESC "\033" | 48 | #define ESC "\033" |
@@ -363,7 +364,6 @@ int conspy_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
363 | int conspy_main(int argc UNUSED_PARAM, char **argv) | 364 | int conspy_main(int argc UNUSED_PARAM, char **argv) |
364 | { | 365 | { |
365 | char tty_name[sizeof(DEV_TTY "NN")]; | 366 | char tty_name[sizeof(DEV_TTY "NN")]; |
366 | #define keybuf bb_common_bufsiz1 | ||
367 | struct termios termbuf; | 367 | struct termios termbuf; |
368 | unsigned opts; | 368 | unsigned opts; |
369 | unsigned ttynum; | 369 | unsigned ttynum; |
@@ -382,6 +382,9 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) | |||
382 | 382 | ||
383 | applet_long_options = getopt_longopts; | 383 | applet_long_options = getopt_longopts; |
384 | #endif | 384 | #endif |
385 | #define keybuf bb_common_bufsiz1 | ||
386 | setup_common_bufsiz(); | ||
387 | |||
385 | INIT_G(); | 388 | INIT_G(); |
386 | strcpy(G.vcsa_name, DEV_VCSA); | 389 | strcpy(G.vcsa_name, DEV_VCSA); |
387 | 390 | ||
@@ -513,7 +516,7 @@ int conspy_main(int argc UNUSED_PARAM, char **argv) | |||
513 | default: | 516 | default: |
514 | // Read the keys pressed | 517 | // Read the keys pressed |
515 | k = keybuf + G.key_count; | 518 | k = keybuf + G.key_count; |
516 | bytes_read = read(G.kbd_fd, k, sizeof(keybuf) - G.key_count); | 519 | bytes_read = read(G.kbd_fd, k, COMMON_BUFSIZE - G.key_count); |
517 | if (bytes_read < 0) | 520 | if (bytes_read < 0) |
518 | goto abort; | 521 | goto abort; |
519 | 522 | ||
diff --git a/miscutils/crond.c b/miscutils/crond.c index eb327f855..f96c96ee7 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
@@ -60,6 +60,7 @@ | |||
60 | //usage: "\n -c DIR Cron dir. Default:"CONFIG_FEATURE_CROND_DIR"/crontabs" | 60 | //usage: "\n -c DIR Cron dir. Default:"CONFIG_FEATURE_CROND_DIR"/crontabs" |
61 | 61 | ||
62 | #include "libbb.h" | 62 | #include "libbb.h" |
63 | #include "common_bufsiz.h" | ||
63 | #include <syslog.h> | 64 | #include <syslog.h> |
64 | 65 | ||
65 | /* glibc frees previous setenv'ed value when we do next setenv() | 66 | /* glibc frees previous setenv'ed value when we do next setenv() |
@@ -140,8 +141,9 @@ struct globals { | |||
140 | char *env_var_logname; | 141 | char *env_var_logname; |
141 | #endif | 142 | #endif |
142 | } FIX_ALIASING; | 143 | } FIX_ALIASING; |
143 | #define G (*(struct globals*)&bb_common_bufsiz1) | 144 | #define G (*(struct globals*)bb_common_bufsiz1) |
144 | #define INIT_G() do { \ | 145 | #define INIT_G() do { \ |
146 | setup_common_bufsiz(); \ | ||
145 | G.log_level = 8; \ | 147 | G.log_level = 8; \ |
146 | G.crontab_dir_name = CRONTABS; \ | 148 | G.crontab_dir_name = CRONTABS; \ |
147 | } while (0) | 149 | } while (0) |
diff --git a/miscutils/dc.c b/miscutils/dc.c index 9c74172ba..4d92bc3d0 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c | |||
@@ -4,6 +4,7 @@ | |||
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "libbb.h" | 6 | #include "libbb.h" |
7 | #include "common_bufsiz.h" | ||
7 | #include <math.h> | 8 | #include <math.h> |
8 | 9 | ||
9 | //usage:#define dc_trivial_usage | 10 | //usage:#define dc_trivial_usage |
@@ -47,11 +48,12 @@ struct globals { | |||
47 | double stack[1]; | 48 | double stack[1]; |
48 | } FIX_ALIASING; | 49 | } FIX_ALIASING; |
49 | enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof(double) }; | 50 | enum { STACK_SIZE = (COMMON_BUFSIZE - offsetof(struct globals, stack)) / sizeof(double) }; |
50 | #define G (*(struct globals*)&bb_common_bufsiz1) | 51 | #define G (*(struct globals*)bb_common_bufsiz1) |
51 | #define pointer (G.pointer ) | 52 | #define pointer (G.pointer ) |
52 | #define base (G.base ) | 53 | #define base (G.base ) |
53 | #define stack (G.stack ) | 54 | #define stack (G.stack ) |
54 | #define INIT_G() do { \ | 55 | #define INIT_G() do { \ |
56 | setup_common_bufsiz(); \ | ||
55 | base = 10; \ | 57 | base = 10; \ |
56 | } while (0) | 58 | } while (0) |
57 | 59 | ||
diff --git a/miscutils/eject.c b/miscutils/eject.c index e33d79127..16ae250ff 100644 --- a/miscutils/eject.c +++ b/miscutils/eject.c | |||
@@ -40,7 +40,7 @@ | |||
40 | #if ENABLE_FEATURE_EJECT_SCSI | 40 | #if ENABLE_FEATURE_EJECT_SCSI |
41 | static void eject_scsi(const char *dev) | 41 | static void eject_scsi(const char *dev) |
42 | { | 42 | { |
43 | static const char sg_commands[3][6] = { | 43 | static const char sg_commands[3][6] ALIGN1 = { |
44 | { ALLOW_MEDIUM_REMOVAL, 0, 0, 0, 0, 0 }, | 44 | { ALLOW_MEDIUM_REMOVAL, 0, 0, 0, 0, 0 }, |
45 | { START_STOP, 0, 0, 0, 1, 0 }, | 45 | { START_STOP, 0, 0, 0, 1, 0 }, |
46 | { START_STOP, 0, 0, 0, 2, 0 } | 46 | { START_STOP, 0, 0, 0, 2, 0 } |
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index 9557c41db..3ddf8a242 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c | |||
@@ -34,6 +34,7 @@ | |||
34 | //usage: "\n commands: 'NN' (% for progress bar) or 'exit'" | 34 | //usage: "\n commands: 'NN' (% for progress bar) or 'exit'" |
35 | 35 | ||
36 | #include "libbb.h" | 36 | #include "libbb.h" |
37 | #include "common_bufsiz.h" | ||
37 | #include <linux/fb.h> | 38 | #include <linux/fb.h> |
38 | 39 | ||
39 | /* If you want logging messages on /tmp/fbsplash.log... */ | 40 | /* If you want logging messages on /tmp/fbsplash.log... */ |
@@ -373,10 +374,12 @@ static void fb_drawimage(void) | |||
373 | * in pure binary by 1 or 2 bytes. (we support only 1 byte) | 374 | * in pure binary by 1 or 2 bytes. (we support only 1 byte) |
374 | */ | 375 | */ |
375 | #define concat_buf bb_common_bufsiz1 | 376 | #define concat_buf bb_common_bufsiz1 |
377 | setup_common_bufsiz(); | ||
378 | |||
376 | read_ptr = concat_buf; | 379 | read_ptr = concat_buf; |
377 | while (1) { | 380 | while (1) { |
378 | int w, h, max_color_val; | 381 | int w, h, max_color_val; |
379 | int rem = concat_buf + sizeof(concat_buf) - read_ptr; | 382 | int rem = concat_buf + COMMON_BUFSIZE - read_ptr; |
380 | if (rem < 2 | 383 | if (rem < 2 |
381 | || fgets(read_ptr, rem, theme_file) == NULL | 384 | || fgets(read_ptr, rem, theme_file) == NULL |
382 | ) { | 385 | ) { |
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index 8e201ac35..b4c5876d4 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c | |||
@@ -63,6 +63,7 @@ | |||
63 | //usage: "\n -z Reread partition table" | 63 | //usage: "\n -z Reread partition table" |
64 | 64 | ||
65 | #include "libbb.h" | 65 | #include "libbb.h" |
66 | #include "common_bufsiz.h" | ||
66 | /* must be _after_ libbb.h: */ | 67 | /* must be _after_ libbb.h: */ |
67 | #include <linux/hdreg.h> | 68 | #include <linux/hdreg.h> |
68 | #include <sys/mount.h> | 69 | #include <sys/mount.h> |
@@ -367,7 +368,7 @@ struct globals { | |||
367 | unsigned char flushcache[4] = { WIN_FLUSHCACHE, 0, 0, 0 }; | 368 | unsigned char flushcache[4] = { WIN_FLUSHCACHE, 0, 0, 0 }; |
368 | #endif | 369 | #endif |
369 | } FIX_ALIASING; | 370 | } FIX_ALIASING; |
370 | #define G (*(struct globals*)&bb_common_bufsiz1) | 371 | #define G (*(struct globals*)bb_common_bufsiz1) |
371 | #define get_identity (G.get_identity ) | 372 | #define get_identity (G.get_identity ) |
372 | #define get_geom (G.get_geom ) | 373 | #define get_geom (G.get_geom ) |
373 | #define do_flush (G.do_flush ) | 374 | #define do_flush (G.do_flush ) |
@@ -431,6 +432,7 @@ struct globals { | |||
431 | #define hwif_ctrl (G.hwif_ctrl ) | 432 | #define hwif_ctrl (G.hwif_ctrl ) |
432 | #define hwif_irq (G.hwif_irq ) | 433 | #define hwif_irq (G.hwif_irq ) |
433 | #define INIT_G() do { \ | 434 | #define INIT_G() do { \ |
435 | setup_common_bufsiz(); \ | ||
434 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 436 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
435 | } while (0) | 437 | } while (0) |
436 | 438 | ||
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c index aa1c7c5cc..57bb72ae7 100644 --- a/miscutils/i2c_tools.c +++ b/miscutils/i2c_tools.c | |||
@@ -60,6 +60,7 @@ | |||
60 | */ | 60 | */ |
61 | 61 | ||
62 | #include "libbb.h" | 62 | #include "libbb.h" |
63 | #include "common_bufsiz.h" | ||
63 | 64 | ||
64 | #include <linux/i2c.h> | 65 | #include <linux/i2c.h> |
65 | #include <linux/i2c-dev.h> | 66 | #include <linux/i2c-dev.h> |
diff --git a/miscutils/inotifyd.c b/miscutils/inotifyd.c index 908d657fd..52db08ada 100644 --- a/miscutils/inotifyd.c +++ b/miscutils/inotifyd.c | |||
@@ -56,6 +56,7 @@ | |||
56 | //usage: "\nWhen x event happens for all FILEs, inotifyd exits." | 56 | //usage: "\nWhen x event happens for all FILEs, inotifyd exits." |
57 | 57 | ||
58 | #include "libbb.h" | 58 | #include "libbb.h" |
59 | #include "common_bufsiz.h" | ||
59 | #include <sys/inotify.h> | 60 | #include <sys/inotify.h> |
60 | 61 | ||
61 | static const char mask_names[] ALIGN1 = | 62 | static const char mask_names[] ALIGN1 = |
@@ -161,9 +162,10 @@ int inotifyd_main(int argc, char **argv) | |||
161 | 162 | ||
162 | // read out all pending events | 163 | // read out all pending events |
163 | // (NB: len must be int, not ssize_t or long!) | 164 | // (NB: len must be int, not ssize_t or long!) |
164 | xioctl(pfd.fd, FIONREAD, &len); | ||
165 | #define eventbuf bb_common_bufsiz1 | 165 | #define eventbuf bb_common_bufsiz1 |
166 | ie = buf = (len <= sizeof(eventbuf)) ? eventbuf : xmalloc(len); | 166 | setup_common_bufsiz(); |
167 | xioctl(pfd.fd, FIONREAD, &len); | ||
168 | ie = buf = (len <= COMMON_BUFSIZE) ? eventbuf : xmalloc(len); | ||
167 | len = full_read(pfd.fd, buf, len); | 169 | len = full_read(pfd.fd, buf, len); |
168 | // process events. N.B. events may vary in length | 170 | // process events. N.B. events may vary in length |
169 | while (len > 0) { | 171 | while (len > 0) { |
diff --git a/miscutils/ionice.c b/miscutils/ionice.c index bd300605f..0c14256ab 100644 --- a/miscutils/ionice.c +++ b/miscutils/ionice.c | |||
@@ -41,7 +41,7 @@ enum { | |||
41 | IOPRIO_CLASS_IDLE | 41 | IOPRIO_CLASS_IDLE |
42 | }; | 42 | }; |
43 | 43 | ||
44 | static const char to_prio[] = "none\0realtime\0best-effort\0idle"; | 44 | static const char to_prio[] ALIGN1 = "none\0realtime\0best-effort\0idle"; |
45 | 45 | ||
46 | #define IOPRIO_CLASS_SHIFT 13 | 46 | #define IOPRIO_CLASS_SHIFT 13 |
47 | 47 | ||
diff --git a/miscutils/less.c b/miscutils/less.c index cc0e20bc7..248f3e3f5 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -131,6 +131,7 @@ | |||
131 | #endif | 131 | #endif |
132 | 132 | ||
133 | #include "libbb.h" | 133 | #include "libbb.h" |
134 | #include "common_bufsiz.h" | ||
134 | #if ENABLE_FEATURE_LESS_REGEXP | 135 | #if ENABLE_FEATURE_LESS_REGEXP |
135 | #include "xregex.h" | 136 | #include "xregex.h" |
136 | #endif | 137 | #endif |
@@ -445,7 +446,6 @@ static int at_end(void) | |||
445 | */ | 446 | */ |
446 | static void read_lines(void) | 447 | static void read_lines(void) |
447 | { | 448 | { |
448 | #define readbuf bb_common_bufsiz1 | ||
449 | char *current_line, *p; | 449 | char *current_line, *p; |
450 | int w = width; | 450 | int w = width; |
451 | char last_terminated = terminated; | 451 | char last_terminated = terminated; |
@@ -455,6 +455,9 @@ static void read_lines(void) | |||
455 | unsigned old_max_fline = max_fline; | 455 | unsigned old_max_fline = max_fline; |
456 | #endif | 456 | #endif |
457 | 457 | ||
458 | #define readbuf bb_common_bufsiz1 | ||
459 | setup_common_bufsiz(); | ||
460 | |||
458 | /* (careful: max_fline can be -1) */ | 461 | /* (careful: max_fline can be -1) */ |
459 | if (max_fline + 1 > MAXLINES) | 462 | if (max_fline + 1 > MAXLINES) |
460 | return; | 463 | return; |
@@ -486,7 +489,7 @@ static void read_lines(void) | |||
486 | time_t t; | 489 | time_t t; |
487 | 490 | ||
488 | errno = 0; | 491 | errno = 0; |
489 | eof_error = safe_read(STDIN_FILENO, readbuf, sizeof(readbuf)); | 492 | eof_error = safe_read(STDIN_FILENO, readbuf, COMMON_BUFSIZE); |
490 | if (errno != EAGAIN) | 493 | if (errno != EAGAIN) |
491 | break; | 494 | break; |
492 | t = time(NULL); | 495 | t = time(NULL); |
diff --git a/miscutils/microcom.c b/miscutils/microcom.c index 5e29a1acd..d9e8f9187 100644 --- a/miscutils/microcom.c +++ b/miscutils/microcom.c | |||
@@ -19,6 +19,7 @@ | |||
19 | //usage: "\n -X Disable special meaning of NUL and Ctrl-X from stdin" | 19 | //usage: "\n -X Disable special meaning of NUL and Ctrl-X from stdin" |
20 | 20 | ||
21 | #include "libbb.h" | 21 | #include "libbb.h" |
22 | #include "common_bufsiz.h" | ||
22 | 23 | ||
23 | // set raw tty mode | 24 | // set raw tty mode |
24 | static void xget1(int fd, struct termios *t, struct termios *oldt) | 25 | static void xget1(int fd, struct termios *t, struct termios *oldt) |
@@ -155,10 +156,11 @@ int microcom_main(int argc UNUSED_PARAM, char **argv) | |||
155 | skip_write: ; | 156 | skip_write: ; |
156 | } | 157 | } |
157 | if (pfd[0].revents) { | 158 | if (pfd[0].revents) { |
158 | #define iobuf bb_common_bufsiz1 | ||
159 | ssize_t len; | 159 | ssize_t len; |
160 | #define iobuf bb_common_bufsiz1 | ||
161 | setup_common_bufsiz(); | ||
160 | // read from device -> write to stdout | 162 | // read from device -> write to stdout |
161 | len = safe_read(sfd, iobuf, sizeof(iobuf)); | 163 | len = safe_read(sfd, iobuf, COMMON_BUFSIZE); |
162 | if (len > 0) | 164 | if (len > 0) |
163 | full_write(STDOUT_FILENO, iobuf, len); | 165 | full_write(STDOUT_FILENO, iobuf, len); |
164 | else { | 166 | else { |
diff --git a/miscutils/setserial.c b/miscutils/setserial.c index dfed3306e..8b5c4a9c7 100644 --- a/miscutils/setserial.c +++ b/miscutils/setserial.c | |||
@@ -257,7 +257,7 @@ enum print_mode | |||
257 | #define CTL_CLOSE (1 << 3) | 257 | #define CTL_CLOSE (1 << 3) |
258 | #define CTL_NODIE (1 << 4) | 258 | #define CTL_NODIE (1 << 4) |
259 | 259 | ||
260 | static const char serial_types[] = | 260 | static const char serial_types[] ALIGN1 = |
261 | "unknown\0" /* 0 */ | 261 | "unknown\0" /* 0 */ |
262 | "8250\0" /* 1 */ | 262 | "8250\0" /* 1 */ |
263 | "16450\0" /* 2 */ | 263 | "16450\0" /* 2 */ |
@@ -288,7 +288,7 @@ static const char serial_types[] = | |||
288 | # define MAX_SERIAL_TYPE 13 | 288 | # define MAX_SERIAL_TYPE 13 |
289 | #endif | 289 | #endif |
290 | 290 | ||
291 | static const char commands[] = | 291 | static const char commands[] ALIGN1 = |
292 | "spd_normal\0" | 292 | "spd_normal\0" |
293 | "spd_hi\0" | 293 | "spd_hi\0" |
294 | "spd_vhi\0" | 294 | "spd_vhi\0" |
@@ -404,8 +404,8 @@ static const uint16_t setbits[CMD_FLAG_LAST + 1] = | |||
404 | ASYNC_LOW_LATENCY | 404 | ASYNC_LOW_LATENCY |
405 | }; | 405 | }; |
406 | 406 | ||
407 | static const char STR_INFINITE[] = "infinite"; | 407 | #define STR_INFINITE "infinite" |
408 | static const char STR_NONE[] = "none"; | 408 | #define STR_NONE "none" |
409 | 409 | ||
410 | static const char *uart_type(int type) | 410 | static const char *uart_type(int type) |
411 | { | 411 | { |
diff --git a/networking/arp.c b/networking/arp.c index 0099aa534..9381eb53a 100644 --- a/networking/arp.c +++ b/networking/arp.c | |||
@@ -32,6 +32,7 @@ | |||
32 | //usage: "\n -H HWTYPE Hardware address type" | 32 | //usage: "\n -H HWTYPE Hardware address type" |
33 | 33 | ||
34 | #include "libbb.h" | 34 | #include "libbb.h" |
35 | #include "common_bufsiz.h" | ||
35 | #include "inet_common.h" | 36 | #include "inet_common.h" |
36 | 37 | ||
37 | #include <arpa/inet.h> | 38 | #include <arpa/inet.h> |
@@ -69,12 +70,13 @@ struct globals { | |||
69 | const char *device; /* current device */ | 70 | const char *device; /* current device */ |
70 | smallint hw_set; /* flag if hw-type was set (-H) */ | 71 | smallint hw_set; /* flag if hw-type was set (-H) */ |
71 | } FIX_ALIASING; | 72 | } FIX_ALIASING; |
72 | #define G (*(struct globals*)&bb_common_bufsiz1) | 73 | #define G (*(struct globals*)bb_common_bufsiz1) |
73 | #define ap (G.ap ) | 74 | #define ap (G.ap ) |
74 | #define hw (G.hw ) | 75 | #define hw (G.hw ) |
75 | #define device (G.device ) | 76 | #define device (G.device ) |
76 | #define hw_set (G.hw_set ) | 77 | #define hw_set (G.hw_set ) |
77 | #define INIT_G() do { \ | 78 | #define INIT_G() do { \ |
79 | setup_common_bufsiz(); \ | ||
78 | device = ""; \ | 80 | device = ""; \ |
79 | } while (0) | 81 | } while (0) |
80 | 82 | ||
diff --git a/networking/arping.c b/networking/arping.c index ef205e5e6..6b0de4de2 100644 --- a/networking/arping.c +++ b/networking/arping.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <netpacket/packet.h> | 28 | #include <netpacket/packet.h> |
29 | 29 | ||
30 | #include "libbb.h" | 30 | #include "libbb.h" |
31 | #include "common_bufsiz.h" | ||
31 | 32 | ||
32 | /* We don't expect to see 1000+ seconds delay, unsigned is enough */ | 33 | /* We don't expect to see 1000+ seconds delay, unsigned is enough */ |
33 | #define MONOTONIC_US() ((unsigned)monotonic_us()) | 34 | #define MONOTONIC_US() ((unsigned)monotonic_us()) |
@@ -60,7 +61,7 @@ struct globals { | |||
60 | unsigned brd_recv; | 61 | unsigned brd_recv; |
61 | unsigned req_recv; | 62 | unsigned req_recv; |
62 | } FIX_ALIASING; | 63 | } FIX_ALIASING; |
63 | #define G (*(struct globals*)&bb_common_bufsiz1) | 64 | #define G (*(struct globals*)bb_common_bufsiz1) |
64 | #define src (G.src ) | 65 | #define src (G.src ) |
65 | #define dst (G.dst ) | 66 | #define dst (G.dst ) |
66 | #define me (G.me ) | 67 | #define me (G.me ) |
@@ -76,6 +77,7 @@ struct globals { | |||
76 | #define brd_recv (G.brd_recv ) | 77 | #define brd_recv (G.brd_recv ) |
77 | #define req_recv (G.req_recv ) | 78 | #define req_recv (G.req_recv ) |
78 | #define INIT_G() do { \ | 79 | #define INIT_G() do { \ |
80 | setup_common_bufsiz(); \ | ||
79 | count = -1; \ | 81 | count = -1; \ |
80 | } while (0) | 82 | } while (0) |
81 | 83 | ||
diff --git a/networking/ftpd.c b/networking/ftpd.c index 8345ae67c..360d1e6be 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c | |||
@@ -29,6 +29,7 @@ | |||
29 | //usage: "\n DIR Change root to this directory" | 29 | //usage: "\n DIR Change root to this directory" |
30 | 30 | ||
31 | #include "libbb.h" | 31 | #include "libbb.h" |
32 | #include "common_bufsiz.h" | ||
32 | #include <syslog.h> | 33 | #include <syslog.h> |
33 | #include <netinet/tcp.h> | 34 | #include <netinet/tcp.h> |
34 | 35 | ||
@@ -123,8 +124,9 @@ struct globals { | |||
123 | char msg_ok [(sizeof("NNN " MSG_OK ) + 3) & 0xfffc]; | 124 | char msg_ok [(sizeof("NNN " MSG_OK ) + 3) & 0xfffc]; |
124 | char msg_err[(sizeof("NNN " MSG_ERR) + 3) & 0xfffc]; | 125 | char msg_err[(sizeof("NNN " MSG_ERR) + 3) & 0xfffc]; |
125 | } FIX_ALIASING; | 126 | } FIX_ALIASING; |
126 | #define G (*(struct globals*)&bb_common_bufsiz1) | 127 | #define G (*(struct globals*)bb_common_bufsiz1) |
127 | #define INIT_G() do { \ | 128 | #define INIT_G() do { \ |
129 | setup_common_bufsiz(); \ | ||
128 | /* Moved to main */ \ | 130 | /* Moved to main */ \ |
129 | /*strcpy(G.msg_ok + 4, MSG_OK );*/ \ | 131 | /*strcpy(G.msg_ok + 4, MSG_OK );*/ \ |
130 | /*strcpy(G.msg_err + 4, MSG_ERR);*/ \ | 132 | /*strcpy(G.msg_err + 4, MSG_ERR);*/ \ |
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index 607e82713..0bfe388a8 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
@@ -50,6 +50,7 @@ | |||
50 | //usage: ) | 50 | //usage: ) |
51 | 51 | ||
52 | #include "libbb.h" | 52 | #include "libbb.h" |
53 | #include "common_bufsiz.h" | ||
53 | 54 | ||
54 | struct globals { | 55 | struct globals { |
55 | const char *user; | 56 | const char *user; |
@@ -60,7 +61,7 @@ struct globals { | |||
60 | int do_continue; | 61 | int do_continue; |
61 | char buf[4]; /* actually [BUFSZ] */ | 62 | char buf[4]; /* actually [BUFSZ] */ |
62 | } FIX_ALIASING; | 63 | } FIX_ALIASING; |
63 | #define G (*(struct globals*)&bb_common_bufsiz1) | 64 | #define G (*(struct globals*)bb_common_bufsiz1) |
64 | enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) }; | 65 | enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) }; |
65 | #define user (G.user ) | 66 | #define user (G.user ) |
66 | #define password (G.password ) | 67 | #define password (G.password ) |
@@ -70,6 +71,7 @@ enum { BUFSZ = COMMON_BUFSIZE - offsetof(struct globals, buf) }; | |||
70 | #define do_continue (G.do_continue ) | 71 | #define do_continue (G.do_continue ) |
71 | #define buf (G.buf ) | 72 | #define buf (G.buf ) |
72 | #define INIT_G() do { \ | 73 | #define INIT_G() do { \ |
74 | setup_common_bufsiz(); \ | ||
73 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 75 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
74 | } while (0) | 76 | } while (0) |
75 | 77 | ||
diff --git a/networking/httpd.c b/networking/httpd.c index ed15fd883..abe83a458 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -125,6 +125,7 @@ | |||
125 | //usage: "\n -d STRING URL decode STRING" | 125 | //usage: "\n -d STRING URL decode STRING" |
126 | 126 | ||
127 | #include "libbb.h" | 127 | #include "libbb.h" |
128 | #include "common_bufsiz.h" | ||
128 | #if ENABLE_PAM | 129 | #if ENABLE_PAM |
129 | /* PAM may include <locale.h>. We may need to undefine bbox's stub define: */ | 130 | /* PAM may include <locale.h>. We may need to undefine bbox's stub define: */ |
130 | # undef setlocale | 131 | # undef setlocale |
@@ -307,7 +308,8 @@ struct globals { | |||
307 | Htaccess *script_i; /* config script interpreters */ | 308 | Htaccess *script_i; /* config script interpreters */ |
308 | #endif | 309 | #endif |
309 | char *iobuf; /* [IOBUF_SIZE] */ | 310 | char *iobuf; /* [IOBUF_SIZE] */ |
310 | #define hdr_buf bb_common_bufsiz1 | 311 | #define hdr_buf bb_common_bufsiz1 |
312 | #define sizeof_hdr_buf COMMON_BUFSIZE | ||
311 | char *hdr_ptr; | 313 | char *hdr_ptr; |
312 | int hdr_cnt; | 314 | int hdr_cnt; |
313 | #if ENABLE_FEATURE_HTTPD_ERROR_PAGES | 315 | #if ENABLE_FEATURE_HTTPD_ERROR_PAGES |
@@ -368,6 +370,7 @@ enum { | |||
368 | # define content_gzip 0 | 370 | # define content_gzip 0 |
369 | #endif | 371 | #endif |
370 | #define INIT_G() do { \ | 372 | #define INIT_G() do { \ |
373 | setup_common_bufsiz(); \ | ||
371 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 374 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
372 | IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \ | 375 | IF_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \ |
373 | IF_FEATURE_HTTPD_RANGES(range_start = -1;) \ | 376 | IF_FEATURE_HTTPD_RANGES(range_start = -1;) \ |
@@ -1066,7 +1069,7 @@ static int get_line(void) | |||
1066 | alarm(HEADER_READ_TIMEOUT); | 1069 | alarm(HEADER_READ_TIMEOUT); |
1067 | while (1) { | 1070 | while (1) { |
1068 | if (hdr_cnt <= 0) { | 1071 | if (hdr_cnt <= 0) { |
1069 | hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof(hdr_buf)); | 1072 | hdr_cnt = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf); |
1070 | if (hdr_cnt <= 0) | 1073 | if (hdr_cnt <= 0) |
1071 | break; | 1074 | break; |
1072 | hdr_ptr = hdr_buf; | 1075 | hdr_ptr = hdr_buf; |
@@ -1191,9 +1194,9 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post | |||
1191 | /* We expect data, prev data portion is eaten by CGI | 1194 | /* We expect data, prev data portion is eaten by CGI |
1192 | * and there *is* data to read from the peer | 1195 | * and there *is* data to read from the peer |
1193 | * (POSTDATA) */ | 1196 | * (POSTDATA) */ |
1194 | //count = post_len > (int)sizeof(hdr_buf) ? (int)sizeof(hdr_buf) : post_len; | 1197 | //count = post_len > (int)sizeof_hdr_buf ? (int)sizeof_hdr_buf : post_len; |
1195 | //count = safe_read(STDIN_FILENO, hdr_buf, count); | 1198 | //count = safe_read(STDIN_FILENO, hdr_buf, count); |
1196 | count = safe_read(STDIN_FILENO, hdr_buf, sizeof(hdr_buf)); | 1199 | count = safe_read(STDIN_FILENO, hdr_buf, sizeof_hdr_buf); |
1197 | if (count > 0) { | 1200 | if (count > 0) { |
1198 | hdr_cnt = count; | 1201 | hdr_cnt = count; |
1199 | hdr_ptr = hdr_buf; | 1202 | hdr_ptr = hdr_buf; |
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 2c6db926f..25b04c9d7 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -44,6 +44,7 @@ | |||
44 | //usage: "\n -f Force de/configuration" | 44 | //usage: "\n -f Force de/configuration" |
45 | 45 | ||
46 | #include "libbb.h" | 46 | #include "libbb.h" |
47 | #include "common_bufsiz.h" | ||
47 | /* After libbb.h, since it needs sys/types.h on some systems */ | 48 | /* After libbb.h, since it needs sys/types.h on some systems */ |
48 | #include <sys/utsname.h> | 49 | #include <sys/utsname.h> |
49 | #include <fnmatch.h> | 50 | #include <fnmatch.h> |
@@ -129,8 +130,8 @@ struct globals { | |||
129 | const char *startup_PATH; | 130 | const char *startup_PATH; |
130 | char *shell; | 131 | char *shell; |
131 | } FIX_ALIASING; | 132 | } FIX_ALIASING; |
132 | #define G (*(struct globals*)&bb_common_bufsiz1) | 133 | #define G (*(struct globals*)bb_common_bufsiz1) |
133 | #define INIT_G() do { } while (0) | 134 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
134 | 135 | ||
135 | 136 | ||
136 | static const char keywords_up_down[] ALIGN1 = | 137 | static const char keywords_up_down[] ALIGN1 = |
diff --git a/networking/inetd.c b/networking/inetd.c index 4f6673b12..8d44b5198 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -170,6 +170,7 @@ | |||
170 | #include <sys/un.h> | 170 | #include <sys/un.h> |
171 | 171 | ||
172 | #include "libbb.h" | 172 | #include "libbb.h" |
173 | #include "common_bufsiz.h" | ||
173 | 174 | ||
174 | #if ENABLE_FEATURE_INETD_RPC | 175 | #if ENABLE_FEATURE_INETD_RPC |
175 | # if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_RPC__) | 176 | # if defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_RPC__) |
@@ -327,7 +328,7 @@ struct globals { | |||
327 | /* Used in next_line(), and as scratch read buffer */ | 328 | /* Used in next_line(), and as scratch read buffer */ |
328 | char line[256]; /* _at least_ 256, see LINE_SIZE */ | 329 | char line[256]; /* _at least_ 256, see LINE_SIZE */ |
329 | } FIX_ALIASING; | 330 | } FIX_ALIASING; |
330 | #define G (*(struct globals*)&bb_common_bufsiz1) | 331 | #define G (*(struct globals*)bb_common_bufsiz1) |
331 | enum { LINE_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line) }; | 332 | enum { LINE_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line) }; |
332 | #define rlim_ofile_cur (G.rlim_ofile_cur ) | 333 | #define rlim_ofile_cur (G.rlim_ofile_cur ) |
333 | #define rlim_ofile (G.rlim_ofile ) | 334 | #define rlim_ofile (G.rlim_ofile ) |
@@ -349,6 +350,7 @@ enum { LINE_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line) }; | |||
349 | #define allsock (G.allsock ) | 350 | #define allsock (G.allsock ) |
350 | #define line (G.line ) | 351 | #define line (G.line ) |
351 | #define INIT_G() do { \ | 352 | #define INIT_G() do { \ |
353 | setup_common_bufsiz(); \ | ||
352 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 354 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
353 | rlim_ofile_cur = OPEN_MAX; \ | 355 | rlim_ofile_cur = OPEN_MAX; \ |
354 | global_queuelen = 128; \ | 356 | global_queuelen = 128; \ |
diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c index 252c8aba9..8a15926e5 100644 --- a/networking/isrv_identd.c +++ b/networking/isrv_identd.c | |||
@@ -18,6 +18,7 @@ | |||
18 | //usage: "\n STRING Ident answer string (default: nobody)" | 18 | //usage: "\n STRING Ident answer string (default: nobody)" |
19 | 19 | ||
20 | #include "libbb.h" | 20 | #include "libbb.h" |
21 | #include "common_bufsiz.h" | ||
21 | #include <syslog.h> | 22 | #include <syslog.h> |
22 | #include "isrv.h" | 23 | #include "isrv.h" |
23 | 24 | ||
@@ -115,10 +116,12 @@ int fakeidentd_main(int argc UNUSED_PARAM, char **argv) | |||
115 | unsigned opt; | 116 | unsigned opt; |
116 | int fd; | 117 | int fd; |
117 | 118 | ||
119 | setup_common_bufsiz(); | ||
120 | |||
118 | opt = getopt32(argv, "fiwb:", &bind_address); | 121 | opt = getopt32(argv, "fiwb:", &bind_address); |
119 | strcpy(bogouser, "nobody"); | 122 | strcpy(bogouser, "nobody"); |
120 | if (argv[optind]) | 123 | if (argv[optind]) |
121 | strncpy(bogouser, argv[optind], sizeof(bogouser) - 1); | 124 | strncpy(bogouser, argv[optind], COMMON_BUFSIZE - 1); |
122 | 125 | ||
123 | /* Daemonize if no -f and no -i and no -w */ | 126 | /* Daemonize if no -f and no -i and no -w */ |
124 | if (!(opt & OPT_fiw)) | 127 | if (!(opt & OPT_fiw)) |
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 5c975d8c5..d9e099607 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <net/if_arp.h> | 13 | #include <net/if_arp.h> |
14 | 14 | ||
15 | #include "ip_common.h" /* #include "libbb.h" is inside */ | 15 | #include "ip_common.h" /* #include "libbb.h" is inside */ |
16 | #include "common_bufsiz.h" | ||
16 | #include "rt_names.h" | 17 | #include "rt_names.h" |
17 | #include "utils.h" | 18 | #include "utils.h" |
18 | 19 | ||
@@ -39,8 +40,8 @@ struct filter_t { | |||
39 | } FIX_ALIASING; | 40 | } FIX_ALIASING; |
40 | typedef struct filter_t filter_t; | 41 | typedef struct filter_t filter_t; |
41 | 42 | ||
42 | #define G_filter (*(filter_t*)&bb_common_bufsiz1) | 43 | #define G_filter (*(filter_t*)bb_common_bufsiz1) |
43 | 44 | #define INIT_G() do { setup_common_bufsiz(); } while (0) | |
44 | 45 | ||
45 | static void print_link_flags(unsigned flags, unsigned mdown) | 46 | static void print_link_flags(unsigned flags, unsigned mdown) |
46 | { | 47 | { |
@@ -744,6 +745,9 @@ int FAST_FUNC do_ipaddr(char **argv) | |||
744 | /* 0 1 2 3 4 5 6 7 8 */ | 745 | /* 0 1 2 3 4 5 6 7 8 */ |
745 | "add\0""change\0""chg\0""replace\0""delete\0""list\0""show\0""lst\0""flush\0"; | 746 | "add\0""change\0""chg\0""replace\0""delete\0""list\0""show\0""lst\0""flush\0"; |
746 | int cmd = 2; | 747 | int cmd = 2; |
748 | |||
749 | INIT_G(); | ||
750 | |||
747 | if (*argv) { | 751 | if (*argv) { |
748 | cmd = index_in_substrings(commands, *argv); | 752 | cmd = index_in_substrings(commands, *argv); |
749 | if (cmd < 0) | 753 | if (cmd < 0) |
diff --git a/networking/libiproute/ipneigh.c b/networking/libiproute/ipneigh.c index 179505c2d..2a1c20e20 100644 --- a/networking/libiproute/ipneigh.c +++ b/networking/libiproute/ipneigh.c | |||
@@ -8,6 +8,7 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include "ip_common.h" /* #include "libbb.h" is inside */ | 10 | #include "ip_common.h" /* #include "libbb.h" is inside */ |
11 | #include "common_bufsiz.h" | ||
11 | #include "rt_names.h" | 12 | #include "rt_names.h" |
12 | #include "utils.h" | 13 | #include "utils.h" |
13 | #include <linux/neighbour.h> | 14 | #include <linux/neighbour.h> |
@@ -40,7 +41,8 @@ struct filter_t { | |||
40 | } FIX_ALIASING; | 41 | } FIX_ALIASING; |
41 | typedef struct filter_t filter_t; | 42 | typedef struct filter_t filter_t; |
42 | 43 | ||
43 | #define G_filter (*(filter_t*)&bb_common_bufsiz1) | 44 | #define G_filter (*(filter_t*)bb_common_bufsiz1) |
45 | #define INIT_G() do { setup_common_bufsiz(); } while (0) | ||
44 | 46 | ||
45 | static int flush_update(void) | 47 | static int flush_update(void) |
46 | { | 48 | { |
@@ -60,7 +62,7 @@ static unsigned nud_state_a2n(char *arg) | |||
60 | "stale\0" "incomplete\0" "delay\0" "probe\0" | 62 | "stale\0" "incomplete\0" "delay\0" "probe\0" |
61 | "failed\0" | 63 | "failed\0" |
62 | ; | 64 | ; |
63 | static uint8_t nuds[] = { | 65 | static uint8_t nuds[] ALIGN1 = { |
64 | NUD_PERMANENT,NUD_REACHABLE, NUD_NOARP,NUD_NONE, | 66 | NUD_PERMANENT,NUD_REACHABLE, NUD_NOARP,NUD_NONE, |
65 | NUD_STALE, NUD_INCOMPLETE,NUD_DELAY,NUD_PROBE, | 67 | NUD_STALE, NUD_INCOMPLETE,NUD_DELAY,NUD_PROBE, |
66 | NUD_FAILED | 68 | NUD_FAILED |
@@ -338,6 +340,8 @@ int FAST_FUNC do_ipneigh(char **argv) | |||
338 | /*0-1*/ "show\0" "flush\0"; | 340 | /*0-1*/ "show\0" "flush\0"; |
339 | int command_num; | 341 | int command_num; |
340 | 342 | ||
343 | INIT_G(); | ||
344 | |||
341 | if (!*argv) | 345 | if (!*argv) |
342 | return ipneigh_list_or_flush(argv, 0); | 346 | return ipneigh_list_or_flush(argv, 0); |
343 | 347 | ||
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index 82827488f..e674e9a0d 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c | |||
@@ -11,6 +11,7 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include "ip_common.h" /* #include "libbb.h" is inside */ | 13 | #include "ip_common.h" /* #include "libbb.h" is inside */ |
14 | #include "common_bufsiz.h" | ||
14 | #include "rt_names.h" | 15 | #include "rt_names.h" |
15 | #include "utils.h" | 16 | #include "utils.h" |
16 | 17 | ||
@@ -43,7 +44,8 @@ struct filter_t { | |||
43 | } FIX_ALIASING; | 44 | } FIX_ALIASING; |
44 | typedef struct filter_t filter_t; | 45 | typedef struct filter_t filter_t; |
45 | 46 | ||
46 | #define G_filter (*(filter_t*)&bb_common_bufsiz1) | 47 | #define G_filter (*(filter_t*)bb_common_bufsiz1) |
48 | #define INIT_G() do { setup_common_bufsiz(); } while (0) | ||
47 | 49 | ||
48 | static int flush_update(void) | 50 | static int flush_update(void) |
49 | { | 51 | { |
@@ -902,6 +904,8 @@ int FAST_FUNC do_iproute(char **argv) | |||
902 | unsigned flags = 0; | 904 | unsigned flags = 0; |
903 | int cmd = RTM_NEWROUTE; | 905 | int cmd = RTM_NEWROUTE; |
904 | 906 | ||
907 | INIT_G(); | ||
908 | |||
905 | if (!*argv) | 909 | if (!*argv) |
906 | return iproute_list_or_flush(argv, 0); | 910 | return iproute_list_or_flush(argv, 0); |
907 | 911 | ||
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index c7533a4a7..cbb5daf95 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c | |||
@@ -71,11 +71,15 @@ int FAST_FUNC rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, in | |||
71 | struct nlmsghdr nlh; | 71 | struct nlmsghdr nlh; |
72 | struct sockaddr_nl nladdr; | 72 | struct sockaddr_nl nladdr; |
73 | struct iovec iov[2] = { { &nlh, sizeof(nlh) }, { req, len } }; | 73 | struct iovec iov[2] = { { &nlh, sizeof(nlh) }, { req, len } }; |
74 | /* Use designated initializers, struct layout is non-portable */ | ||
74 | struct msghdr msg = { | 75 | struct msghdr msg = { |
75 | (void*)&nladdr, sizeof(nladdr), | 76 | .msg_name = (void*)&nladdr, |
76 | iov, 2, | 77 | .msg_namelen = sizeof(nladdr), |
77 | NULL, 0, | 78 | .msg_iov = iov, |
78 | 0 | 79 | .msg_iovlen = 2, |
80 | .msg_control = NULL, | ||
81 | .msg_controllen = 0, | ||
82 | .msg_flags = 0 | ||
79 | }; | 83 | }; |
80 | 84 | ||
81 | memset(&nladdr, 0, sizeof(nladdr)); | 85 | memset(&nladdr, 0, sizeof(nladdr)); |
@@ -104,12 +108,15 @@ static int rtnl_dump_filter(struct rtnl_handle *rth, | |||
104 | while (1) { | 108 | while (1) { |
105 | int status; | 109 | int status; |
106 | struct nlmsghdr *h; | 110 | struct nlmsghdr *h; |
107 | 111 | /* Use designated initializers, struct layout is non-portable */ | |
108 | struct msghdr msg = { | 112 | struct msghdr msg = { |
109 | (void*)&nladdr, sizeof(nladdr), | 113 | .msg_name = (void*)&nladdr, |
110 | &iov, 1, | 114 | .msg_namelen = sizeof(nladdr), |
111 | NULL, 0, | 115 | .msg_iov = &iov, |
112 | 0 | 116 | .msg_iovlen = 1, |
117 | .msg_control = NULL, | ||
118 | .msg_controllen = 0, | ||
119 | .msg_flags = 0 | ||
113 | }; | 120 | }; |
114 | 121 | ||
115 | status = recvmsg(rth->fd, &msg, 0); | 122 | status = recvmsg(rth->fd, &msg, 0); |
@@ -211,11 +218,15 @@ int FAST_FUNC rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, | |||
211 | struct sockaddr_nl nladdr; | 218 | struct sockaddr_nl nladdr; |
212 | struct iovec iov = { (void*)n, n->nlmsg_len }; | 219 | struct iovec iov = { (void*)n, n->nlmsg_len }; |
213 | char *buf = xmalloc(8*1024); /* avoid big stack buffer */ | 220 | char *buf = xmalloc(8*1024); /* avoid big stack buffer */ |
221 | /* Use designated initializers, struct layout is non-portable */ | ||
214 | struct msghdr msg = { | 222 | struct msghdr msg = { |
215 | (void*)&nladdr, sizeof(nladdr), | 223 | .msg_name = (void*)&nladdr, |
216 | &iov, 1, | 224 | .msg_namelen = sizeof(nladdr), |
217 | NULL, 0, | 225 | .msg_iov = &iov, |
218 | 0 | 226 | .msg_iovlen = 1, |
227 | .msg_control = NULL, | ||
228 | .msg_controllen = 0, | ||
229 | .msg_flags = 0 | ||
219 | }; | 230 | }; |
220 | 231 | ||
221 | memset(&nladdr, 0, sizeof(nladdr)); | 232 | memset(&nladdr, 0, sizeof(nladdr)); |
diff --git a/networking/libiproute/ll_proto.c b/networking/libiproute/ll_proto.c index da2b53cbf..4c32ae574 100644 --- a/networking/libiproute/ll_proto.c +++ b/networking/libiproute/ll_proto.c | |||
@@ -84,7 +84,7 @@ ETH_P_IP | |||
84 | 84 | ||
85 | /* Keep declarations above and below in sync! */ | 85 | /* Keep declarations above and below in sync! */ |
86 | 86 | ||
87 | static const char llproto_names[] = | 87 | static const char llproto_names[] ALIGN1 = |
88 | #define __PF(f,n) #n "\0" | 88 | #define __PF(f,n) #n "\0" |
89 | __PF(LOOP,loop) | 89 | __PF(LOOP,loop) |
90 | __PF(PUP,pup) | 90 | __PF(PUP,pup) |
diff --git a/networking/libiproute/ll_types.c b/networking/libiproute/ll_types.c index bb42e269e..62ee0cc54 100644 --- a/networking/libiproute/ll_types.c +++ b/networking/libiproute/ll_types.c | |||
@@ -16,7 +16,7 @@ | |||
16 | 16 | ||
17 | const char* FAST_FUNC ll_type_n2a(int type, char *buf) | 17 | const char* FAST_FUNC ll_type_n2a(int type, char *buf) |
18 | { | 18 | { |
19 | static const char arphrd_name[] = | 19 | static const char arphrd_name[] ALIGN1 = |
20 | /* 0, */ "generic" "\0" | 20 | /* 0, */ "generic" "\0" |
21 | /* ARPHRD_LOOPBACK, */ "loopback" "\0" | 21 | /* ARPHRD_LOOPBACK, */ "loopback" "\0" |
22 | /* ARPHRD_ETHER, */ "ether" "\0" | 22 | /* ARPHRD_ETHER, */ "ether" "\0" |
@@ -105,7 +105,7 @@ const char* FAST_FUNC ll_type_n2a(int type, char *buf) | |||
105 | 105 | ||
106 | /* Keep these arrays in sync! */ | 106 | /* Keep these arrays in sync! */ |
107 | 107 | ||
108 | static const uint16_t arphrd_type[] = { | 108 | static const uint16_t arphrd_type[] ALIGN2 = { |
109 | 0, /* "generic" "\0" */ | 109 | 0, /* "generic" "\0" */ |
110 | ARPHRD_LOOPBACK, /* "loopback" "\0" */ | 110 | ARPHRD_LOOPBACK, /* "loopback" "\0" */ |
111 | ARPHRD_ETHER, /* "ether" "\0" */ | 111 | ARPHRD_ETHER, /* "ether" "\0" */ |
diff --git a/networking/nc.c b/networking/nc.c index 2f9e17466..13a9b48a8 100644 --- a/networking/nc.c +++ b/networking/nc.c | |||
@@ -8,6 +8,7 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | #include "common_bufsiz.h" | ||
11 | 12 | ||
12 | //config:config NC | 13 | //config:config NC |
13 | //config: bool "nc" | 14 | //config: bool "nc" |
@@ -238,6 +239,8 @@ int nc_main(int argc, char **argv) | |||
238 | FD_SET(cfd, &readfds); | 239 | FD_SET(cfd, &readfds); |
239 | FD_SET(STDIN_FILENO, &readfds); | 240 | FD_SET(STDIN_FILENO, &readfds); |
240 | 241 | ||
242 | #define iobuf bb_common_bufsiz1 | ||
243 | setup_common_bufsiz(); | ||
241 | for (;;) { | 244 | for (;;) { |
242 | int fd; | 245 | int fd; |
243 | int ofd; | 246 | int ofd; |
@@ -248,11 +251,10 @@ int nc_main(int argc, char **argv) | |||
248 | if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0) | 251 | if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0) |
249 | bb_perror_msg_and_die("select"); | 252 | bb_perror_msg_and_die("select"); |
250 | 253 | ||
251 | #define iobuf bb_common_bufsiz1 | ||
252 | fd = STDIN_FILENO; | 254 | fd = STDIN_FILENO; |
253 | while (1) { | 255 | while (1) { |
254 | if (FD_ISSET(fd, &testfds)) { | 256 | if (FD_ISSET(fd, &testfds)) { |
255 | nread = safe_read(fd, iobuf, sizeof(iobuf)); | 257 | nread = safe_read(fd, iobuf, COMMON_BUFSIZE); |
256 | if (fd == cfd) { | 258 | if (fd == cfd) { |
257 | if (nread < 1) | 259 | if (nread < 1) |
258 | exit(EXIT_SUCCESS); | 260 | exit(EXIT_SUCCESS); |
diff --git a/networking/ping.c b/networking/ping.c index 0eb1ae799..cfe682646 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <net/if.h> | 28 | #include <net/if.h> |
29 | #include <netinet/ip_icmp.h> | 29 | #include <netinet/ip_icmp.h> |
30 | #include "libbb.h" | 30 | #include "libbb.h" |
31 | #include "common_bufsiz.h" | ||
31 | 32 | ||
32 | #ifdef __BIONIC__ | 33 | #ifdef __BIONIC__ |
33 | /* should be in netinet/ip_icmp.h */ | 34 | /* should be in netinet/ip_icmp.h */ |
@@ -186,8 +187,8 @@ struct globals { | |||
186 | char *hostname; | 187 | char *hostname; |
187 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; | 188 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; |
188 | } FIX_ALIASING; | 189 | } FIX_ALIASING; |
189 | #define G (*(struct globals*)&bb_common_bufsiz1) | 190 | #define G (*(struct globals*)bb_common_bufsiz1) |
190 | #define INIT_G() do { } while (0) | 191 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
191 | 192 | ||
192 | static void noresp(int ign UNUSED_PARAM) | 193 | static void noresp(int ign UNUSED_PARAM) |
193 | { | 194 | { |
@@ -378,7 +379,7 @@ struct globals { | |||
378 | } pingaddr; | 379 | } pingaddr; |
379 | unsigned char rcvd_tbl[MAX_DUP_CHK / 8]; | 380 | unsigned char rcvd_tbl[MAX_DUP_CHK / 8]; |
380 | } FIX_ALIASING; | 381 | } FIX_ALIASING; |
381 | #define G (*(struct globals*)&bb_common_bufsiz1) | 382 | #define G (*(struct globals*)bb_common_bufsiz1) |
382 | #define if_index (G.if_index ) | 383 | #define if_index (G.if_index ) |
383 | #define source_lsa (G.source_lsa ) | 384 | #define source_lsa (G.source_lsa ) |
384 | #define str_I (G.str_I ) | 385 | #define str_I (G.str_I ) |
@@ -397,6 +398,7 @@ struct globals { | |||
397 | #define pingaddr (G.pingaddr ) | 398 | #define pingaddr (G.pingaddr ) |
398 | #define rcvd_tbl (G.rcvd_tbl ) | 399 | #define rcvd_tbl (G.rcvd_tbl ) |
399 | #define INIT_G() do { \ | 400 | #define INIT_G() do { \ |
401 | setup_common_bufsiz(); \ | ||
400 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 402 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
401 | datalen = DEFDATALEN; \ | 403 | datalen = DEFDATALEN; \ |
402 | timeout = MAXWAIT; \ | 404 | timeout = MAXWAIT; \ |
diff --git a/networking/slattach.c b/networking/slattach.c index 14e0c1941..2d1305e32 100644 --- a/networking/slattach.c +++ b/networking/slattach.c | |||
@@ -27,6 +27,7 @@ | |||
27 | //usage: "\n -F Disable RTS/CTS flow control" | 27 | //usage: "\n -F Disable RTS/CTS flow control" |
28 | 28 | ||
29 | #include "libbb.h" | 29 | #include "libbb.h" |
30 | #include "common_bufsiz.h" | ||
30 | #include "libiproute/utils.h" /* invarg_1_to_2() */ | 31 | #include "libiproute/utils.h" /* invarg_1_to_2() */ |
31 | 32 | ||
32 | struct globals { | 33 | struct globals { |
@@ -34,11 +35,11 @@ struct globals { | |||
34 | int saved_disc; | 35 | int saved_disc; |
35 | struct termios saved_state; | 36 | struct termios saved_state; |
36 | } FIX_ALIASING; | 37 | } FIX_ALIASING; |
37 | #define G (*(struct globals*)&bb_common_bufsiz1) | 38 | #define G (*(struct globals*)bb_common_bufsiz1) |
38 | #define handle (G.handle ) | 39 | #define handle (G.handle ) |
39 | #define saved_disc (G.saved_disc ) | 40 | #define saved_disc (G.saved_disc ) |
40 | #define saved_state (G.saved_state ) | 41 | #define saved_state (G.saved_state ) |
41 | #define INIT_G() do { } while (0) | 42 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
42 | 43 | ||
43 | 44 | ||
44 | /* | 45 | /* |
diff --git a/networking/tc.c b/networking/tc.c index c84c18a67..d0bcbdeaa 100644 --- a/networking/tc.c +++ b/networking/tc.c | |||
@@ -29,6 +29,7 @@ | |||
29 | //usage: "filter show [ dev STRING ] [ root | parent CLASSID ]" | 29 | //usage: "filter show [ dev STRING ] [ root | parent CLASSID ]" |
30 | 30 | ||
31 | #include "libbb.h" | 31 | #include "libbb.h" |
32 | #include "common_bufsiz.h" | ||
32 | 33 | ||
33 | #include "libiproute/utils.h" | 34 | #include "libiproute/utils.h" |
34 | #include "libiproute/ip_common.h" | 35 | #include "libiproute/ip_common.h" |
@@ -63,13 +64,14 @@ struct globals { | |||
63 | uint32_t filter_prio; | 64 | uint32_t filter_prio; |
64 | uint32_t filter_proto; | 65 | uint32_t filter_proto; |
65 | } FIX_ALIASING; | 66 | } FIX_ALIASING; |
66 | #define G (*(struct globals*)&bb_common_bufsiz1) | 67 | #define G (*(struct globals*)bb_common_bufsiz1) |
67 | #define filter_ifindex (G.filter_ifindex) | 68 | #define filter_ifindex (G.filter_ifindex) |
68 | #define filter_qdisc (G.filter_qdisc) | 69 | #define filter_qdisc (G.filter_qdisc) |
69 | #define filter_parent (G.filter_parent) | 70 | #define filter_parent (G.filter_parent) |
70 | #define filter_prio (G.filter_prio) | 71 | #define filter_prio (G.filter_prio) |
71 | #define filter_proto (G.filter_proto) | 72 | #define filter_proto (G.filter_proto) |
72 | #define INIT_G() do { \ | 73 | #define INIT_G() do { \ |
74 | setup_common_bufsiz(); \ | ||
73 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 75 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
74 | } while (0) | 76 | } while (0) |
75 | 77 | ||
diff --git a/networking/tcpudp.c b/networking/tcpudp.c index 3df6a98d8..31bc70459 100644 --- a/networking/tcpudp.c +++ b/networking/tcpudp.c | |||
@@ -67,6 +67,7 @@ | |||
67 | //usage: "\n -v Verbose" | 67 | //usage: "\n -v Verbose" |
68 | 68 | ||
69 | #include "libbb.h" | 69 | #include "libbb.h" |
70 | #include "common_bufsiz.h" | ||
70 | 71 | ||
71 | /* Wants <limits.h> etc, thus included after libbb.h: */ | 72 | /* Wants <limits.h> etc, thus included after libbb.h: */ |
72 | #ifdef __linux__ | 73 | #ifdef __linux__ |
@@ -91,7 +92,7 @@ struct globals { | |||
91 | char **env_cur; | 92 | char **env_cur; |
92 | char *env_var[1]; /* actually bigger */ | 93 | char *env_var[1]; /* actually bigger */ |
93 | } FIX_ALIASING; | 94 | } FIX_ALIASING; |
94 | #define G (*(struct globals*)&bb_common_bufsiz1) | 95 | #define G (*(struct globals*)bb_common_bufsiz1) |
95 | #define verbose (G.verbose ) | 96 | #define verbose (G.verbose ) |
96 | #define max_per_host (G.max_per_host) | 97 | #define max_per_host (G.max_per_host) |
97 | #define cur_per_host (G.cur_per_host) | 98 | #define cur_per_host (G.cur_per_host) |
@@ -100,6 +101,7 @@ struct globals { | |||
100 | #define env_cur (G.env_cur ) | 101 | #define env_cur (G.env_cur ) |
101 | #define env_var (G.env_var ) | 102 | #define env_var (G.env_var ) |
102 | #define INIT_G() do { \ | 103 | #define INIT_G() do { \ |
104 | setup_common_bufsiz(); \ | ||
103 | cmax = 30; \ | 105 | cmax = 30; \ |
104 | env_cur = &env_var[0]; \ | 106 | env_cur = &env_var[0]; \ |
105 | } while (0) | 107 | } while (0) |
diff --git a/networking/telnet.c b/networking/telnet.c index 944cf1bd6..d2daf5c8c 100644 --- a/networking/telnet.c +++ b/networking/telnet.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #include <arpa/telnet.h> | 39 | #include <arpa/telnet.h> |
40 | #include <netinet/in.h> | 40 | #include <netinet/in.h> |
41 | #include "libbb.h" | 41 | #include "libbb.h" |
42 | #include "common_bufsiz.h" | ||
42 | 43 | ||
43 | #ifdef __BIONIC__ | 44 | #ifdef __BIONIC__ |
44 | /* should be in arpa/telnet.h */ | 45 | /* should be in arpa/telnet.h */ |
@@ -108,8 +109,9 @@ struct globals { | |||
108 | struct termios termios_def; | 109 | struct termios termios_def; |
109 | struct termios termios_raw; | 110 | struct termios termios_raw; |
110 | } FIX_ALIASING; | 111 | } FIX_ALIASING; |
111 | #define G (*(struct globals*)&bb_common_bufsiz1) | 112 | #define G (*(struct globals*)bb_common_bufsiz1) |
112 | #define INIT_G() do { \ | 113 | #define INIT_G() do { \ |
114 | setup_common_bufsiz(); \ | ||
113 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 115 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
114 | } while (0) | 116 | } while (0) |
115 | 117 | ||
diff --git a/networking/telnetd.c b/networking/telnetd.c index 25d05fe7a..13c36aa46 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -44,6 +44,7 @@ | |||
44 | #define DEBUG 0 | 44 | #define DEBUG 0 |
45 | 45 | ||
46 | #include "libbb.h" | 46 | #include "libbb.h" |
47 | #include "common_bufsiz.h" | ||
47 | #include <syslog.h> | 48 | #include <syslog.h> |
48 | 49 | ||
49 | #if DEBUG | 50 | #if DEBUG |
@@ -82,8 +83,9 @@ struct globals { | |||
82 | const char *issuefile; | 83 | const char *issuefile; |
83 | int maxfd; | 84 | int maxfd; |
84 | } FIX_ALIASING; | 85 | } FIX_ALIASING; |
85 | #define G (*(struct globals*)&bb_common_bufsiz1) | 86 | #define G (*(struct globals*)bb_common_bufsiz1) |
86 | #define INIT_G() do { \ | 87 | #define INIT_G() do { \ |
88 | setup_common_bufsiz(); \ | ||
87 | G.loginpath = "/bin/login"; \ | 89 | G.loginpath = "/bin/login"; \ |
88 | G.issuefile = "/etc/issue.net"; \ | 90 | G.issuefile = "/etc/issue.net"; \ |
89 | } while (0) | 91 | } while (0) |
diff --git a/networking/telnetd.ctrlSQ.patch b/networking/telnetd.ctrlSQ.patch index 7060e1c6e..bc26d2279 100644 --- a/networking/telnetd.ctrlSQ.patch +++ b/networking/telnetd.ctrlSQ.patch | |||
@@ -94,9 +94,9 @@ exceptional conditions. | |||
94 | #endif | 94 | #endif |
95 | +#ifdef TIOCPKT | 95 | +#ifdef TIOCPKT |
96 | + int control; | 96 | + int control; |
97 | + static const char lflow_on[] = | 97 | + static const char lflow_on[] ALIGN1 = |
98 | + {IAC, SB, TELOPT_LFLOW, LFLOW_ON, IAC, SE}; | 98 | + {IAC, SB, TELOPT_LFLOW, LFLOW_ON, IAC, SE}; |
99 | + static const char lflow_off[] = | 99 | + static const char lflow_off[] ALIGN1 = |
100 | + {IAC, SB, TELOPT_LFLOW, LFLOW_OFF, IAC, SE}; | 100 | + {IAC, SB, TELOPT_LFLOW, LFLOW_OFF, IAC, SE}; |
101 | +# define RESERVED sizeof(lflow_on) | 101 | +# define RESERVED sizeof(lflow_on) |
102 | +#else | 102 | +#else |
diff --git a/networking/tftp.c b/networking/tftp.c index ad9308e52..e879c4674 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -51,6 +51,7 @@ | |||
51 | //usage: "\n -l Log to syslog (inetd mode requires this)" | 51 | //usage: "\n -l Log to syslog (inetd mode requires this)" |
52 | 52 | ||
53 | #include "libbb.h" | 53 | #include "libbb.h" |
54 | #include "common_bufsiz.h" | ||
54 | #include <syslog.h> | 55 | #include <syslog.h> |
55 | 56 | ||
56 | #if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT | 57 | #if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT |
@@ -128,8 +129,9 @@ struct globals { | |||
128 | bb_progress_t pmt; | 129 | bb_progress_t pmt; |
129 | #endif | 130 | #endif |
130 | } FIX_ALIASING; | 131 | } FIX_ALIASING; |
131 | #define G (*(struct globals*)&bb_common_bufsiz1) | 132 | #define G (*(struct globals*)bb_common_bufsiz1) |
132 | #define INIT_G() do { \ | 133 | #define INIT_G() do { \ |
134 | setup_common_bufsiz(); \ | ||
133 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 135 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
134 | } while (0) | 136 | } while (0) |
135 | 137 | ||
@@ -757,7 +759,8 @@ int tftpd_main(int argc UNUSED_PARAM, char **argv) | |||
757 | { | 759 | { |
758 | len_and_sockaddr *our_lsa; | 760 | len_and_sockaddr *our_lsa; |
759 | len_and_sockaddr *peer_lsa; | 761 | len_and_sockaddr *peer_lsa; |
760 | char *local_file, *mode, *user_opt; | 762 | char *mode, *user_opt; |
763 | char *local_file = local_file; | ||
761 | const char *error_msg; | 764 | const char *error_msg; |
762 | int opt, result, opcode; | 765 | int opt, result, opcode; |
763 | IF_FEATURE_TFTP_BLOCKSIZE(int blksize = TFTP_BLKSIZE_DEFAULT;) | 766 | IF_FEATURE_TFTP_BLOCKSIZE(int blksize = TFTP_BLKSIZE_DEFAULT;) |
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 496ab11a1..a526494d7 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h | |||
@@ -9,6 +9,7 @@ | |||
9 | #define UDHCP_COMMON_H 1 | 9 | #define UDHCP_COMMON_H 1 |
10 | 10 | ||
11 | #include "libbb.h" | 11 | #include "libbb.h" |
12 | #include "common_bufsiz.h" | ||
12 | #include <netinet/udp.h> | 13 | #include <netinet/udp.h> |
13 | #include <netinet/ip.h> | 14 | #include <netinet/ip.h> |
14 | 15 | ||
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 422254d62..c77669a31 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c | |||
@@ -930,6 +930,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
930 | int retval; | 930 | int retval; |
931 | fd_set rfds; | 931 | fd_set rfds; |
932 | 932 | ||
933 | setup_common_bufsiz(); | ||
934 | |||
933 | /* Default options */ | 935 | /* Default options */ |
934 | IF_FEATURE_UDHCP_PORT(SERVER_PORT6 = 547;) | 936 | IF_FEATURE_UDHCP_PORT(SERVER_PORT6 = 547;) |
935 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT6 = 546;) | 937 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT6 = 546;) |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 660b943ce..fc7b6216d 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -109,7 +109,7 @@ enum { | |||
109 | /*** Script execution code ***/ | 109 | /*** Script execution code ***/ |
110 | 110 | ||
111 | /* get a rough idea of how long an option will be (rounding up...) */ | 111 | /* get a rough idea of how long an option will be (rounding up...) */ |
112 | static const uint8_t len_of_option_as_string[] = { | 112 | static const uint8_t len_of_option_as_string[] ALIGN1 = { |
113 | [OPTION_IP ] = sizeof("255.255.255.255 "), | 113 | [OPTION_IP ] = sizeof("255.255.255.255 "), |
114 | [OPTION_IP_PAIR ] = sizeof("255.255.255.255 ") * 2, | 114 | [OPTION_IP_PAIR ] = sizeof("255.255.255.255 ") * 2, |
115 | [OPTION_STATIC_ROUTES ] = sizeof("255.255.255.255/32 255.255.255.255 "), | 115 | [OPTION_STATIC_ROUTES ] = sizeof("255.255.255.255/32 255.255.255.255 "), |
@@ -1268,6 +1268,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1268 | int retval; | 1268 | int retval; |
1269 | fd_set rfds; | 1269 | fd_set rfds; |
1270 | 1270 | ||
1271 | setup_common_bufsiz(); | ||
1272 | |||
1271 | /* Default options */ | 1273 | /* Default options */ |
1272 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) | 1274 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) |
1273 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) | 1275 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) |
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 2671ea3e2..e93a9f1da 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -310,10 +310,10 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
310 | unsigned arpping_ms; | 310 | unsigned arpping_ms; |
311 | IF_FEATURE_UDHCP_PORT(char *str_P;) | 311 | IF_FEATURE_UDHCP_PORT(char *str_P;) |
312 | 312 | ||
313 | #if ENABLE_FEATURE_UDHCP_PORT | 313 | setup_common_bufsiz(); |
314 | SERVER_PORT = 67; | 314 | |
315 | CLIENT_PORT = 68; | 315 | IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) |
316 | #endif | 316 | IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) |
317 | 317 | ||
318 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 | 318 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1 |
319 | opt_complementary = "vv"; | 319 | opt_complementary = "vv"; |
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h index 183e7e24c..9dd5bef9e 100644 --- a/networking/udhcp/dhcpd.h +++ b/networking/udhcp/dhcpd.h | |||
@@ -57,7 +57,7 @@ struct server_config_t { | |||
57 | struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */ | 57 | struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */ |
58 | } FIX_ALIASING; | 58 | } FIX_ALIASING; |
59 | 59 | ||
60 | #define server_config (*(struct server_config_t*)&bb_common_bufsiz1) | 60 | #define server_config (*(struct server_config_t*)bb_common_bufsiz1) |
61 | /* client_config sits in 2nd half of bb_common_bufsiz1 */ | 61 | /* client_config sits in 2nd half of bb_common_bufsiz1 */ |
62 | 62 | ||
63 | #if ENABLE_FEATURE_UDHCP_PORT | 63 | #if ENABLE_FEATURE_UDHCP_PORT |
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c index f82ac05b4..f52a0cf88 100644 --- a/networking/udhcp/dhcprelay.c +++ b/networking/udhcp/dhcprelay.c | |||
@@ -33,7 +33,8 @@ struct xid_item { | |||
33 | struct xid_item *next; | 33 | struct xid_item *next; |
34 | } FIX_ALIASING; | 34 | } FIX_ALIASING; |
35 | 35 | ||
36 | #define dhcprelay_xid_list (*(struct xid_item*)&bb_common_bufsiz1) | 36 | #define dhcprelay_xid_list (*(struct xid_item*)bb_common_bufsiz1) |
37 | #define INIT_G() do { setup_common_bufsiz(); } while (0) | ||
37 | 38 | ||
38 | static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client) | 39 | static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client) |
39 | { | 40 | { |
@@ -257,6 +258,8 @@ int dhcprelay_main(int argc, char **argv) | |||
257 | int num_sockets, max_socket; | 258 | int num_sockets, max_socket; |
258 | uint32_t our_nip; | 259 | uint32_t our_nip; |
259 | 260 | ||
261 | INIT_G(); | ||
262 | |||
260 | server_addr.sin_family = AF_INET; | 263 | server_addr.sin_family = AF_INET; |
261 | server_addr.sin_addr.s_addr = htonl(INADDR_BROADCAST); | 264 | server_addr.sin_addr.s_addr = htonl(INADDR_BROADCAST); |
262 | server_addr.sin_port = htons(SERVER_PORT); | 265 | server_addr.sin_port = htons(SERVER_PORT); |
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index 7b57c6258..b22425352 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c | |||
@@ -57,33 +57,35 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg) | |||
57 | struct config_keyword { | 57 | struct config_keyword { |
58 | const char *keyword; | 58 | const char *keyword; |
59 | int (*handler)(const char *line, void *var) FAST_FUNC; | 59 | int (*handler)(const char *line, void *var) FAST_FUNC; |
60 | void *var; | 60 | unsigned ofs; |
61 | const char *def; | 61 | const char *def; |
62 | }; | 62 | }; |
63 | 63 | ||
64 | #define OFS(field) offsetof(struct server_config_t, field) | ||
65 | |||
64 | static const struct config_keyword keywords[] = { | 66 | static const struct config_keyword keywords[] = { |
65 | /* keyword handler variable address default */ | 67 | /* keyword handler variable address default */ |
66 | {"start" , udhcp_str2nip , &server_config.start_ip , "192.168.0.20"}, | 68 | {"start" , udhcp_str2nip , OFS(start_ip ), "192.168.0.20"}, |
67 | {"end" , udhcp_str2nip , &server_config.end_ip , "192.168.0.254"}, | 69 | {"end" , udhcp_str2nip , OFS(end_ip ), "192.168.0.254"}, |
68 | {"interface" , read_str , &server_config.interface , "eth0"}, | 70 | {"interface" , read_str , OFS(interface ), "eth0"}, |
69 | /* Avoid "max_leases value not sane" warning by setting default | 71 | /* Avoid "max_leases value not sane" warning by setting default |
70 | * to default_end_ip - default_start_ip + 1: */ | 72 | * to default_end_ip - default_start_ip + 1: */ |
71 | {"max_leases" , read_u32 , &server_config.max_leases , "235"}, | 73 | {"max_leases" , read_u32 , OFS(max_leases ), "235"}, |
72 | {"auto_time" , read_u32 , &server_config.auto_time , "7200"}, | 74 | {"auto_time" , read_u32 , OFS(auto_time ), "7200"}, |
73 | {"decline_time" , read_u32 , &server_config.decline_time , "3600"}, | 75 | {"decline_time" , read_u32 , OFS(decline_time ), "3600"}, |
74 | {"conflict_time", read_u32 , &server_config.conflict_time, "3600"}, | 76 | {"conflict_time", read_u32 , OFS(conflict_time), "3600"}, |
75 | {"offer_time" , read_u32 , &server_config.offer_time , "60"}, | 77 | {"offer_time" , read_u32 , OFS(offer_time ), "60"}, |
76 | {"min_lease" , read_u32 , &server_config.min_lease_sec, "60"}, | 78 | {"min_lease" , read_u32 , OFS(min_lease_sec), "60"}, |
77 | {"lease_file" , read_str , &server_config.lease_file , LEASES_FILE}, | 79 | {"lease_file" , read_str , OFS(lease_file ), LEASES_FILE}, |
78 | {"pidfile" , read_str , &server_config.pidfile , "/var/run/udhcpd.pid"}, | 80 | {"pidfile" , read_str , OFS(pidfile ), "/var/run/udhcpd.pid"}, |
79 | {"siaddr" , udhcp_str2nip , &server_config.siaddr_nip , "0.0.0.0"}, | 81 | {"siaddr" , udhcp_str2nip , OFS(siaddr_nip ), "0.0.0.0"}, |
80 | /* keywords with no defaults must be last! */ | 82 | /* keywords with no defaults must be last! */ |
81 | {"option" , udhcp_str2optset, &server_config.options , ""}, | 83 | {"option" , udhcp_str2optset, OFS(options ), ""}, |
82 | {"opt" , udhcp_str2optset, &server_config.options , ""}, | 84 | {"opt" , udhcp_str2optset, OFS(options ), ""}, |
83 | {"notify_file" , read_str , &server_config.notify_file , NULL}, | 85 | {"notify_file" , read_str , OFS(notify_file ), NULL}, |
84 | {"sname" , read_str , &server_config.sname , NULL}, | 86 | {"sname" , read_str , OFS(sname ), NULL}, |
85 | {"boot_file" , read_str , &server_config.boot_file , NULL}, | 87 | {"boot_file" , read_str , OFS(boot_file ), NULL}, |
86 | {"static_lease" , read_staticlease, &server_config.static_leases, ""}, | 88 | {"static_lease" , read_staticlease, OFS(static_leases), ""}, |
87 | }; | 89 | }; |
88 | enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 }; | 90 | enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 }; |
89 | 91 | ||
@@ -95,17 +97,17 @@ void FAST_FUNC read_config(const char *file) | |||
95 | char *token[2]; | 97 | char *token[2]; |
96 | 98 | ||
97 | for (i = 0; i < KWS_WITH_DEFAULTS; i++) | 99 | for (i = 0; i < KWS_WITH_DEFAULTS; i++) |
98 | keywords[i].handler(keywords[i].def, keywords[i].var); | 100 | keywords[i].handler(keywords[i].def, (char*)&server_config + keywords[i].ofs); |
99 | 101 | ||
100 | parser = config_open(file); | 102 | parser = config_open(file); |
101 | while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { | 103 | while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { |
102 | for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) { | 104 | for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) { |
103 | if (strcasecmp(token[0], k->keyword) == 0) { | 105 | if (strcasecmp(token[0], k->keyword) == 0) { |
104 | if (!k->handler(token[1], k->var)) { | 106 | if (!k->handler(token[1], (char*)&server_config + k->ofs)) { |
105 | bb_error_msg("can't parse line %u in %s", | 107 | bb_error_msg("can't parse line %u in %s", |
106 | parser->lineno, file); | 108 | parser->lineno, file); |
107 | /* reset back to the default value */ | 109 | /* reset back to the default value */ |
108 | k->handler(k->def, k->var); | 110 | k->handler(k->def, (char*)&server_config + k->ofs); |
109 | } | 111 | } |
110 | break; | 112 | break; |
111 | } | 113 | } |
diff --git a/networking/wget.c b/networking/wget.c index 87d3bbd13..c725edb5b 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -146,10 +146,10 @@ struct host_info { | |||
146 | char *host; | 146 | char *host; |
147 | int port; | 147 | int port; |
148 | }; | 148 | }; |
149 | static const char P_FTP[] = "ftp"; | 149 | static const char P_FTP[] ALIGN1 = "ftp"; |
150 | static const char P_HTTP[] = "http"; | 150 | static const char P_HTTP[] ALIGN1 = "http"; |
151 | #if ENABLE_FEATURE_WGET_OPENSSL || ENABLE_FEATURE_WGET_SSL_HELPER | 151 | #if ENABLE_FEATURE_WGET_OPENSSL || ENABLE_FEATURE_WGET_SSL_HELPER |
152 | static const char P_HTTPS[] = "https"; | 152 | static const char P_HTTPS[] ALIGN1 = "https"; |
153 | #endif | 153 | #endif |
154 | 154 | ||
155 | #if ENABLE_FEATURE_WGET_LONG_OPTIONS | 155 | #if ENABLE_FEATURE_WGET_LONG_OPTIONS |
diff --git a/networking/zcip.c b/networking/zcip.c index c93082619..47f3216a0 100644 --- a/networking/zcip.c +++ b/networking/zcip.c | |||
@@ -40,6 +40,7 @@ | |||
40 | //usage: "\nexits only on I/O errors (link down etc)" | 40 | //usage: "\nexits only on I/O errors (link down etc)" |
41 | 41 | ||
42 | #include "libbb.h" | 42 | #include "libbb.h" |
43 | #include "common_bufsiz.h" | ||
43 | #include <netinet/ether.h> | 44 | #include <netinet/ether.h> |
44 | #include <net/if.h> | 45 | #include <net/if.h> |
45 | #include <net/if_arp.h> | 46 | #include <net/if_arp.h> |
@@ -90,8 +91,8 @@ struct globals { | |||
90 | struct ether_addr our_ethaddr; | 91 | struct ether_addr our_ethaddr; |
91 | uint32_t localnet_ip; | 92 | uint32_t localnet_ip; |
92 | } FIX_ALIASING; | 93 | } FIX_ALIASING; |
93 | #define G (*(struct globals*)&bb_common_bufsiz1) | 94 | #define G (*(struct globals*)bb_common_bufsiz1) |
94 | #define INIT_G() do { } while (0) | 95 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
95 | 96 | ||
96 | 97 | ||
97 | /** | 98 | /** |
diff --git a/procps/free.c b/procps/free.c index 0d023f740..fca9a2242 100644 --- a/procps/free.c +++ b/procps/free.c | |||
@@ -22,6 +22,7 @@ | |||
22 | //usage: "Total: 386144 257128 129016\n" | 22 | //usage: "Total: 386144 257128 129016\n" |
23 | 23 | ||
24 | #include "libbb.h" | 24 | #include "libbb.h" |
25 | #include "common_bufsiz.h" | ||
25 | #ifdef __linux__ | 26 | #ifdef __linux__ |
26 | # include <sys/sysinfo.h> | 27 | # include <sys/sysinfo.h> |
27 | #endif | 28 | #endif |
@@ -35,8 +36,8 @@ struct globals { | |||
35 | # define G_unit_steps 10 | 36 | # define G_unit_steps 10 |
36 | #endif | 37 | #endif |
37 | } FIX_ALIASING; | 38 | } FIX_ALIASING; |
38 | #define G (*(struct globals*)&bb_common_bufsiz1) | 39 | #define G (*(struct globals*)bb_common_bufsiz1) |
39 | #define INIT_G() do { } while (0) | 40 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
40 | 41 | ||
41 | 42 | ||
42 | static unsigned long long scale(unsigned long d) | 43 | static unsigned long long scale(unsigned long d) |
diff --git a/procps/fuser.c b/procps/fuser.c index 05b52abb1..6dac852ed 100644 --- a/procps/fuser.c +++ b/procps/fuser.c | |||
@@ -18,6 +18,7 @@ | |||
18 | //usage: "\n -SIGNAL Signal to send (default: KILL)" | 18 | //usage: "\n -SIGNAL Signal to send (default: KILL)" |
19 | 19 | ||
20 | #include "libbb.h" | 20 | #include "libbb.h" |
21 | #include "common_bufsiz.h" | ||
21 | 22 | ||
22 | #define MAX_LINE 255 | 23 | #define MAX_LINE 255 |
23 | 24 | ||
@@ -43,8 +44,9 @@ struct globals { | |||
43 | smallint kill_failed; | 44 | smallint kill_failed; |
44 | int killsig; | 45 | int killsig; |
45 | } FIX_ALIASING; | 46 | } FIX_ALIASING; |
46 | #define G (*(struct globals*)&bb_common_bufsiz1) | 47 | #define G (*(struct globals*)bb_common_bufsiz1) |
47 | #define INIT_G() do { \ | 48 | #define INIT_G() do { \ |
49 | setup_common_bufsiz(); \ | ||
48 | G.mypid = getpid(); \ | 50 | G.mypid = getpid(); \ |
49 | G.killsig = SIGKILL; \ | 51 | G.killsig = SIGKILL; \ |
50 | } while (0) | 52 | } while (0) |
diff --git a/procps/nmeter.c b/procps/nmeter.c index 33de3790f..3eac2d3b2 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c | |||
@@ -53,6 +53,7 @@ | |||
53 | // totalswap=134209536, freeswap=134209536, procs=157}) | 53 | // totalswap=134209536, freeswap=134209536, procs=157}) |
54 | 54 | ||
55 | #include "libbb.h" | 55 | #include "libbb.h" |
56 | #include "common_bufsiz.h" | ||
56 | 57 | ||
57 | typedef unsigned long long ullong; | 58 | typedef unsigned long long ullong; |
58 | 59 | ||
@@ -108,16 +109,15 @@ struct globals { | |||
108 | #define proc_meminfo (G.proc_meminfo ) | 109 | #define proc_meminfo (G.proc_meminfo ) |
109 | #define proc_diskstats (G.proc_diskstats ) | 110 | #define proc_diskstats (G.proc_diskstats ) |
110 | #define proc_sys_fs_filenr (G.proc_sys_fs_filenr) | 111 | #define proc_sys_fs_filenr (G.proc_sys_fs_filenr) |
112 | #define outbuf bb_common_bufsiz1 | ||
111 | #define INIT_G() do { \ | 113 | #define INIT_G() do { \ |
114 | setup_common_bufsiz(); \ | ||
112 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 115 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
113 | cur_outbuf = outbuf; \ | 116 | cur_outbuf = outbuf; \ |
114 | G.final_char = '\n'; \ | 117 | G.final_char = '\n'; \ |
115 | G.deltanz = G.delta = 1000000; \ | 118 | G.deltanz = G.delta = 1000000; \ |
116 | } while (0) | 119 | } while (0) |
117 | 120 | ||
118 | // We depend on this being a char[], not char* - we take sizeof() of it | ||
119 | #define outbuf bb_common_bufsiz1 | ||
120 | |||
121 | static inline void reset_outbuf(void) | 121 | static inline void reset_outbuf(void) |
122 | { | 122 | { |
123 | cur_outbuf = outbuf; | 123 | cur_outbuf = outbuf; |
@@ -140,7 +140,7 @@ static void print_outbuf(void) | |||
140 | static void put(const char *s) | 140 | static void put(const char *s) |
141 | { | 141 | { |
142 | char *p = cur_outbuf; | 142 | char *p = cur_outbuf; |
143 | int sz = outbuf + sizeof(outbuf) - p; | 143 | int sz = outbuf + COMMON_BUFSIZE - p; |
144 | while (*s && --sz >= 0) | 144 | while (*s && --sz >= 0) |
145 | *p++ = *s++; | 145 | *p++ = *s++; |
146 | cur_outbuf = p; | 146 | cur_outbuf = p; |
@@ -148,7 +148,7 @@ static void put(const char *s) | |||
148 | 148 | ||
149 | static void put_c(char c) | 149 | static void put_c(char c) |
150 | { | 150 | { |
151 | if (cur_outbuf < outbuf + sizeof(outbuf)) | 151 | if (cur_outbuf < outbuf + COMMON_BUFSIZE) |
152 | *cur_outbuf++ = c; | 152 | *cur_outbuf++ = c; |
153 | } | 153 | } |
154 | 154 | ||
diff --git a/procps/ps.c b/procps/ps.c index 8c373376d..39cccec82 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -62,6 +62,7 @@ | |||
62 | //usage: " 2990 andersen andersen R ps\n" | 62 | //usage: " 2990 andersen andersen R ps\n" |
63 | 63 | ||
64 | #include "libbb.h" | 64 | #include "libbb.h" |
65 | #include "common_bufsiz.h" | ||
65 | #ifdef __linux__ | 66 | #ifdef __linux__ |
66 | # include <sys/sysinfo.h> | 67 | # include <sys/sysinfo.h> |
67 | #endif | 68 | #endif |
@@ -144,7 +145,7 @@ struct globals { | |||
144 | unsigned long seconds_since_boot; | 145 | unsigned long seconds_since_boot; |
145 | #endif | 146 | #endif |
146 | } FIX_ALIASING; | 147 | } FIX_ALIASING; |
147 | #define G (*(struct globals*)&bb_common_bufsiz1) | 148 | #define G (*(struct globals*)bb_common_bufsiz1) |
148 | #define out (G.out ) | 149 | #define out (G.out ) |
149 | #define out_cnt (G.out_cnt ) | 150 | #define out_cnt (G.out_cnt ) |
150 | #define print_header (G.print_header ) | 151 | #define print_header (G.print_header ) |
@@ -152,7 +153,7 @@ struct globals { | |||
152 | #define buffer (G.buffer ) | 153 | #define buffer (G.buffer ) |
153 | #define terminal_width (G.terminal_width ) | 154 | #define terminal_width (G.terminal_width ) |
154 | #define kernel_HZ (G.kernel_HZ ) | 155 | #define kernel_HZ (G.kernel_HZ ) |
155 | #define INIT_G() do { } while (0) | 156 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
156 | 157 | ||
157 | #if ENABLE_FEATURE_PS_TIME | 158 | #if ENABLE_FEATURE_PS_TIME |
158 | /* for ELF executables, notes are pushed before environment and args */ | 159 | /* for ELF executables, notes are pushed before environment and args */ |
diff --git a/procps/top.c b/procps/top.c index ddf794d7d..73cd285f0 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -105,6 +105,7 @@ | |||
105 | //config: Enable 's' in top (gives lots of memory info). | 105 | //config: Enable 's' in top (gives lots of memory info). |
106 | 106 | ||
107 | #include "libbb.h" | 107 | #include "libbb.h" |
108 | #include "common_bufsiz.h" | ||
108 | 109 | ||
109 | 110 | ||
110 | typedef struct top_status_t { | 111 | typedef struct top_status_t { |
@@ -183,7 +184,7 @@ struct globals { | |||
183 | char line_buf[80]; | 184 | char line_buf[80]; |
184 | }; //FIX_ALIASING; - large code growth | 185 | }; //FIX_ALIASING; - large code growth |
185 | enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) }; | 186 | enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) }; |
186 | #define G (*(struct globals*)&bb_common_bufsiz1) | 187 | #define G (*(struct globals*)bb_common_bufsiz1) |
187 | #define top (G.top ) | 188 | #define top (G.top ) |
188 | #define ntop (G.ntop ) | 189 | #define ntop (G.ntop ) |
189 | #define sort_field (G.sort_field ) | 190 | #define sort_field (G.sort_field ) |
@@ -201,6 +202,7 @@ enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) }; | |||
201 | #define total_pcpu (G.total_pcpu ) | 202 | #define total_pcpu (G.total_pcpu ) |
202 | #define line_buf (G.line_buf ) | 203 | #define line_buf (G.line_buf ) |
203 | #define INIT_G() do { \ | 204 | #define INIT_G() do { \ |
205 | setup_common_bufsiz(); \ | ||
204 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ | 206 | BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \ |
205 | BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \ | 207 | BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \ |
206 | } while (0) | 208 | } while (0) |
@@ -263,9 +265,9 @@ static int mult_lvl_cmp(void* a, void* b) | |||
263 | static NOINLINE int read_cpu_jiffy(FILE *fp, jiffy_counts_t *p_jif) | 265 | static NOINLINE int read_cpu_jiffy(FILE *fp, jiffy_counts_t *p_jif) |
264 | { | 266 | { |
265 | #if !ENABLE_FEATURE_TOP_SMP_CPU | 267 | #if !ENABLE_FEATURE_TOP_SMP_CPU |
266 | static const char fmt[] = "cpu %llu %llu %llu %llu %llu %llu %llu %llu"; | 268 | static const char fmt[] ALIGN1 = "cpu %llu %llu %llu %llu %llu %llu %llu %llu"; |
267 | #else | 269 | #else |
268 | static const char fmt[] = "cp%*s %llu %llu %llu %llu %llu %llu %llu %llu"; | 270 | static const char fmt[] ALIGN1 = "cp%*s %llu %llu %llu %llu %llu %llu %llu %llu"; |
269 | #endif | 271 | #endif |
270 | int ret; | 272 | int ret; |
271 | 273 | ||
@@ -517,7 +519,7 @@ enum { | |||
517 | 519 | ||
518 | static void parse_meminfo(unsigned long meminfo[MI_MAX]) | 520 | static void parse_meminfo(unsigned long meminfo[MI_MAX]) |
519 | { | 521 | { |
520 | static const char fields[] = | 522 | static const char fields[] ALIGN1 = |
521 | "MemTotal\0" | 523 | "MemTotal\0" |
522 | "MemFree\0" | 524 | "MemFree\0" |
523 | "MemShared\0" | 525 | "MemShared\0" |
diff --git a/runit/runsv.c b/runit/runsv.c index 4b18d12d5..e0e31508a 100644 --- a/runit/runsv.c +++ b/runit/runsv.c | |||
@@ -45,6 +45,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
45 | 45 | ||
46 | #include <sys/file.h> | 46 | #include <sys/file.h> |
47 | #include "libbb.h" | 47 | #include "libbb.h" |
48 | #include "common_bufsiz.h" | ||
48 | #include "runit_lib.h" | 49 | #include "runit_lib.h" |
49 | 50 | ||
50 | #if ENABLE_MONOTONIC_SYSCALL | 51 | #if ENABLE_MONOTONIC_SYSCALL |
@@ -105,7 +106,7 @@ struct globals { | |||
105 | char *dir; | 106 | char *dir; |
106 | struct svdir svd[2]; | 107 | struct svdir svd[2]; |
107 | } FIX_ALIASING; | 108 | } FIX_ALIASING; |
108 | #define G (*(struct globals*)&bb_common_bufsiz1) | 109 | #define G (*(struct globals*)bb_common_bufsiz1) |
109 | #define haslog (G.haslog ) | 110 | #define haslog (G.haslog ) |
110 | #define sigterm (G.sigterm ) | 111 | #define sigterm (G.sigterm ) |
111 | #define pidchanged (G.pidchanged ) | 112 | #define pidchanged (G.pidchanged ) |
@@ -114,6 +115,7 @@ struct globals { | |||
114 | #define dir (G.dir ) | 115 | #define dir (G.dir ) |
115 | #define svd (G.svd ) | 116 | #define svd (G.svd ) |
116 | #define INIT_G() do { \ | 117 | #define INIT_G() do { \ |
118 | setup_common_bufsiz(); \ | ||
117 | pidchanged = 1; \ | 119 | pidchanged = 1; \ |
118 | } while (0) | 120 | } while (0) |
119 | 121 | ||
diff --git a/runit/runsvdir.c b/runit/runsvdir.c index b3d9e7390..2b7927542 100644 --- a/runit/runsvdir.c +++ b/runit/runsvdir.c | |||
@@ -57,6 +57,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
57 | 57 | ||
58 | #include <sys/file.h> | 58 | #include <sys/file.h> |
59 | #include "libbb.h" | 59 | #include "libbb.h" |
60 | #include "common_bufsiz.h" | ||
60 | #include "runit_lib.h" | 61 | #include "runit_lib.h" |
61 | 62 | ||
62 | #define MAXSERVICES 1000 | 63 | #define MAXSERVICES 1000 |
@@ -84,7 +85,7 @@ struct globals { | |||
84 | unsigned stamplog; | 85 | unsigned stamplog; |
85 | #endif | 86 | #endif |
86 | } FIX_ALIASING; | 87 | } FIX_ALIASING; |
87 | #define G (*(struct globals*)&bb_common_bufsiz1) | 88 | #define G (*(struct globals*)bb_common_bufsiz1) |
88 | #define sv (G.sv ) | 89 | #define sv (G.sv ) |
89 | #define svdir (G.svdir ) | 90 | #define svdir (G.svdir ) |
90 | #define svnum (G.svnum ) | 91 | #define svnum (G.svnum ) |
@@ -92,7 +93,7 @@ struct globals { | |||
92 | #define logpipe (G.logpipe ) | 93 | #define logpipe (G.logpipe ) |
93 | #define pfd (G.pfd ) | 94 | #define pfd (G.pfd ) |
94 | #define stamplog (G.stamplog ) | 95 | #define stamplog (G.stamplog ) |
95 | #define INIT_G() do { } while (0) | 96 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
96 | 97 | ||
97 | static void fatal2_cannot(const char *m1, const char *m2) | 98 | static void fatal2_cannot(const char *m1, const char *m2) |
98 | { | 99 | { |
diff --git a/runit/sv.c b/runit/sv.c index de8a0d8a4..2a256a6b4 100644 --- a/runit/sv.c +++ b/runit/sv.c | |||
@@ -189,6 +189,7 @@ Exit Codes | |||
189 | 189 | ||
190 | #include <sys/file.h> | 190 | #include <sys/file.h> |
191 | #include "libbb.h" | 191 | #include "libbb.h" |
192 | #include "common_bufsiz.h" | ||
192 | #include "runit_lib.h" | 193 | #include "runit_lib.h" |
193 | 194 | ||
194 | struct globals { | 195 | struct globals { |
@@ -199,14 +200,14 @@ struct globals { | |||
199 | uint64_t tstart, tnow; | 200 | uint64_t tstart, tnow; |
200 | svstatus_t svstatus; | 201 | svstatus_t svstatus; |
201 | } FIX_ALIASING; | 202 | } FIX_ALIASING; |
202 | #define G (*(struct globals*)&bb_common_bufsiz1) | 203 | #define G (*(struct globals*)bb_common_bufsiz1) |
203 | #define acts (G.acts ) | 204 | #define acts (G.acts ) |
204 | #define service (G.service ) | 205 | #define service (G.service ) |
205 | #define rc (G.rc ) | 206 | #define rc (G.rc ) |
206 | #define tstart (G.tstart ) | 207 | #define tstart (G.tstart ) |
207 | #define tnow (G.tnow ) | 208 | #define tnow (G.tnow ) |
208 | #define svstatus (G.svstatus ) | 209 | #define svstatus (G.svstatus ) |
209 | #define INIT_G() do { } while (0) | 210 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
210 | 211 | ||
211 | 212 | ||
212 | #define str_equal(s,t) (!strcmp((s), (t))) | 213 | #define str_equal(s,t) (!strcmp((s), (t))) |
diff --git a/runit/svlogd.c b/runit/svlogd.c index dbe8df65c..7cae81cb2 100644 --- a/runit/svlogd.c +++ b/runit/svlogd.c | |||
@@ -155,6 +155,7 @@ log message, you can use a pattern like this instead | |||
155 | 155 | ||
156 | #include <sys/file.h> | 156 | #include <sys/file.h> |
157 | #include "libbb.h" | 157 | #include "libbb.h" |
158 | #include "common_bufsiz.h" | ||
158 | #include "runit_lib.h" | 159 | #include "runit_lib.h" |
159 | 160 | ||
160 | #define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0) | 161 | #define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0) |
@@ -233,7 +234,9 @@ struct globals { | |||
233 | #define blocked_sigset (G.blocked_sigset) | 234 | #define blocked_sigset (G.blocked_sigset) |
234 | #define fl_flag_0 (G.fl_flag_0 ) | 235 | #define fl_flag_0 (G.fl_flag_0 ) |
235 | #define dirn (G.dirn ) | 236 | #define dirn (G.dirn ) |
237 | #define line bb_common_bufsiz1 | ||
236 | #define INIT_G() do { \ | 238 | #define INIT_G() do { \ |
239 | setup_common_bufsiz(); \ | ||
237 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 240 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
238 | linemax = 1000; \ | 241 | linemax = 1000; \ |
239 | /*buflen = 1024;*/ \ | 242 | /*buflen = 1024;*/ \ |
@@ -241,8 +244,6 @@ struct globals { | |||
241 | replace = ""; \ | 244 | replace = ""; \ |
242 | } while (0) | 245 | } while (0) |
243 | 246 | ||
244 | #define line bb_common_bufsiz1 | ||
245 | |||
246 | 247 | ||
247 | #define FATAL "fatal: " | 248 | #define FATAL "fatal: " |
248 | #define WARNING "warning: " | 249 | #define WARNING "warning: " |
@@ -1045,9 +1046,9 @@ int svlogd_main(int argc, char **argv) | |||
1045 | } | 1046 | } |
1046 | if (opt & 2) if (!repl) repl = '_'; // -R | 1047 | if (opt & 2) if (!repl) repl = '_'; // -R |
1047 | if (opt & 4) { // -l | 1048 | if (opt & 4) { // -l |
1048 | linemax = xatou_range(l, 0, BUFSIZ-26); | 1049 | linemax = xatou_range(l, 0, COMMON_BUFSIZE-26); |
1049 | if (linemax == 0) | 1050 | if (linemax == 0) |
1050 | linemax = BUFSIZ-26; | 1051 | linemax = COMMON_BUFSIZE-26; |
1051 | if (linemax < 256) | 1052 | if (linemax < 256) |
1052 | linemax = 256; | 1053 | linemax = 256; |
1053 | } | 1054 | } |
diff --git a/scripts/generate_BUFSIZ.sh b/scripts/generate_BUFSIZ.sh new file mode 100755 index 000000000..844261906 --- /dev/null +++ b/scripts/generate_BUFSIZ.sh | |||
@@ -0,0 +1,181 @@ | |||
1 | #!/bin/sh | ||
2 | # Called from top-level directory a-la | ||
3 | # | ||
4 | # scripts/generate_BUFSIZ.sh include/common_bufsiz.h | ||
5 | |||
6 | . ./.config || exit 1 | ||
7 | |||
8 | debug=false | ||
9 | #debug=true | ||
10 | |||
11 | postcompile=false | ||
12 | test x"$1" = x"--post" && { postcompile=true; shift; } | ||
13 | |||
14 | common_bufsiz_h=$1 | ||
15 | |||
16 | test x"$NM" = x"" && NM="${CONFIG_CROSS_COMPILER_PREFIX}nm" | ||
17 | test x"$CC" = x"" && CC="${CONFIG_CROSS_COMPILER_PREFIX}gcc" | ||
18 | |||
19 | exitcmd="exit 0" | ||
20 | |||
21 | regenerate() { | ||
22 | cat >"$1.$$" | ||
23 | test -f "$1" && diff "$1.$$" "$1" >/dev/null && rm "$1.$$" && return | ||
24 | mv "$1.$$" "$1" | ||
25 | } | ||
26 | |||
27 | generate_std_and_exit() { | ||
28 | $debug && echo "Configuring: bb_common_bufsiz1[] in bss" | ||
29 | { | ||
30 | echo "enum { COMMON_BUFSIZE = 1024 };" | ||
31 | echo "extern char bb_common_bufsiz1[];" | ||
32 | echo "#define setup_common_bufsiz() ((void)0)" | ||
33 | } | regenerate "$common_bufsiz_h" | ||
34 | echo "std" >"$common_bufsiz_h.method" | ||
35 | $exitcmd | ||
36 | } | ||
37 | |||
38 | generate_big_and_exit() { | ||
39 | $debug && echo "Configuring: bb_common_bufsiz1[] in _end[], COMMON_BUFSIZE = $1" | ||
40 | { | ||
41 | echo "enum { COMMON_BUFSIZE = $1 };" | ||
42 | echo "extern char _end[]; /* linker-provided label */" | ||
43 | echo "#define bb_common_bufsiz1 _end" | ||
44 | echo "#define setup_common_bufsiz() ((void)0)" | ||
45 | } | regenerate "$common_bufsiz_h" | ||
46 | echo "$2" >"$common_bufsiz_h.method" | ||
47 | $exitcmd | ||
48 | } | ||
49 | |||
50 | generate_1k_and_exit() { | ||
51 | generate_big_and_exit 1024 "1k" | ||
52 | } | ||
53 | |||
54 | |||
55 | generate_malloc_and_exit() { | ||
56 | $debug && echo "Configuring: bb_common_bufsiz1[] is malloced" | ||
57 | { | ||
58 | echo "enum { COMMON_BUFSIZE = 1024 };" | ||
59 | echo "extern char *const bb_common_bufsiz1;" | ||
60 | echo "void setup_common_bufsiz(void);" | ||
61 | } | regenerate "$common_bufsiz_h" | ||
62 | echo "malloc" >"$common_bufsiz_h.method" | ||
63 | $exitcmd | ||
64 | } | ||
65 | |||
66 | round_down_COMMON_BUFSIZE() { | ||
67 | COMMON_BUFSIZE=$(( ($1-32) & 0xfffffe0 )) | ||
68 | COMMON_BUFSIZE=$(( COMMON_BUFSIZE < 1024 ? 1024 : COMMON_BUFSIZE )) | ||
69 | } | ||
70 | |||
71 | # User does not want any funky stuff? | ||
72 | test x"$CONFIG_FEATURE_USE_BSS_TAIL" = x"y" || generate_std_and_exit | ||
73 | |||
74 | # The script is run two times: before compilation, when it needs to | ||
75 | # (re)generate $common_bufsiz_h, and directly after successful build, | ||
76 | # when it needs to assess whether the build is ok to use at all (not buggy), | ||
77 | # and (re)generate $common_bufsiz_h for a future build. | ||
78 | |||
79 | if $postcompile; then | ||
80 | # Postcompile needs to create/delete OK/FAIL files | ||
81 | |||
82 | test -f busybox_unstripped || exit 1 | ||
83 | test -f "$common_bufsiz_h.method" || exit 1 | ||
84 | |||
85 | # How the build was done? | ||
86 | method=`cat -- "$common_bufsiz_h.method"` | ||
87 | |||
88 | # Get _end address | ||
89 | END=`$NM busybox_unstripped | grep ' . _end$'| cut -d' ' -f1` | ||
90 | test x"$END" = x"" && generate_std_and_exit | ||
91 | $debug && echo "END:0x$END $((0x$END))" | ||
92 | END=$((0x$END)) | ||
93 | |||
94 | # Get PAGE_SIZE | ||
95 | { | ||
96 | echo "#include <sys/user.h>" | ||
97 | echo "#if defined(PAGE_SIZE) && PAGE_SIZE > 0" | ||
98 | echo "char page_size[PAGE_SIZE];" | ||
99 | echo "#endif" | ||
100 | } >page_size_$$.c | ||
101 | $CC -c "page_size_$$.c" || exit 1 | ||
102 | PAGE_SIZE=`$NM --size-sort "page_size_$$.o" | cut -d' ' -f1` | ||
103 | rm "page_size_$$.c" "page_size_$$.o" | ||
104 | test x"$PAGE_SIZE" = x"" && exit 1 | ||
105 | $debug && echo "PAGE_SIZE:0x$PAGE_SIZE $((0x$PAGE_SIZE))" | ||
106 | PAGE_SIZE=$((0x$PAGE_SIZE)) | ||
107 | test $PAGE_SIZE -lt 512 && exit 1 | ||
108 | |||
109 | # How much space between _end[] and next page? | ||
110 | PAGE_MASK=$((PAGE_SIZE-1)) | ||
111 | TAIL_SIZE=$(( (-END) & PAGE_MASK )) | ||
112 | $debug && echo "TAIL_SIZE:$TAIL_SIZE bytes" | ||
113 | |||
114 | if test x"$method" = x"1k" || test x"$method" = x"big"; then | ||
115 | if test $TAIL_SIZE -lt 1024; then | ||
116 | # _end[] has no enough space for bb_common_bufsiz1[] | ||
117 | echo "Warning! Space in _end[] is too small ($TAIL_SIZE bytes)!" | ||
118 | echo "Rerun make to build a binary which doesn't use it!" | ||
119 | rm -- "$common_bufsiz_h.1k.OK" 2>/dev/null | ||
120 | { md5sum <.config | cut -d' ' -f1; stat -c "%Y" .config; } >"$common_bufsiz_h.1k.FAIL" | ||
121 | rm busybox_unstripped busybox 2>/dev/null | ||
122 | # Note: here we can do either a "malloc" or "std" build. | ||
123 | # "malloc" gives a bit bigger code: | ||
124 | # text bss filename | ||
125 | # 804355 5385 busybox.std | ||
126 | # 804618 4361 busybox.malloc | ||
127 | # but may have a smaller .bss (not guaranteed!). Use "pmap -x" to verify. | ||
128 | exitcmd="exit 1" | ||
129 | generate_malloc_and_exit | ||
130 | else | ||
131 | PREV_SIZE=1024 | ||
132 | test x"$method" = x"big" && PREV_SIZE=`cat -- "$common_bufsiz_h.1k.OK"` | ||
133 | round_down_COMMON_BUFSIZE $PREV_SIZE | ||
134 | PREV_BUFSIZE=$COMMON_BUFSIZE | ||
135 | |||
136 | rm -- "$common_bufsiz_h.1k.FAIL" 2>/dev/null | ||
137 | echo $TAIL_SIZE >"$common_bufsiz_h.1k.OK" | ||
138 | round_down_COMMON_BUFSIZE $TAIL_SIZE | ||
139 | # emit message only if COMMON_BUFSIZE is indeed larger | ||
140 | test $COMMON_BUFSIZE -gt $PREV_BUFSIZE \ | ||
141 | && echo "Rerun make to use larger COMMON_BUFSIZE ($COMMON_BUFSIZE)" | ||
142 | #TODO: test $PREV_BUFSIZE -lt $TAIL_SIZE && PANIC!!! | ||
143 | #Code size with COMMON_BUFSIZE > 1024 may be bigger than code with COMMON_BUFSIZE = 1024! | ||
144 | #(currently we just hope "-32 and round down to 32" saves us) | ||
145 | |||
146 | test $COMMON_BUFSIZE = 1024 && generate_1k_and_exit | ||
147 | generate_big_and_exit $COMMON_BUFSIZE "big" | ||
148 | fi | ||
149 | fi | ||
150 | fi | ||
151 | |||
152 | # Based on past success/fail of 1k build, decide next build type | ||
153 | |||
154 | if test -f "$common_bufsiz_h.1k.OK"; then | ||
155 | # Previous build succeeded fitting 1k into _end[]. | ||
156 | # Try bigger COMMON_BUFSIZE if possible. | ||
157 | TAIL_SIZE=`cat -- "$common_bufsiz_h.1k.OK"` | ||
158 | round_down_COMMON_BUFSIZE $TAIL_SIZE | ||
159 | test $COMMON_BUFSIZE = 1024 && generate_1k_and_exit | ||
160 | generate_big_and_exit $COMMON_BUFSIZE "big" | ||
161 | fi | ||
162 | |||
163 | if test -f "$common_bufsiz_h.1k.FAIL"; then | ||
164 | # Previous build FAILED to fit 1k into _end[]. | ||
165 | # Was it with same .config? | ||
166 | oldcfg=`cat -- "$common_bufsiz_h.1k.FAIL"` | ||
167 | curcfg=`md5sum <.config | cut -d' ' -f1; stat -c "%Y" .config` | ||
168 | # If yes, then build a "malloced" version | ||
169 | if test x"$oldcfg" = x"$curcfg"; then | ||
170 | echo "Will not try 1k build, it failed before. Touch .config to override" | ||
171 | # Note: here we can do either a "malloc" or "std" build. | ||
172 | generate_malloc_and_exit | ||
173 | fi | ||
174 | # else: try 1k version | ||
175 | echo "New .config, will try 1k build" | ||
176 | rm -- "$common_bufsiz_h.1k.FAIL" | ||
177 | generate_1k_and_exit | ||
178 | fi | ||
179 | |||
180 | # There was no 1k build yet. Try it. | ||
181 | generate_1k_and_exit | ||
diff --git a/scripts/trylink b/scripts/trylink index 15435f009..129570a60 100755 --- a/scripts/trylink +++ b/scripts/trylink | |||
@@ -209,6 +209,16 @@ else | |||
209 | # *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*) | 209 | # *(.bss SORT_BY_ALIGNMENT(.bss.*) .gnu.linkonce.b.*) |
210 | # This will eliminate most of the padding (~3kb). | 210 | # This will eliminate most of the padding (~3kb). |
211 | # Hmm, "ld --sort-section alignment" should do it too. | 211 | # Hmm, "ld --sort-section alignment" should do it too. |
212 | # | ||
213 | # There is a ld hack which is meant to decrease disk usage | ||
214 | # at the cost of more RAM usage (??!!) in standard ld script: | ||
215 | # /* Adjust the address for the data segment. We want to adjust up to | ||
216 | # the same address within the page on the next page up. */ | ||
217 | # . = ALIGN (0x1000) - ((0x1000 - .) & (0x1000 - 1)); . = DATA_SEGMENT_ALIGN (0x1000, 0x1000); | ||
218 | # Replace it with: | ||
219 | # . = ALIGN (0x1000); . = DATA_SEGMENT_ALIGN (0x1000, 0x1000); | ||
220 | # to unconditionally align .data to the next page boundary, | ||
221 | # instead of "next page, plus current offset in this page" | ||
212 | try $CC $CFLAGS $LDFLAGS \ | 222 | try $CC $CFLAGS $LDFLAGS \ |
213 | -o $EXE \ | 223 | -o $EXE \ |
214 | $SORT_COMMON \ | 224 | $SORT_COMMON \ |
diff --git a/selinux/setfiles.c b/selinux/setfiles.c index de99dfe44..51a7e63bd 100644 --- a/selinux/setfiles.c +++ b/selinux/setfiles.c | |||
@@ -77,9 +77,10 @@ struct globals { | |||
77 | int nerr; | 77 | int nerr; |
78 | struct edir excludeArray[MAX_EXCLUDES]; | 78 | struct edir excludeArray[MAX_EXCLUDES]; |
79 | } FIX_ALIASING; | 79 | } FIX_ALIASING; |
80 | #define G (*(struct globals*)&bb_common_bufsiz1) | 80 | #define G (*(struct globals*)bb_common_bufsiz1) |
81 | void BUG_setfiles_globals_too_big(void); | 81 | void BUG_setfiles_globals_too_big(void); |
82 | #define INIT_G() do { \ | 82 | #define INIT_G() do { \ |
83 | setup_common_bufsiz(); \ | ||
83 | if (sizeof(G) > COMMON_BUFSIZE) \ | 84 | if (sizeof(G) > COMMON_BUFSIZE) \ |
84 | BUG_setfiles_globals_too_big(); \ | 85 | BUG_setfiles_globals_too_big(); \ |
85 | /* memset(&G, 0, sizeof(G)); - already is */ \ | 86 | /* memset(&G, 0, sizeof(G)); - already is */ \ |
diff --git a/shell/ash.c b/shell/ash.c index 52feff422..5870a23f3 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2942,7 +2942,7 @@ pwdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
2942 | #else | 2942 | #else |
2943 | # define SIT_ITEM(a,b,c,d) (a | (b << 4) | (c << 8)) | 2943 | # define SIT_ITEM(a,b,c,d) (a | (b << 4) | (c << 8)) |
2944 | #endif | 2944 | #endif |
2945 | static const uint16_t S_I_T[] = { | 2945 | static const uint16_t S_I_T[] ALIGN2 = { |
2946 | #if ENABLE_ASH_ALIAS | 2946 | #if ENABLE_ASH_ALIAS |
2947 | SIT_ITEM(CSPCL , CIGN , CIGN , CIGN ), /* 0, PEOA */ | 2947 | SIT_ITEM(CSPCL , CIGN , CIGN , CIGN ), /* 0, PEOA */ |
2948 | #endif | 2948 | #endif |
@@ -3044,7 +3044,7 @@ SIT(int c, int syntax) | |||
3044 | 3044 | ||
3045 | #else /* !USE_SIT_FUNCTION */ | 3045 | #else /* !USE_SIT_FUNCTION */ |
3046 | 3046 | ||
3047 | static const uint8_t syntax_index_table[] = { | 3047 | static const uint8_t syntax_index_table[] ALIGN1 = { |
3048 | /* BASESYNTAX_DQSYNTAX_SQSYNTAX_ARISYNTAX */ | 3048 | /* BASESYNTAX_DQSYNTAX_SQSYNTAX_ARISYNTAX */ |
3049 | /* 0 */ CWORD_CWORD_CWORD_CWORD, | 3049 | /* 0 */ CWORD_CWORD_CWORD_CWORD, |
3050 | /* 1 */ CWORD_CWORD_CWORD_CWORD, | 3050 | /* 1 */ CWORD_CWORD_CWORD_CWORD, |
@@ -8320,7 +8320,7 @@ static char **nodeptr; | |||
8320 | #define EV_TESTED 02 /* exit status is checked; ignore -e flag */ | 8320 | #define EV_TESTED 02 /* exit status is checked; ignore -e flag */ |
8321 | #define EV_BACKCMD 04 /* command executing within back quotes */ | 8321 | #define EV_BACKCMD 04 /* command executing within back quotes */ |
8322 | 8322 | ||
8323 | static const uint8_t nodesize[N_NUMBER] = { | 8323 | static const uint8_t nodesize[N_NUMBER] ALIGN1 = { |
8324 | [NCMD ] = SHELL_ALIGN(sizeof(struct ncmd)), | 8324 | [NCMD ] = SHELL_ALIGN(sizeof(struct ncmd)), |
8325 | [NPIPE ] = SHELL_ALIGN(sizeof(struct npipe)), | 8325 | [NPIPE ] = SHELL_ALIGN(sizeof(struct npipe)), |
8326 | [NREDIR ] = SHELL_ALIGN(sizeof(struct nredir)), | 8326 | [NREDIR ] = SHELL_ALIGN(sizeof(struct nredir)), |
@@ -11935,7 +11935,7 @@ parsesub: { | |||
11935 | || (c != '(' && c != '{' && !is_name(c) && !is_special(c)) | 11935 | || (c != '(' && c != '{' && !is_name(c) && !is_special(c)) |
11936 | ) { | 11936 | ) { |
11937 | #if ENABLE_ASH_BASH_COMPAT | 11937 | #if ENABLE_ASH_BASH_COMPAT |
11938 | if (c == '\'') | 11938 | if (syntax != DQSYNTAX && c == '\'') |
11939 | bash_dollar_squote = 1; | 11939 | bash_dollar_squote = 1; |
11940 | else | 11940 | else |
11941 | #endif | 11941 | #endif |
@@ -13072,7 +13072,8 @@ helpcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
13072 | out1fmt("\n"); | 13072 | out1fmt("\n"); |
13073 | col = 0; | 13073 | col = 0; |
13074 | } | 13074 | } |
13075 | a += strlen(a) + 1; | 13075 | while (*a++ != '\0') |
13076 | continue; | ||
13076 | } | 13077 | } |
13077 | } | 13078 | } |
13078 | # endif | 13079 | # endif |
diff --git a/shell/ash_test/ash-heredoc/heredoc4.right b/shell/ash_test/ash-heredoc/heredoc4.right new file mode 100644 index 000000000..371b092e2 --- /dev/null +++ b/shell/ash_test/ash-heredoc/heredoc4.right | |||
@@ -0,0 +1 @@ | |||
'$' | |||
diff --git a/shell/ash_test/ash-heredoc/heredoc4.tests b/shell/ash_test/ash-heredoc/heredoc4.tests new file mode 100755 index 000000000..642ddb324 --- /dev/null +++ b/shell/ash_test/ash-heredoc/heredoc4.tests | |||
@@ -0,0 +1,3 @@ | |||
1 | cat <<EOF | ||
2 | '$' | ||
3 | EOF | ||
diff --git a/shell/ash_test/ash-quoting/dollar_squote_bash1.right b/shell/ash_test/ash-quoting/dollar_squote_bash1.right index 57536b1d9..9f4e25efa 100644 --- a/shell/ash_test/ash-quoting/dollar_squote_bash1.right +++ b/shell/ash_test/ash-quoting/dollar_squote_bash1.right | |||
@@ -1,4 +1,5 @@ | |||
1 | a b | 1 | a b |
2 | $'a\tb' | ||
2 | a | 3 | a |
3 | b c | 4 | b c |
4 | def | 5 | def |
diff --git a/shell/ash_test/ash-quoting/dollar_squote_bash1.tests b/shell/ash_test/ash-quoting/dollar_squote_bash1.tests index 93a56cac3..6fc411b93 100755 --- a/shell/ash_test/ash-quoting/dollar_squote_bash1.tests +++ b/shell/ash_test/ash-quoting/dollar_squote_bash1.tests | |||
@@ -1,4 +1,5 @@ | |||
1 | echo $'a\tb' | 1 | echo $'a\tb' |
2 | echo "$'a\tb'" | ||
2 | echo $'a\nb' $'c\nd''ef' | 3 | echo $'a\nb' $'c\nd''ef' |
3 | echo $'a\'b' $'c\"d' $'e\\f' | 4 | echo $'a\'b' $'c\"d' $'e\\f' |
4 | echo $'a\63b' $'c\063b' $'e\0633f' | 5 | echo $'a\63b' $'c\063b' $'e\0633f' |
diff --git a/shell/shell_common.c b/shell/shell_common.c index dbd4286bf..c3bff477d 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c | |||
@@ -335,7 +335,7 @@ enum { | |||
335 | }; | 335 | }; |
336 | 336 | ||
337 | /* "-": treat args as parameters of option with ASCII code 1 */ | 337 | /* "-": treat args as parameters of option with ASCII code 1 */ |
338 | static const char ulimit_opt_string[] = "-HSa" | 338 | static const char ulimit_opt_string[] ALIGN1 = "-HSa" |
339 | #ifdef RLIMIT_FSIZE | 339 | #ifdef RLIMIT_FSIZE |
340 | "f::" | 340 | "f::" |
341 | #endif | 341 | #endif |
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index 03d65b37f..4db72110d 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c | |||
@@ -58,6 +58,7 @@ | |||
58 | //usage: "\n -n Run in foreground" | 58 | //usage: "\n -n Run in foreground" |
59 | 59 | ||
60 | #include "libbb.h" | 60 | #include "libbb.h" |
61 | #include "common_bufsiz.h" | ||
61 | #include <syslog.h> | 62 | #include <syslog.h> |
62 | 63 | ||
63 | 64 | ||
@@ -147,7 +148,7 @@ static void klogd_close(void) | |||
147 | 148 | ||
148 | #define log_buffer bb_common_bufsiz1 | 149 | #define log_buffer bb_common_bufsiz1 |
149 | enum { | 150 | enum { |
150 | KLOGD_LOGBUF_SIZE = sizeof(log_buffer), | 151 | KLOGD_LOGBUF_SIZE = COMMON_BUFSIZE, |
151 | OPT_LEVEL = (1 << 0), | 152 | OPT_LEVEL = (1 << 0), |
152 | OPT_FOREGROUND = (1 << 1), | 153 | OPT_FOREGROUND = (1 << 1), |
153 | }; | 154 | }; |
@@ -173,6 +174,8 @@ int klogd_main(int argc UNUSED_PARAM, char **argv) | |||
173 | int opt; | 174 | int opt; |
174 | int used; | 175 | int used; |
175 | 176 | ||
177 | setup_common_bufsiz(); | ||
178 | |||
176 | opt = getopt32(argv, "c:n", &opt_c); | 179 | opt = getopt32(argv, "c:n", &opt_c); |
177 | if (opt & OPT_LEVEL) { | 180 | if (opt & OPT_LEVEL) { |
178 | /* Valid levels are between 1 and 8 */ | 181 | /* Valid levels are between 1 and 8 */ |
diff --git a/sysklogd/logger.c b/sysklogd/logger.c index b3ca85703..f9eafeb25 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c | |||
@@ -99,6 +99,8 @@ int logger_main(int argc UNUSED_PARAM, char **argv) | |||
99 | int opt; | 99 | int opt; |
100 | int i = 0; | 100 | int i = 0; |
101 | 101 | ||
102 | setup_common_bufsiz(); | ||
103 | |||
102 | /* Fill out the name string early (may be overwritten later) */ | 104 | /* Fill out the name string early (may be overwritten later) */ |
103 | str_t = uid2uname_utoa(geteuid()); | 105 | str_t = uid2uname_utoa(geteuid()); |
104 | 106 | ||
diff --git a/sysklogd/logread.c b/sysklogd/logread.c index 781a603b2..5b999730a 100644 --- a/sysklogd/logread.c +++ b/sysklogd/logread.c | |||
@@ -42,6 +42,7 @@ | |||
42 | //usage: "\n -F Same as -f, but dump buffer first" | 42 | //usage: "\n -F Same as -f, but dump buffer first" |
43 | 43 | ||
44 | #include "libbb.h" | 44 | #include "libbb.h" |
45 | #include "common_bufsiz.h" | ||
45 | #include <sys/ipc.h> | 46 | #include <sys/ipc.h> |
46 | #include <sys/sem.h> | 47 | #include <sys/sem.h> |
47 | #include <sys/shm.h> | 48 | #include <sys/shm.h> |
@@ -67,11 +68,12 @@ struct globals { | |||
67 | struct sembuf SMrdn[2]; // {1, 0}, {0, +1, SEM_UNDO} | 68 | struct sembuf SMrdn[2]; // {1, 0}, {0, +1, SEM_UNDO} |
68 | struct shbuf_ds *shbuf; | 69 | struct shbuf_ds *shbuf; |
69 | } FIX_ALIASING; | 70 | } FIX_ALIASING; |
70 | #define G (*(struct globals*)&bb_common_bufsiz1) | 71 | #define G (*(struct globals*)bb_common_bufsiz1) |
71 | #define SMrup (G.SMrup) | 72 | #define SMrup (G.SMrup) |
72 | #define SMrdn (G.SMrdn) | 73 | #define SMrdn (G.SMrdn) |
73 | #define shbuf (G.shbuf) | 74 | #define shbuf (G.shbuf) |
74 | #define INIT_G() do { \ | 75 | #define INIT_G() do { \ |
76 | setup_common_bufsiz(); \ | ||
75 | memcpy(SMrup, init_sem, sizeof(init_sem)); \ | 77 | memcpy(SMrup, init_sem, sizeof(init_sem)); \ |
76 | } while (0) | 78 | } while (0) |
77 | 79 | ||
diff --git a/sysklogd/syslogd_and_logger.c b/sysklogd/syslogd_and_logger.c index 0964f239c..6458a9332 100644 --- a/sysklogd/syslogd_and_logger.c +++ b/sysklogd/syslogd_and_logger.c | |||
@@ -8,6 +8,7 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | #include "common_bufsiz.h" | ||
11 | #define SYSLOG_NAMES | 12 | #define SYSLOG_NAMES |
12 | #define SYSLOG_NAMES_CONST | 13 | #define SYSLOG_NAMES_CONST |
13 | #include <syslog.h> | 14 | #include <syslog.h> |
diff --git a/testsuite/sed.tests b/testsuite/sed.tests index 5d2356b64..a71f8b1f0 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests | |||
@@ -135,10 +135,12 @@ testing "sed empty file plus cat" "sed -e 's/nohit//' input -" "one\ntwo" \ | |||
135 | "" "one\ntwo" | 135 | "" "one\ntwo" |
136 | testing "sed cat plus empty file" "sed -e 's/nohit//' input -" "one\ntwo" \ | 136 | testing "sed cat plus empty file" "sed -e 's/nohit//' input -" "one\ntwo" \ |
137 | "one\ntwo" "" | 137 | "one\ntwo" "" |
138 | test x"$SKIP_KNOWN_BUGS" = x"" && { | ||
139 | testing "sed append autoinserts newline" "sed -e '/woot/a woo' -" \ | 138 | testing "sed append autoinserts newline" "sed -e '/woot/a woo' -" \ |
140 | "woot\nwoo\n" "" "woot" | 139 | "woot\nwoo\n" "" "woot" |
141 | } | 140 | testing "sed append autoinserts newline 2" "sed -e '/oot/a woo' - input" \ |
141 | "woot\nwoo\nboot\nwoo\n" "boot" "woot" | ||
142 | testing "sed append autoinserts newline 3" "sed -e '/oot/a woo' -i input && cat input" \ | ||
143 | "boot\nwoo\n" "boot" "" | ||
142 | testing "sed insert doesn't autoinsert newline" "sed -e '/woot/i woo' -" \ | 144 | testing "sed insert doesn't autoinsert newline" "sed -e '/woot/i woo' -" \ |
143 | "woo\nwoot" "" "woot" | 145 | "woo\nwoot" "" "woot" |
144 | testing "sed print autoinsert newlines" "sed -e 'p' -" "one\none" "" "one" | 146 | testing "sed print autoinsert newlines" "sed -e 'p' -" "one\none" "" "one" |
@@ -275,6 +277,24 @@ testing "sed a cmd ended by double backslash" \ | |||
275 | | two \\ | 277 | | two \\ |
276 | ' | 278 | ' |
277 | 279 | ||
280 | testing "sed a cmd understands \\n,\\t,\\r" \ | ||
281 | "sed '/1/a\\\\t\\rzero\\none\\\\ntwo\\\\\\nthree'" \ | ||
282 | "\ | ||
283 | line1 | ||
284 | \t\rzero | ||
285 | one\\\\ntwo\\ | ||
286 | three | ||
287 | " "" "line1\n" | ||
288 | |||
289 | testing "sed i cmd understands \\n,\\t,\\r" \ | ||
290 | "sed '/1/i\\\\t\\rzero\\none\\\\ntwo\\\\\\nthree'" \ | ||
291 | "\ | ||
292 | \t\rzero | ||
293 | one\\\\ntwo\\ | ||
294 | three | ||
295 | line1 | ||
296 | " "" "line1\n" | ||
297 | |||
278 | # first three lines are deleted; 4th line is matched and printed by "2,3" and by "4" ranges | 298 | # first three lines are deleted; 4th line is matched and printed by "2,3" and by "4" ranges |
279 | testing "sed with N skipping lines past ranges on next cmds" \ | 299 | testing "sed with N skipping lines past ranges on next cmds" \ |
280 | "sed -n '1{N;N;d};1p;2,3p;3p;4p'" \ | 300 | "sed -n '1{N;N;d};1p;2,3p;3p;4p'" \ |
diff --git a/util-linux/fatattr.c b/util-linux/fatattr.c index 5d933874a..6dca24a73 100644 --- a/util-linux/fatattr.c +++ b/util-linux/fatattr.c | |||
@@ -42,7 +42,7 @@ | |||
42 | * Extra space at the end is a hack to print space separator in file listing. | 42 | * Extra space at the end is a hack to print space separator in file listing. |
43 | * Let's hope no one ever passes space as an option char :) | 43 | * Let's hope no one ever passes space as an option char :) |
44 | */ | 44 | */ |
45 | static const char bit_to_char[] = "rhsvda67 "; | 45 | static const char bit_to_char[] ALIGN1 = "rhsvda67 "; |
46 | 46 | ||
47 | static inline unsigned long get_flag(char c) | 47 | static inline unsigned long get_flag(char c) |
48 | { | 48 | { |
diff --git a/util-linux/flock.c b/util-linux/flock.c index 05a747f72..1f7ade7c4 100644 --- a/util-linux/flock.c +++ b/util-linux/flock.c | |||
@@ -57,7 +57,6 @@ int flock_main(int argc UNUSED_PARAM, char **argv) | |||
57 | /* If it is "flock FILE -c PROG", then -c isn't caught by getopt32: | 57 | /* If it is "flock FILE -c PROG", then -c isn't caught by getopt32: |
58 | * we use "+" in order to support "flock -opt FILE PROG -with-opts", | 58 | * we use "+" in order to support "flock -opt FILE PROG -with-opts", |
59 | * we need to remove -c by hand. | 59 | * we need to remove -c by hand. |
60 | * TODO: in upstream, -c 'PROG ARGS' means "run sh -c 'PROG ARGS'" | ||
61 | */ | 60 | */ |
62 | if (argv[0] | 61 | if (argv[0] |
63 | && argv[0][0] == '-' | 62 | && argv[0][0] == '-' |
@@ -66,6 +65,9 @@ int flock_main(int argc UNUSED_PARAM, char **argv) | |||
66 | ) | 65 | ) |
67 | ) { | 66 | ) { |
68 | argv++; | 67 | argv++; |
68 | if (argv[1]) | ||
69 | bb_error_msg_and_die("-c takes only one argument"); | ||
70 | opt |= OPT_c; | ||
69 | } | 71 | } |
70 | 72 | ||
71 | if (OPT_s == LOCK_SH && OPT_x == LOCK_EX && OPT_n == LOCK_NB && OPT_u == LOCK_UN) { | 73 | if (OPT_s == LOCK_SH && OPT_x == LOCK_EX && OPT_n == LOCK_NB && OPT_u == LOCK_UN) { |
@@ -90,8 +92,21 @@ int flock_main(int argc UNUSED_PARAM, char **argv) | |||
90 | bb_perror_nomsg_and_die(); | 92 | bb_perror_nomsg_and_die(); |
91 | } | 93 | } |
92 | 94 | ||
93 | if (argv[0]) | 95 | if (argv[0]) { |
94 | return spawn_and_wait(argv); | 96 | int rc; |
97 | if (opt & OPT_c) { | ||
98 | /* -c 'PROG ARGS' means "run sh -c 'PROG ARGS'" */ | ||
99 | argv -= 2; | ||
100 | argv[0] = (char*)get_shell_name(); | ||
101 | argv[1] = (char*)"-c"; | ||
102 | /* argv[2] = "PROG ARGS"; */ | ||
103 | /* argv[3] = NULL; */ | ||
104 | } | ||
105 | rc = spawn_and_wait(argv); | ||
106 | if (rc < 0) | ||
107 | bb_simple_perror_msg(argv[0]); | ||
108 | return rc; | ||
109 | } | ||
95 | 110 | ||
96 | return EXIT_SUCCESS; | 111 | return EXIT_SUCCESS; |
97 | } | 112 | } |
diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 37fa56827..37514eb54 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c | |||
@@ -97,6 +97,7 @@ | |||
97 | //usage: "If /dev/mdev.log file exists, debug log will be appended to it." | 97 | //usage: "If /dev/mdev.log file exists, debug log will be appended to it." |
98 | 98 | ||
99 | #include "libbb.h" | 99 | #include "libbb.h" |
100 | #include "common_bufsiz.h" | ||
100 | #include "xregex.h" | 101 | #include "xregex.h" |
101 | 102 | ||
102 | /* "mdev -s" scans /sys/class/xxx, looking for directories which have dev | 103 | /* "mdev -s" scans /sys/class/xxx, looking for directories which have dev |
@@ -285,8 +286,9 @@ struct globals { | |||
285 | struct rule cur_rule; | 286 | struct rule cur_rule; |
286 | char timestr[sizeof("HH:MM:SS.123456")]; | 287 | char timestr[sizeof("HH:MM:SS.123456")]; |
287 | } FIX_ALIASING; | 288 | } FIX_ALIASING; |
288 | #define G (*(struct globals*)&bb_common_bufsiz1) | 289 | #define G (*(struct globals*)bb_common_bufsiz1) |
289 | #define INIT_G() do { \ | 290 | #define INIT_G() do { \ |
291 | setup_common_bufsiz(); \ | ||
290 | IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.maj = -1;) \ | 292 | IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.maj = -1;) \ |
291 | IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.mode = 0660;) \ | 293 | IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.mode = 0660;) \ |
292 | } while (0) | 294 | } while (0) |
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c index b5d2c49b6..dcb53f008 100644 --- a/util-linux/mkswap.c +++ b/util-linux/mkswap.c | |||
@@ -13,6 +13,7 @@ | |||
13 | //usage: "\n -L LBL Label" | 13 | //usage: "\n -L LBL Label" |
14 | 14 | ||
15 | #include "libbb.h" | 15 | #include "libbb.h" |
16 | #include "common_bufsiz.h" | ||
16 | 17 | ||
17 | #if ENABLE_SELINUX | 18 | #if ENABLE_SELINUX |
18 | static void mkswap_selinux_setcontext(int fd, const char *path) | 19 | static void mkswap_selinux_setcontext(int fd, const char *path) |
@@ -75,6 +76,7 @@ struct swap_header_v1 { | |||
75 | 76 | ||
76 | #define NWORDS 129 | 77 | #define NWORDS 129 |
77 | #define hdr ((struct swap_header_v1*)bb_common_bufsiz1) | 78 | #define hdr ((struct swap_header_v1*)bb_common_bufsiz1) |
79 | #define INIT_G() do { setup_common_bufsiz(); } while (0) | ||
78 | 80 | ||
79 | struct BUG_sizes { | 81 | struct BUG_sizes { |
80 | char swap_header_v1_wrong[sizeof(*hdr) != (NWORDS * 4) ? -1 : 1]; | 82 | char swap_header_v1_wrong[sizeof(*hdr) != (NWORDS * 4) ? -1 : 1]; |
@@ -92,6 +94,8 @@ int mkswap_main(int argc UNUSED_PARAM, char **argv) | |||
92 | off_t len; | 94 | off_t len; |
93 | const char *label = ""; | 95 | const char *label = ""; |
94 | 96 | ||
97 | INIT_G(); | ||
98 | |||
95 | opt_complementary = "-1"; /* at least one param */ | 99 | opt_complementary = "-1"; /* at least one param */ |
96 | /* TODO: -p PAGESZ, -U UUID */ | 100 | /* TODO: -p PAGESZ, -U UUID */ |
97 | getopt32(argv, "L:", &label); | 101 | getopt32(argv, "L:", &label); |
diff --git a/util-linux/more.c b/util-linux/more.c index 29984df8c..4812f1bc5 100644 --- a/util-linux/more.c +++ b/util-linux/more.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <conio.h> | 26 | #include <conio.h> |
27 | #endif | 27 | #endif |
28 | #include "libbb.h" | 28 | #include "libbb.h" |
29 | #include "common_bufsiz.h" | ||
29 | 30 | ||
30 | /* Support for FEATURE_USE_TERMIOS */ | 31 | /* Support for FEATURE_USE_TERMIOS */ |
31 | 32 | ||
@@ -35,10 +36,10 @@ struct globals { | |||
35 | struct termios new_settings; | 36 | struct termios new_settings; |
36 | } FIX_ALIASING; | 37 | } FIX_ALIASING; |
37 | #define G (*(struct globals*)bb_common_bufsiz1) | 38 | #define G (*(struct globals*)bb_common_bufsiz1) |
38 | #define INIT_G() ((void)0) | ||
39 | #define initial_settings (G.initial_settings) | 39 | #define initial_settings (G.initial_settings) |
40 | #define new_settings (G.new_settings ) | 40 | #define new_settings (G.new_settings ) |
41 | #define cin_fileno (G.cin_fileno ) | 41 | #define cin_fileno (G.cin_fileno ) |
42 | #define INIT_G() do { setup_common_bufsiz(); } while (0) | ||
42 | 43 | ||
43 | #define setTermSettings(fd, argp) \ | 44 | #define setTermSettings(fd, argp) \ |
44 | do { \ | 45 | do { \ |
diff --git a/util-linux/mount.c b/util-linux/mount.c index c428f5827..c76f6ef61 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -223,6 +223,7 @@ | |||
223 | #define BB_MS_INVERTED_VALUE (1u << 31) | 223 | #define BB_MS_INVERTED_VALUE (1u << 31) |
224 | 224 | ||
225 | #include "libbb.h" | 225 | #include "libbb.h" |
226 | #include "common_bufsiz.h" | ||
226 | #if ENABLE_FEATURE_MOUNT_LABEL | 227 | #if ENABLE_FEATURE_MOUNT_LABEL |
227 | # include "volume_id.h" | 228 | # include "volume_id.h" |
228 | #else | 229 | #else |
@@ -376,7 +377,7 @@ static const int32_t mount_options[] = { | |||
376 | /* "remount" */ MS_REMOUNT // action flag | 377 | /* "remount" */ MS_REMOUNT // action flag |
377 | }; | 378 | }; |
378 | 379 | ||
379 | static const char mount_option_str[] = | 380 | static const char mount_option_str[] ALIGN1 = |
380 | IF_FEATURE_MOUNT_LOOP( | 381 | IF_FEATURE_MOUNT_LOOP( |
381 | "loop\0" | 382 | "loop\0" |
382 | ) | 383 | ) |
@@ -447,7 +448,7 @@ struct globals { | |||
447 | char getmntent_buf[1]; | 448 | char getmntent_buf[1]; |
448 | } FIX_ALIASING; | 449 | } FIX_ALIASING; |
449 | enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_buf) }; | 450 | enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_buf) }; |
450 | #define G (*(struct globals*)&bb_common_bufsiz1) | 451 | #define G (*(struct globals*)bb_common_bufsiz1) |
451 | #define nfs_mount_version (G.nfs_mount_version) | 452 | #define nfs_mount_version (G.nfs_mount_version) |
452 | #if ENABLE_FEATURE_MOUNT_VERBOSE | 453 | #if ENABLE_FEATURE_MOUNT_VERBOSE |
453 | #define verbose (G.verbose ) | 454 | #define verbose (G.verbose ) |
@@ -456,7 +457,7 @@ enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_b | |||
456 | #endif | 457 | #endif |
457 | #define fslist (G.fslist ) | 458 | #define fslist (G.fslist ) |
458 | #define getmntent_buf (G.getmntent_buf ) | 459 | #define getmntent_buf (G.getmntent_buf ) |
459 | #define INIT_G() do { } while (0) | 460 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
460 | 461 | ||
461 | #if ENABLE_FEATURE_MTAB_SUPPORT | 462 | #if ENABLE_FEATURE_MTAB_SUPPORT |
462 | /* | 463 | /* |
@@ -1002,7 +1003,7 @@ enum { | |||
1002 | # define EDQUOT ENOSPC | 1003 | # define EDQUOT ENOSPC |
1003 | #endif | 1004 | #endif |
1004 | /* Convert each NFSERR_BLAH into EBLAH */ | 1005 | /* Convert each NFSERR_BLAH into EBLAH */ |
1005 | static const uint8_t nfs_err_stat[] = { | 1006 | static const uint8_t nfs_err_stat[] ALIGN1 = { |
1006 | 1, 2, 5, 6, 13, 17, | 1007 | 1, 2, 5, 6, 13, 17, |
1007 | 19, 20, 21, 22, 27, 28, | 1008 | 19, 20, 21, 22, 27, 28, |
1008 | 30, 63, 66, 69, 70, 71 | 1009 | 30, 63, 66, 69, 70, 71 |
@@ -1015,7 +1016,7 @@ typedef uint8_t nfs_err_type; | |||
1015 | #else | 1016 | #else |
1016 | typedef uint16_t nfs_err_type; | 1017 | typedef uint16_t nfs_err_type; |
1017 | #endif | 1018 | #endif |
1018 | static const nfs_err_type nfs_err_errnum[] = { | 1019 | static const nfs_err_type nfs_err_errnum[] ALIGN2 = { |
1019 | EPERM , ENOENT , EIO , ENXIO , EACCES, EEXIST, | 1020 | EPERM , ENOENT , EIO , ENXIO , EACCES, EEXIST, |
1020 | ENODEV, ENOTDIR , EISDIR , EINVAL, EFBIG , ENOSPC, | 1021 | ENODEV, ENOTDIR , EISDIR , EINVAL, EFBIG , ENOSPC, |
1021 | EROFS , ENAMETOOLONG, ENOTEMPTY, EDQUOT, ESTALE, EREMOTE | 1022 | EROFS , ENAMETOOLONG, ENOTEMPTY, EDQUOT, ESTALE, EREMOTE |
diff --git a/util-linux/nsenter.c b/util-linux/nsenter.c index b08b3dae7..6834292da 100644 --- a/util-linux/nsenter.c +++ b/util-linux/nsenter.c | |||
@@ -128,7 +128,7 @@ static const struct namespace_descr ns_list[] = { | |||
128 | /* | 128 | /* |
129 | * Upstream nsenter doesn't support the short option for --preserve-credentials | 129 | * Upstream nsenter doesn't support the short option for --preserve-credentials |
130 | */ | 130 | */ |
131 | static const char opt_str[] = "U::i::u::n::p::m::""t+S+G+r::w::F"; | 131 | static const char opt_str[] ALIGN1 = "U::i::u::n::p::m::""t+S+G+r::w::F"; |
132 | 132 | ||
133 | #if ENABLE_FEATURE_NSENTER_LONG_OPTS | 133 | #if ENABLE_FEATURE_NSENTER_LONG_OPTS |
134 | static const char nsenter_longopts[] ALIGN1 = | 134 | static const char nsenter_longopts[] ALIGN1 = |
diff --git a/util-linux/script.c b/util-linux/script.c index abcd73bff..86475c1f1 100644 --- a/util-linux/script.c +++ b/util-linux/script.c | |||
@@ -23,6 +23,7 @@ | |||
23 | //usage: ) | 23 | //usage: ) |
24 | 24 | ||
25 | #include "libbb.h" | 25 | #include "libbb.h" |
26 | #include "common_bufsiz.h" | ||
26 | 27 | ||
27 | int script_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 28 | int script_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
28 | int script_main(int argc UNUSED_PARAM, char **argv) | 29 | int script_main(int argc UNUSED_PARAM, char **argv) |
@@ -108,11 +109,12 @@ int script_main(int argc UNUSED_PARAM, char **argv) | |||
108 | 109 | ||
109 | if (child_pid) { | 110 | if (child_pid) { |
110 | /* parent */ | 111 | /* parent */ |
111 | #define buf bb_common_bufsiz1 | ||
112 | struct pollfd pfd[2]; | 112 | struct pollfd pfd[2]; |
113 | int outfd, count, loop; | 113 | int outfd, count, loop; |
114 | double oldtime = ENABLE_SCRIPTREPLAY ? time(NULL) : 0; | 114 | double oldtime = ENABLE_SCRIPTREPLAY ? time(NULL) : 0; |
115 | smallint fd_count = 2; | 115 | smallint fd_count = 2; |
116 | #define buf bb_common_bufsiz1 | ||
117 | setup_common_bufsiz(); | ||
116 | 118 | ||
117 | outfd = xopen(fname, mode); | 119 | outfd = xopen(fname, mode); |
118 | pfd[0].fd = pty; | 120 | pfd[0].fd = pty; |
@@ -134,7 +136,7 @@ int script_main(int argc UNUSED_PARAM, char **argv) | |||
134 | } | 136 | } |
135 | if (pfd[0].revents) { | 137 | if (pfd[0].revents) { |
136 | errno = 0; | 138 | errno = 0; |
137 | count = safe_read(pty, buf, sizeof(buf)); | 139 | count = safe_read(pty, buf, COMMON_BUFSIZE); |
138 | if (count <= 0 && errno != EAGAIN) { | 140 | if (count <= 0 && errno != EAGAIN) { |
139 | /* err/eof from pty: exit */ | 141 | /* err/eof from pty: exit */ |
140 | goto restore; | 142 | goto restore; |
@@ -157,7 +159,7 @@ int script_main(int argc UNUSED_PARAM, char **argv) | |||
157 | } | 159 | } |
158 | } | 160 | } |
159 | if (pfd[1].revents) { | 161 | if (pfd[1].revents) { |
160 | count = safe_read(STDIN_FILENO, buf, sizeof(buf)); | 162 | count = safe_read(STDIN_FILENO, buf, COMMON_BUFSIZE); |
161 | if (count <= 0) { | 163 | if (count <= 0) { |
162 | /* err/eof from stdin: don't read stdin anymore */ | 164 | /* err/eof from stdin: don't read stdin anymore */ |
163 | pfd[1].revents = 0; | 165 | pfd[1].revents = 0; |
@@ -176,7 +178,7 @@ int script_main(int argc UNUSED_PARAM, char **argv) | |||
176 | * (util-linux's script doesn't do this. buggy :) */ | 178 | * (util-linux's script doesn't do this. buggy :) */ |
177 | loop = 999; | 179 | loop = 999; |
178 | /* pty is in O_NONBLOCK mode, we exit as soon as buffer is empty */ | 180 | /* pty is in O_NONBLOCK mode, we exit as soon as buffer is empty */ |
179 | while (--loop && (count = safe_read(pty, buf, sizeof(buf))) > 0) { | 181 | while (--loop && (count = safe_read(pty, buf, COMMON_BUFSIZE)) > 0) { |
180 | full_write(STDOUT_FILENO, buf, count); | 182 | full_write(STDOUT_FILENO, buf, count); |
181 | full_write(outfd, buf, count); | 183 | full_write(outfd, buf, count); |
182 | } | 184 | } |
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index c29dd3071..6713852e5 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c | |||
@@ -28,6 +28,7 @@ | |||
28 | //usage: "\n -a Stop swapping on all swap devices" | 28 | //usage: "\n -a Stop swapping on all swap devices" |
29 | 29 | ||
30 | #include "libbb.h" | 30 | #include "libbb.h" |
31 | #include "common_bufsiz.h" | ||
31 | #include <mntent.h> | 32 | #include <mntent.h> |
32 | #ifndef __BIONIC__ | 33 | #ifndef __BIONIC__ |
33 | # include <sys/swap.h> | 34 | # include <sys/swap.h> |
@@ -62,7 +63,7 @@ | |||
62 | struct globals { | 63 | struct globals { |
63 | int flags; | 64 | int flags; |
64 | } FIX_ALIASING; | 65 | } FIX_ALIASING; |
65 | #define G (*(struct globals*)&bb_common_bufsiz1) | 66 | #define G (*(struct globals*)bb_common_bufsiz1) |
66 | #define g_flags (G.flags) | 67 | #define g_flags (G.flags) |
67 | #define save_g_flags() int save_g_flags = g_flags | 68 | #define save_g_flags() int save_g_flags = g_flags |
68 | #define restore_g_flags() g_flags = save_g_flags | 69 | #define restore_g_flags() g_flags = save_g_flags |
@@ -71,7 +72,7 @@ struct globals { | |||
71 | #define save_g_flags() ((void)0) | 72 | #define save_g_flags() ((void)0) |
72 | #define restore_g_flags() ((void)0) | 73 | #define restore_g_flags() ((void)0) |
73 | #endif | 74 | #endif |
74 | #define INIT_G() do { } while (0) | 75 | #define INIT_G() do { setup_common_bufsiz(); } while (0) |
75 | 76 | ||
76 | #define do_swapoff (applet_name[5] == 'f') | 77 | #define do_swapoff (applet_name[5] == 'f') |
77 | 78 | ||
diff --git a/util-linux/uevent.c b/util-linux/uevent.c index 514a9e934..b98fe6160 100644 --- a/util-linux/uevent.c +++ b/util-linux/uevent.c | |||
@@ -25,11 +25,13 @@ | |||
25 | //usage: "\n"" # uevent mdev & mdev -s" | 25 | //usage: "\n"" # uevent mdev & mdev -s" |
26 | 26 | ||
27 | #include "libbb.h" | 27 | #include "libbb.h" |
28 | #include "common_bufsiz.h" | ||
28 | #include <linux/netlink.h> | 29 | #include <linux/netlink.h> |
29 | 30 | ||
30 | #define BUFFER_SIZE 16*1024 | 31 | #define BUFFER_SIZE 16*1024 |
31 | 32 | ||
32 | #define env ((char **)&bb_common_bufsiz1) | 33 | #define env ((char **)bb_common_bufsiz1) |
34 | #define INIT_G() do { setup_common_bufsiz(); } while (0) | ||
33 | enum { | 35 | enum { |
34 | MAX_ENV = COMMON_BUFSIZE / sizeof(env[0]) - 1, | 36 | MAX_ENV = COMMON_BUFSIZE / sizeof(env[0]) - 1, |
35 | }; | 37 | }; |
@@ -45,6 +47,8 @@ int uevent_main(int argc UNUSED_PARAM, char **argv) | |||
45 | struct sockaddr_nl sa; | 47 | struct sockaddr_nl sa; |
46 | int fd; | 48 | int fd; |
47 | 49 | ||
50 | INIT_G(); | ||
51 | |||
48 | argv++; | 52 | argv++; |
49 | 53 | ||
50 | // Subscribe for UEVENT kernel messages | 54 | // Subscribe for UEVENT kernel messages |
diff --git a/util-linux/umount.c b/util-linux/umount.c index 30bef1686..91da69674 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c | |||
@@ -34,6 +34,7 @@ | |||
34 | # define MNT_DETACH 0x00000002 | 34 | # define MNT_DETACH 0x00000002 |
35 | #endif | 35 | #endif |
36 | #include "libbb.h" | 36 | #include "libbb.h" |
37 | #include "common_bufsiz.h" | ||
37 | 38 | ||
38 | #if defined(__dietlibc__) | 39 | #if defined(__dietlibc__) |
39 | // TODO: This does not belong here. | 40 | // TODO: This does not belong here. |
@@ -102,7 +103,8 @@ int umount_main(int argc UNUSED_PARAM, char **argv) | |||
102 | if (opt & OPT_ALL) | 103 | if (opt & OPT_ALL) |
103 | bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file); | 104 | bb_error_msg_and_die("can't open '%s'", bb_path_mtab_file); |
104 | } else { | 105 | } else { |
105 | while (getmntent_r(fp, &me, bb_common_bufsiz1, sizeof(bb_common_bufsiz1))) { | 106 | setup_common_bufsiz(); |
107 | while (getmntent_r(fp, &me, bb_common_bufsiz1, COMMON_BUFSIZE)) { | ||
106 | /* Match fstype if passed */ | 108 | /* Match fstype if passed */ |
107 | if (!match_fstype(&me, fstype)) | 109 | if (!match_fstype(&me, fstype)) |
108 | continue; | 110 | continue; |
diff --git a/util-linux/unshare.c b/util-linux/unshare.c index d05cfdb6c..fa7086add 100644 --- a/util-linux/unshare.c +++ b/util-linux/unshare.c | |||
@@ -137,7 +137,7 @@ static const struct namespace_descr ns_list[] = { | |||
137 | * we are forced to use "fake" letters for them. | 137 | * we are forced to use "fake" letters for them. |
138 | * '+': stop at first non-option. | 138 | * '+': stop at first non-option. |
139 | */ | 139 | */ |
140 | static const char opt_str[] = "+muinpU""fr""\xfd::""\xfe:""\xff:"; | 140 | static const char opt_str[] ALIGN1 = "+muinpU""fr""\xfd::""\xfe:""\xff:"; |
141 | static const char unshare_longopts[] ALIGN1 = | 141 | static const char unshare_longopts[] ALIGN1 = |
142 | "mount\0" Optional_argument "\xf0" | 142 | "mount\0" Optional_argument "\xf0" |
143 | "uts\0" Optional_argument "\xf1" | 143 | "uts\0" Optional_argument "\xf1" |
diff --git a/util-linux/volume_id/bcache.c b/util-linux/volume_id/bcache.c index 648e44de5..fd40eb081 100644 --- a/util-linux/volume_id/bcache.c +++ b/util-linux/volume_id/bcache.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #define SB_LABEL_SIZE 32 | 24 | #define SB_LABEL_SIZE 32 |
25 | #define SB_JOURNAL_BUCKETS 256U | 25 | #define SB_JOURNAL_BUCKETS 256U |
26 | 26 | ||
27 | static const char bcache_magic[] = { | 27 | static const char bcache_magic[] ALIGN1 = { |
28 | 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca, | 28 | 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca, |
29 | 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 | 29 | 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81 |
30 | }; | 30 | }; |
diff --git a/util-linux/volume_id/luks.c b/util-linux/volume_id/luks.c index 42bf87659..21cb26f51 100644 --- a/util-linux/volume_id/luks.c +++ b/util-linux/volume_id/luks.c | |||
@@ -40,7 +40,7 @@ | |||
40 | #define LUKS_SALTSIZE 32 | 40 | #define LUKS_SALTSIZE 32 |
41 | #define LUKS_NUMKEYS 8 | 41 | #define LUKS_NUMKEYS 8 |
42 | 42 | ||
43 | static const uint8_t LUKS_MAGIC[] = { 'L','U','K','S', 0xba, 0xbe }; | 43 | static const uint8_t LUKS_MAGIC[] ALIGN1 = { 'L','U','K','S', 0xba, 0xbe }; |
44 | 44 | ||
45 | struct luks_phdr { | 45 | struct luks_phdr { |
46 | uint8_t magic[LUKS_MAGIC_L]; | 46 | uint8_t magic[LUKS_MAGIC_L]; |