From 931c55f9e2b41473132683488820c6fb7c47506b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 13 Jan 2022 12:50:48 +0100 Subject: libbb: invert the meaning of SETUP_ENV_NO_CHDIR -> SETUP_ENV_CHDIR Double negatives are hard to grok. function old new delta login_main 986 988 +2 su_main 474 470 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 2/-4) Total: -2 bytes Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 +- shell/hush.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 12b2db3a9..ca5c755b6 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -10791,7 +10791,7 @@ preadfd(void) write(STDOUT_FILENO, "^C", 2); raise(SIGINT); /* raise(SIGINT) did not work! (e.g. if SIGINT - * is SIG_INGed on startup, it stays SIG_IGNed) + * is SIG_IGNed on startup, it stays SIG_IGNed) */ if (trap[SIGINT]) { buf[0] = '\n'; diff --git a/shell/hush.c b/shell/hush.c index 982fc356a..7d0dc67e4 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -10361,7 +10361,7 @@ int hush_main(int argc, char **argv) //it ignores TERM: // bash -i -c 'kill $$; echo ALIVE' // ALIVE -//it resets SIG_INGed HUP to SIG_DFL: +//it resets SIG_IGNed HUP to SIG_DFL: // trap '' hup; bash -i -c 'kill -hup $$; echo ALIVE' // Hangup [the message is not printed by bash, it's the shell which started it] //is talkative about jobs and exiting: -- cgit v1.2.3-55-g6feb From a277506a64404e6c4472ff89c944c4f353db1c33 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 16 Jan 2022 23:54:46 +0100 Subject: shell: add comments about SIGINT-related problems Signed-off-by: Denys Vlasenko --- shell/ash.c | 13 ++++++++----- shell/shell_common.c | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index ca5c755b6..086773dd7 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -664,7 +664,7 @@ raise_exception(int e) /* * Called when a SIGINT is received. (If the user specifies * that SIGINT is to be trapped or ignored using the trap builtin, then - * this routine is not called.) Suppressint is nonzero when interrupts + * this routine is not called.) suppress_int is nonzero when interrupts * are held using the INT_OFF macro. (The test for iflag is just * defensive programming.) */ @@ -695,13 +695,12 @@ raise_interrupt(void) } while (0) #endif -static IF_ASH_OPTIMIZE_FOR_SIZE(inline) void +static IF_NOT_ASH_OPTIMIZE_FOR_SIZE(inline) void int_on(void) { barrier(); - if (--suppress_int == 0 && pending_int) { + if (--suppress_int == 0 && pending_int) raise_interrupt(); - } } #if DEBUG_INTONOFF # define INT_ON do { \ @@ -711,7 +710,7 @@ int_on(void) #else # define INT_ON int_on() #endif -static IF_ASH_OPTIMIZE_FOR_SIZE(inline) void +static IF_NOT_ASH_OPTIMIZE_FOR_SIZE(inline) void force_int_on(void) { barrier(); @@ -10785,6 +10784,10 @@ preadfd(void) # endif reinit_unicode_for_ash(); again: +//BUG: not in INT_OFF/INT_ON section - SIGINT et al would longjmp out of read_line_input()! +//This would cause a memory leak in interactive shell +//(repeated internal allocations in read_line_input): +// (while kill -INT $$; do :; done) & nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ); if (nr == 0) { /* ^C pressed, "convert" to SIGINT */ diff --git a/shell/shell_common.c b/shell/shell_common.c index 2e36d9208..13163acdf 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -196,6 +196,7 @@ shell_builtin_read(struct builtin_read_params *params) */ errno = 0; pfd[0].events = POLLIN; +//TODO race with a signal arriving just before the poll! if (poll(pfd, 1, timeout) <= 0) { /* timed out, or EINTR */ err = errno; -- cgit v1.2.3-55-g6feb From 12566e7f9b5e5c5d445bc4d36991d134b431dc6c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 17 Jan 2022 03:02:40 +0100 Subject: ash,hush: fix handling of SIGINT while waiting for interactive input function old new delta lineedit_read_key 160 237 +77 __pgetc 522 589 +67 fgetc_interactive 244 309 +65 safe_read_key - 39 +39 read_key 588 607 +19 record_pending_signo 23 32 +9 signal_handler 75 81 +6 .rodata 104312 104309 -3 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 6/1 up/down: 282/-3) Total: 279 bytes Signed-off-by: Denys Vlasenko --- editors/vi.c | 4 ++-- include/libbb.h | 5 +++- libbb/lineedit.c | 24 ++++++++++++++++--- libbb/read_key.c | 16 +++++++++++-- miscutils/hexedit.c | 2 +- miscutils/less.c | 4 ++-- procps/top.c | 2 +- shell/ash.c | 39 ++++++++++++++++++++++++------- shell/hush.c | 67 +++++++++++++++++++++++++++++++++++++---------------- 9 files changed, 122 insertions(+), 41 deletions(-) (limited to 'shell') diff --git a/editors/vi.c b/editors/vi.c index 3dbe5b471..d37cd48a3 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -1122,7 +1122,7 @@ static int readit(void) // read (maybe cursor) key from stdin // on nonblocking stdin. // Note: read_key sets errno to 0 on success. again: - c = read_key(STDIN_FILENO, readbuffer, /*timeout:*/ -1); + c = safe_read_key(STDIN_FILENO, readbuffer, /*timeout:*/ -1); if (c == -1) { // EOF/error if (errno == EAGAIN) // paranoia goto again; @@ -4770,7 +4770,7 @@ static void edit_file(char *fn) uint64_t k; write1(ESC"[999;999H" ESC"[6n"); fflush_all(); - k = read_key(STDIN_FILENO, readbuffer, /*timeout_ms:*/ 100); + k = safe_read_key(STDIN_FILENO, readbuffer, /*timeout_ms:*/ 100); if ((int32_t)k == KEYCODE_CURSOR_POS) { uint32_t rc = (k >> 32); columns = (rc & 0x7fff); diff --git a/include/libbb.h b/include/libbb.h index 91b456915..b45ce91c5 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1908,6 +1908,8 @@ enum { * >=0: poll() for TIMEOUT milliseconds, return -1/EAGAIN on timeout */ int64_t read_key(int fd, char *buffer, int timeout) FAST_FUNC; +/* This version loops on EINTR: */ +int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC; void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC; @@ -1961,7 +1963,8 @@ enum { USERNAME_COMPLETION = 4 * ENABLE_FEATURE_USERNAME_COMPLETION, VI_MODE = 8 * ENABLE_FEATURE_EDITING_VI, WITH_PATH_LOOKUP = 0x10, - FOR_SHELL = DO_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION, + LI_INTERRUPTIBLE = 0x20, + FOR_SHELL = DO_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION | LI_INTERRUPTIBLE, }; line_input_t *new_line_input_t(int flags) FAST_FUNC; #if ENABLE_FEATURE_EDITING_SAVEHISTORY diff --git a/libbb/lineedit.c b/libbb/lineedit.c index e14c78707..f76afd37d 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -2161,12 +2161,30 @@ static int lineedit_read_key(char *read_key_buffer, int timeout) * insist on full MB_CUR_MAX buffer to declare input like * "\xff\n",pause,"ls\n" invalid and thus won't lose "ls". * + * If LI_INTERRUPTIBLE, return -1 if got EINTR in poll() + * inside read_key, or if bb_got_signal != 0 (IOW: if signal + * arrived before poll() is reached). + * * Note: read_key sets errno to 0 on success. */ - IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 1;) - ic = read_key(STDIN_FILENO, read_key_buffer, timeout); - IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;) + do { + if ((state->flags & LI_INTERRUPTIBLE) && bb_got_signal) { + errno = EINTR; + return -1; + } +//FIXME: still races here with signals, but small window to poll() inside read_key + IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 1;) + ic = read_key(STDIN_FILENO, read_key_buffer, timeout); + IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;) + } while (!(state->flags & LI_INTERRUPTIBLE) && errno == EINTR); + if (errno) { + /* LI_INTERRUPTIBLE can bail out with EINTR here, + * but nothing really guarantees that bb_got_signal + * is nonzero. Follow the least surprise principle: + */ + if (errno == EINTR && bb_got_signal == 0) + bb_got_signal = 255; /* something nonzero */ #if ENABLE_UNICODE_SUPPORT if (errno == EAGAIN && unicode_idx != 0) goto pushback; diff --git a/libbb/read_key.c b/libbb/read_key.c index 03b7da656..829ae215c 100644 --- a/libbb/read_key.c +++ b/libbb/read_key.c @@ -126,7 +126,10 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) * if fd can be in non-blocking mode. */ if (timeout >= -1) { - if (safe_poll(&pfd, 1, timeout) == 0) { + n = poll(&pfd, 1, timeout); + if (n < 0 && errno == EINTR) + return n; + if (n == 0) { /* Timed out */ errno = EAGAIN; return -1; @@ -138,7 +141,7 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) * When we were reading 3 bytes here, we were eating * "li" too, and cat was getting wrong input. */ - n = safe_read(fd, buffer, 1); + n = read(fd, buffer, 1); if (n <= 0) return -1; } @@ -284,6 +287,15 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) goto start_over; } +int64_t FAST_FUNC safe_read_key(int fd, char *buffer, int timeout) +{ + int64_t r; + do { + r = read_key(fd, buffer, timeout); + } while (errno == EINTR); + return r; +} + void FAST_FUNC read_key_ungets(char *buffer, const char *str, unsigned len) { unsigned cur_len = (unsigned char)buffer[0]; diff --git a/miscutils/hexedit.c b/miscutils/hexedit.c index f8ff9b62b..15ad78377 100644 --- a/miscutils/hexedit.c +++ b/miscutils/hexedit.c @@ -292,7 +292,7 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv) fflush_all(); G.in_read_key = 1; if (!bb_got_signal) - key = read_key(STDIN_FILENO, G.read_key_buffer, -1); + key = safe_read_key(STDIN_FILENO, G.read_key_buffer, -1); G.in_read_key = 0; if (bb_got_signal) key = CTRL('X'); diff --git a/miscutils/less.c b/miscutils/less.c index 82c4b21f0..8a0525cb7 100644 --- a/miscutils/less.c +++ b/miscutils/less.c @@ -1137,9 +1137,9 @@ static int64_t getch_nowait(void) #endif } - /* We have kbd_fd in O_NONBLOCK mode, read inside read_key() + /* We have kbd_fd in O_NONBLOCK mode, read inside safe_read_key() * would not block even if there is no input available */ - key64 = read_key(kbd_fd, kbd_input, /*timeout off:*/ -2); + key64 = safe_read_key(kbd_fd, kbd_input, /*timeout off:*/ -2); if ((int)key64 == -1) { if (errno == EAGAIN) { /* No keyboard input available. Since poll() did return, diff --git a/procps/top.c b/procps/top.c index 4cd545c69..804d6f258 100644 --- a/procps/top.c +++ b/procps/top.c @@ -913,7 +913,7 @@ static unsigned handle_input(unsigned scan_mask, duration_t interval) while (1) { int32_t c; - c = read_key(STDIN_FILENO, G.kbd_input, interval * 1000); + c = safe_read_key(STDIN_FILENO, G.kbd_input, interval * 1000); if (c == -1 && errno != EAGAIN) { /* error/EOF */ option_mask32 |= OPT_EOF; diff --git a/shell/ash.c b/shell/ash.c index 086773dd7..55df54bd0 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -3679,7 +3679,9 @@ signal_handler(int signo) if (!trap[SIGCHLD]) return; } - +#if ENABLE_FEATURE_EDITING + bb_got_signal = signo; /* for read_line_input: "we got a signal" */ +#endif gotsig[signo - 1] = 1; pending_sig = signo; @@ -10784,33 +10786,52 @@ preadfd(void) # endif reinit_unicode_for_ash(); again: -//BUG: not in INT_OFF/INT_ON section - SIGINT et al would longjmp out of read_line_input()! -//This would cause a memory leak in interactive shell -//(repeated internal allocations in read_line_input): -// (while kill -INT $$; do :; done) & + /* For shell, LI_INTERRUPTIBLE is set: + * read_line_input will abort on either + * getting EINTR in poll(), or if it sees bb_got_signal != 0 + * (IOW: if signal arrives before poll() is reached). + * Interactive testcases: + * (while kill -INT $$; do sleep 1; done) & + * #^^^ prints ^C, prints prompt, repeats + * trap 'echo I' int; (while kill -INT $$; do sleep 1; done) & + * #^^^ prints ^C, prints "I", prints prompt, repeats + * trap 'echo T' term; (while kill $$; do sleep 1; done) & + * #^^^ prints "T", prints prompt, repeats + * #(bash 5.0.17 exits after first "T", looks like a bug) + */ + bb_got_signal = 0; + INT_OFF; /* no longjmp'ing out of read_line_input please */ nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ); + if (bb_got_signal == SIGINT) + write(STDOUT_FILENO, "^C\n", 3); + INT_ON; /* here non-blocked SIGINT will longjmp */ if (nr == 0) { /* ^C pressed, "convert" to SIGINT */ - write(STDOUT_FILENO, "^C", 2); - raise(SIGINT); + write(STDOUT_FILENO, "^C\n", 3); + raise(SIGINT); /* here non-blocked SIGINT will longjmp */ /* raise(SIGINT) did not work! (e.g. if SIGINT * is SIG_IGNed on startup, it stays SIG_IGNed) */ if (trap[SIGINT]) { + empty_line_input: buf[0] = '\n'; buf[1] = '\0'; return 1; } exitstatus = 128 + SIGINT; /* bash behavior on ^C + ignored SIGINT: */ - write(STDOUT_FILENO, "\n", 1); goto again; } if (nr < 0) { if (errno == 0) { - /* Ctrl+D pressed */ + /* ^D pressed */ nr = 0; } + else if (errno == EINTR) { /* got signal? */ + if (bb_got_signal != SIGINT) + write(STDOUT_FILENO, "\n", 1); + goto empty_line_input; + } # if ENABLE_ASH_IDLE_TIMEOUT else if (errno == EAGAIN && timeout > 0) { puts("\007timed out waiting for input: auto-logout"); diff --git a/shell/hush.c b/shell/hush.c index 7d0dc67e4..6dc2ecaac 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -918,6 +918,7 @@ struct globals { #if ENABLE_HUSH_INTERACTIVE smallint promptmode; /* 0: PS1, 1: PS2 */ #endif + /* set by signal handler if SIGINT is received _and_ its trap is not set */ smallint flag_SIGINT; #if ENABLE_HUSH_LOOPS smallint flag_break_continue; @@ -1944,6 +1945,9 @@ enum { static void record_pending_signo(int sig) { sigaddset(&G.pending_set, sig); +#if ENABLE_FEATURE_EDITING + bb_got_signal = sig; /* for read_line_input: "we got a signal" */ +#endif #if ENABLE_HUSH_FAST if (sig == SIGCHLD) { G.count_SIGCHLD++; @@ -2652,30 +2656,53 @@ static int get_user_input(struct in_str *i) for (;;) { reinit_unicode_for_hush(); G.flag_SIGINT = 0; - /* buglet: SIGINT will not make new prompt to appear _at once_, - * only after . (^C works immediately) */ - r = read_line_input(G.line_input_state, prompt_str, + + bb_got_signal = 0; + if (!sigisemptyset(&G.pending_set)) { + /* Whoops, already got a signal, do not call read_line_input */ + bb_got_signal = r = -1; + } else { + /* For shell, LI_INTERRUPTIBLE is set: + * read_line_input will abort on either + * getting EINTR in poll(), or if it sees bb_got_signal != 0 + * (IOW: if signal arrives before poll() is reached). + * Interactive testcases: + * (while kill -INT $$; do sleep 1; done) & + * #^^^ prints ^C, prints prompt, repeats + * trap 'echo I' int; (while kill -INT $$; do sleep 1; done) & + * #^^^ prints ^C, prints "I", prints prompt, repeats + * trap 'echo T' term; (while kill $$; do sleep 1; done) & + * #^^^ prints "T", prints prompt, repeats + * #(bash 5.0.17 exits after first "T", looks like a bug) + */ + r = read_line_input(G.line_input_state, prompt_str, G.user_input_buf, CONFIG_FEATURE_EDITING_MAX_LEN-1 - ); - /* read_line_input intercepts ^C, "convert" it to SIGINT */ - if (r == 0) { - raise(SIGINT); + ); + /* read_line_input intercepts ^C, "convert" it to SIGINT */ + if (r == 0) + raise(SIGINT); + } + /* bash prints ^C (before running a trap, if any) + * both on keyboard ^C and on real SIGINT (non-kbd generated). + */ + if (sigismember(&G.pending_set, SIGINT)) { + write(STDOUT_FILENO, "^C\n", 3); + G.last_exitcode = 128 | SIGINT; } check_and_run_traps(); - if (r != 0 && !G.flag_SIGINT) + if (r == 0) /* keyboard ^C? */ + continue; /* go back, read another input line */ + if (r > 0) /* normal input? (no ^C, no ^D, no signals) */ break; - /* ^C or SIGINT: repeat */ - /* bash prints ^C even on real SIGINT (non-kbd generated) */ - write(STDOUT_FILENO, "^C\n", 3); - G.last_exitcode = 128 | SIGINT; - } - if (r < 0) { - /* EOF/error detected */ - /* ^D on interactive input goes to next line before exiting: */ - write(STDOUT_FILENO, "\n", 1); - i->p = NULL; - i->peek_buf[0] = r = EOF; - return r; + if (!bb_got_signal) { + /* r < 0: ^D/EOF/error detected (but not signal) */ + /* ^D on interactive input goes to next line before exiting: */ + write(STDOUT_FILENO, "\n", 1); + i->p = NULL; + i->peek_buf[0] = r = EOF; + return r; + } + /* it was a signal: go back, read another input line */ } i->p = G.user_input_buf; return (unsigned char)*i->p++; -- cgit v1.2.3-55-g6feb From ca466f385ac985a8b3491daa9f326dc480cdee70 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 6 Feb 2022 19:53:10 +0100 Subject: *: slap on a few ALIGN* where appropriate The result of looking at "grep -F -B2 '*fill*' busybox_unstripped.map" function old new delta .rodata 108586 108460 -126 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-126) Total: -126 bytes text data bss dec hex filename 970412 4219 1848 976479 ee65f busybox_old 970286 4219 1848 976353 ee5e1 busybox_unstripped Signed-off-by: Denys Vlasenko --- console-tools/reset.c | 2 +- coreutils/od.c | 2 +- include/platform.h | 1 + libbb/appletlib.c | 2 +- libbb/get_console.c | 2 +- miscutils/bc.c | 2 +- miscutils/man.c | 2 +- networking/ifupdown.c | 8 ++++---- networking/interface.c | 6 +++--- networking/libiproute/ipaddress.c | 2 +- networking/udhcp/common.c | 2 +- networking/udhcp/d6_dhcpc.c | 2 +- shell/ash.c | 2 +- util-linux/hexdump.c | 2 +- util-linux/nsenter.c | 2 +- util-linux/unshare.c | 2 +- 16 files changed, 21 insertions(+), 20 deletions(-) (limited to 'shell') diff --git a/console-tools/reset.c b/console-tools/reset.c index b3acf69f8..cc04e4fcc 100644 --- a/console-tools/reset.c +++ b/console-tools/reset.c @@ -36,7 +36,7 @@ int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) { - static const char *const args[] = { + static const char *const args[] ALIGN_PTR = { "stty", "sane", NULL }; diff --git a/coreutils/od.c b/coreutils/od.c index 9a888dd5f..6f22331e0 100644 --- a/coreutils/od.c +++ b/coreutils/od.c @@ -144,7 +144,7 @@ odoffset(dumper_t *dumper, int argc, char ***argvp) } } -static const char *const add_strings[] = { +static const char *const add_strings[] ALIGN_PTR = { "16/1 \"%3_u \" \"\\n\"", /* a */ "8/2 \" %06o \" \"\\n\"", /* B, o */ "16/1 \"%03o \" \"\\n\"", /* b */ diff --git a/include/platform.h b/include/platform.h index ad27bb31a..ea0512f36 100644 --- a/include/platform.h +++ b/include/platform.h @@ -346,6 +346,7 @@ typedef unsigned smalluint; # define ALIGN4 #endif #define ALIGN8 __attribute__((aligned(8))) +#define ALIGN_INT __attribute__((aligned(sizeof(int)))) #define ALIGN_PTR __attribute__((aligned(sizeof(void*)))) /* diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 03389f541..841b3b873 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -651,7 +651,7 @@ static void check_suid(int applet_no) # if ENABLE_FEATURE_INSTALLER static const char usr_bin [] ALIGN1 = "/usr/bin/"; static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; -static const char *const install_dir[] = { +static const char *const install_dir[] ALIGN_PTR = { &usr_bin [8], /* "/" */ &usr_bin [4], /* "/bin/" */ &usr_sbin[4] /* "/sbin/" */ diff --git a/libbb/get_console.c b/libbb/get_console.c index 7f2c75332..9044efea1 100644 --- a/libbb/get_console.c +++ b/libbb/get_console.c @@ -37,7 +37,7 @@ static int open_a_console(const char *fnam) */ int FAST_FUNC get_console_fd_or_die(void) { - static const char *const console_names[] = { + static const char *const console_names[] ALIGN_PTR = { DEV_CONSOLE, CURRENT_VC, CURRENT_TTY }; diff --git a/miscutils/bc.c b/miscutils/bc.c index ae370ff55..ab785bbc8 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c @@ -6011,7 +6011,7 @@ static BC_STATUS zxc_program_assign(char inst) #endif if (ib || sc || left->t == XC_RESULT_OBASE) { - static const char *const msg[] = { + static const char *const msg[] ALIGN_PTR = { "bad ibase; must be [2,16]", //XC_RESULT_IBASE "bad obase; must be [2,"BC_MAX_OBASE_STR"]", //XC_RESULT_OBASE "bad scale; must be [0,"BC_MAX_SCALE_STR"]", //XC_RESULT_SCALE diff --git a/miscutils/man.c b/miscutils/man.c index d319e8bba..deaf9e5ab 100644 --- a/miscutils/man.c +++ b/miscutils/man.c @@ -303,7 +303,7 @@ int man_main(int argc UNUSED_PARAM, char **argv) config_close(parser); if (!man_path_list) { - static const char *const mpl[] = { "/usr/man", "/usr/share/man", NULL }; + static const char *const mpl[] ALIGN_PTR = { "/usr/man", "/usr/share/man", NULL }; man_path_list = (char**)mpl; /*count_mp = 2; - not used below anyway */ } diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 737113dd4..6c4ae27f2 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -532,7 +532,7 @@ static int FAST_FUNC v4tunnel_down(struct interface_defn_t * ifd, execfn * exec) } # endif -static const struct method_t methods6[] = { +static const struct method_t methods6[] ALIGN_PTR = { # if ENABLE_FEATURE_IFUPDOWN_IP { "v4tunnel" , v4tunnel_up , v4tunnel_down , }, # endif @@ -627,7 +627,7 @@ struct dhcp_client_t { const char *stopcmd; }; -static const struct dhcp_client_t ext_dhcp_clients[] = { +static const struct dhcp_client_t ext_dhcp_clients[] ALIGN_PTR = { { "dhcpcd", "dhcpcd[[ -h %hostname%]][[ -i %vendor%]][[ -I %client%]][[ -l %leasetime%]] %iface%", "dhcpcd -k %iface%", @@ -774,7 +774,7 @@ static int FAST_FUNC wvdial_down(struct interface_defn_t *ifd, execfn *exec) "-p /var/run/wvdial.%iface% -s 2", ifd, exec); } -static const struct method_t methods[] = { +static const struct method_t methods[] ALIGN_PTR = { { "manual" , manual_up_down, manual_up_down, }, { "wvdial" , wvdial_up , wvdial_down , }, { "ppp" , ppp_up , ppp_down , }, @@ -797,7 +797,7 @@ static int FAST_FUNC link_up_down(struct interface_defn_t *ifd UNUSED_PARAM, exe return 1; } -static const struct method_t link_methods[] = { +static const struct method_t link_methods[] ALIGN_PTR = { { "none", link_up_down, link_up_down } }; diff --git a/networking/interface.c b/networking/interface.c index ea6a2c8a8..6b6c0944a 100644 --- a/networking/interface.c +++ b/networking/interface.c @@ -446,13 +446,13 @@ static char *get_name(char name[IFNAMSIZ], char *p) * %n specifiers (even the size of integers may not match). */ #if INT_MAX == LONG_MAX -static const char *const ss_fmt[] = { +static const char *const ss_fmt[] ALIGN_PTR = { "%n%llu%u%u%u%u%n%n%n%llu%u%u%u%u%u", "%llu%llu%u%u%u%u%n%n%llu%llu%u%u%u%u%u", "%llu%llu%u%u%u%u%u%u%llu%llu%u%u%u%u%u%u" }; #else -static const char *const ss_fmt[] = { +static const char *const ss_fmt[] ALIGN_PTR = { "%n%llu%lu%lu%lu%lu%n%n%n%llu%lu%lu%lu%lu%lu", "%llu%llu%lu%lu%lu%lu%n%n%llu%llu%lu%lu%lu%lu%lu", "%llu%llu%lu%lu%lu%lu%lu%lu%llu%llu%lu%lu%lu%lu%lu%lu" @@ -731,7 +731,7 @@ static const struct hwtype ib_hwtype = { #endif -static const struct hwtype *const hwtypes[] = { +static const struct hwtype *const hwtypes[] ALIGN_PTR = { &loop_hwtype, ðer_hwtype, &ppp_hwtype, diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 17a838411..ecc3848ff 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -58,7 +58,7 @@ typedef struct filter_t filter_t; static void print_link_flags(unsigned flags, unsigned mdown) { - static const int flag_masks[] = { + static const int flag_masks[] ALIGN_INT = { IFF_LOOPBACK, IFF_BROADCAST, IFF_POINTOPOINT, IFF_MULTICAST, IFF_NOARP, IFF_UP, IFF_LOWER_UP }; static const char flag_labels[] ALIGN1 = diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 8e9b93655..ae818db05 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c @@ -19,7 +19,7 @@ const uint8_t MAC_BCAST_ADDR[6] ALIGN2 = { * See RFC2132 for more options. * OPTION_REQ: these options are requested by udhcpc (unless -o). */ -const struct dhcp_optflag dhcp_optflags[] = { +const struct dhcp_optflag dhcp_optflags[] ALIGN2 = { /* flags code */ { OPTION_IP | OPTION_REQ, 0x01 }, /* DHCP_SUBNET */ { OPTION_S32 , 0x02 }, /* DHCP_TIME_OFFSET */ diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 9d2a8f5d3..9fc690315 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c @@ -65,7 +65,7 @@ /* "struct client_data_t client_data" is in bb_common_bufsiz1 */ -static const struct dhcp_optflag d6_optflags[] = { +static const struct dhcp_optflag d6_optflags[] ALIGN2 = { #if ENABLE_FEATURE_UDHCPC6_RFC3646 { OPTION_6RD | OPTION_LIST | OPTION_REQ, D6_OPT_DNS_SERVERS }, { OPTION_DNS_STRING | OPTION_LIST | OPTION_REQ, D6_OPT_DOMAIN_LIST }, diff --git a/shell/ash.c b/shell/ash.c index 55df54bd0..adb0f223a 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -313,7 +313,7 @@ typedef long arith_t; /* ============ Shell options */ /* If you add/change options hare, update --help text too */ -static const char *const optletters_optnames[] = { +static const char *const optletters_optnames[] ALIGN_PTR = { "e" "errexit", "f" "noglob", /* bash has '-o ignoreeof', but no short synonym -I for it */ diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c index 57e7e8db7..307a84803 100644 --- a/util-linux/hexdump.c +++ b/util-linux/hexdump.c @@ -71,7 +71,7 @@ static void bb_dump_addfile(dumper_t *dumper, char *name) fclose(fp); } -static const char *const add_strings[] = { +static const char *const add_strings[] ALIGN_PTR = { "\"%07.7_ax \"16/1 \"%03o \"\"\n\"", /* b */ "\"%07.7_ax \"16/1 \"%3_c \"\"\n\"", /* c */ "\"%07.7_ax \"8/2 \" %05u \"\"\n\"", /* d */ diff --git a/util-linux/nsenter.c b/util-linux/nsenter.c index e6339da2f..1aa045b35 100644 --- a/util-linux/nsenter.c +++ b/util-linux/nsenter.c @@ -93,7 +93,7 @@ enum { * The user namespace comes first, so that it is entered first. * This gives an unprivileged user the potential to enter other namespaces. */ -static const struct namespace_descr ns_list[] = { +static const struct namespace_descr ns_list[] ALIGN_INT = { { CLONE_NEWUSER, "ns/user", }, { CLONE_NEWIPC, "ns/ipc", }, { CLONE_NEWUTS, "ns/uts", }, diff --git a/util-linux/unshare.c b/util-linux/unshare.c index 68ccdd874..06b938074 100644 --- a/util-linux/unshare.c +++ b/util-linux/unshare.c @@ -120,7 +120,7 @@ enum { NS_USR_POS, /* OPT_user, NS_USR_POS, and ns_list[] index must match! */ NS_COUNT, }; -static const struct namespace_descr ns_list[] = { +static const struct namespace_descr ns_list[] ALIGN_INT = { { CLONE_NEWNS, "mnt" }, { CLONE_NEWUTS, "uts" }, { CLONE_NEWIPC, "ipc" }, -- cgit v1.2.3-55-g6feb From 987be932ed3cbea56b68bbe85649191c13b66015 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 6 Feb 2022 20:07:12 +0100 Subject: *: slap on a few ALIGN_PTR where appropriate Signed-off-by: Denys Vlasenko --- coreutils/test.c | 2 +- e2fsprogs/fsck.c | 2 +- libbb/getopt32.c | 2 +- miscutils/devfsd.c | 4 ++-- modutils/modutils-24.c | 4 ++-- networking/inetd.c | 2 +- procps/nmeter.c | 2 +- selinux/setenforce.c | 2 +- shell/hush.c | 10 +++++----- 9 files changed, 15 insertions(+), 15 deletions(-) (limited to 'shell') diff --git a/coreutils/test.c b/coreutils/test.c index a914c7490..840a0daaf 100644 --- a/coreutils/test.c +++ b/coreutils/test.c @@ -242,7 +242,7 @@ int depth; depth--; \ return __res; \ } while (0) -static const char *const TOKSTR[] = { +static const char *const TOKSTR[] ALIGN_PTR = { "EOI", "FILRD", "FILWR", diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index 96c1e51e0..028f8a803 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c @@ -190,7 +190,7 @@ struct globals { * Required for the uber-silly devfs /dev/ide/host1/bus2/target3/lun3 * pathames. */ -static const char *const devfs_hier[] = { +static const char *const devfs_hier[] ALIGN_PTR = { "host", "bus", "target", "lun", NULL }; #endif diff --git a/libbb/getopt32.c b/libbb/getopt32.c index 5ab4d66f1..e861d0567 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c @@ -296,7 +296,7 @@ Special characters: /* Code here assumes that 'unsigned' is at least 32 bits wide */ -const char *const bb_argv_dash[] = { "-", NULL }; +const char *const bb_argv_dash[] ALIGN_PTR = { "-", NULL }; enum { PARAM_STRING, diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index 839d00fd0..fb9ebcf60 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c @@ -928,7 +928,7 @@ static void action_compat(const struct devfsd_notify_struct *info, unsigned int unsigned int i; char rewind_; /* 1 to 5 "scsi/" , 6 to 9 "ide/host" */ - static const char *const fmt[] = { + static const char *const fmt[] ALIGN_PTR = { NULL , "sg/c%db%dt%du%d", /* scsi/generic */ "sd/c%db%dt%du%d", /* scsi/disc */ @@ -1468,7 +1468,7 @@ const char *get_old_name(const char *devname, unsigned int namelen, const char *pty1; const char *pty2; /* 1 to 5 "scsi/" , 6 to 9 "ide/host", 10 sbp/, 11 vcc/, 12 pty/ */ - static const char *const fmt[] = { + static const char *const fmt[] ALIGN_PTR = { NULL , "sg%u", /* scsi/generic */ NULL, /* scsi/disc */ diff --git a/modutils/modutils-24.c b/modutils/modutils-24.c index ac8632481..d0bc2a6ef 100644 --- a/modutils/modutils-24.c +++ b/modutils/modutils-24.c @@ -3458,7 +3458,7 @@ static int obj_load_progbits(char *image, size_t image_size, struct obj_file *f, static void hide_special_symbols(struct obj_file *f) { - static const char *const specials[] = { + static const char *const specials[] ALIGN_PTR = { SPFX "cleanup_module", SPFX "init_module", SPFX "kernel_version", @@ -3484,7 +3484,7 @@ static int obj_gpl_license(struct obj_file *f, const char **license) * linux/include/linux/module.h. Checking for leading "GPL" will not * work, somebody will use "GPL sucks, this is proprietary". */ - static const char *const gpl_licenses[] = { + static const char *const gpl_licenses[] ALIGN_PTR = { "GPL", "GPL v2", "GPL and additional rights", diff --git a/networking/inetd.c b/networking/inetd.c index e71be51c3..fb2fbe323 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -1538,7 +1538,7 @@ int inetd_main(int argc UNUSED_PARAM, char **argv) #if ENABLE_FEATURE_INETD_SUPPORT_BUILTIN_ECHO \ || ENABLE_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD # if !BB_MMU -static const char *const cat_args[] = { "cat", NULL }; +static const char *const cat_args[] ALIGN_PTR = { "cat", NULL }; # endif #endif diff --git a/procps/nmeter.c b/procps/nmeter.c index 2310e9844..088d366bf 100644 --- a/procps/nmeter.c +++ b/procps/nmeter.c @@ -70,7 +70,7 @@ typedef struct proc_file { smallint last_gen; } proc_file; -static const char *const proc_name[] = { +static const char *const proc_name[] ALIGN_PTR = { "stat", // Must match the order of proc_file's! "loadavg", "net/dev", diff --git a/selinux/setenforce.c b/selinux/setenforce.c index 996034f8e..2267be451 100644 --- a/selinux/setenforce.c +++ b/selinux/setenforce.c @@ -26,7 +26,7 @@ /* These strings are arranged so that odd ones * result in security_setenforce(1) being done, * the rest will do security_setenforce(0) */ -static const char *const setenforce_cmd[] = { +static const char *const setenforce_cmd[] ALIGN_PTR = { "0", "1", "permissive", diff --git a/shell/hush.c b/shell/hush.c index 6dc2ecaac..ae81f0da5 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -564,7 +564,7 @@ enum { #define NULL_O_STRING { NULL } #ifndef debug_printf_parse -static const char *const assignment_flag[] = { +static const char *const assignment_flag[] ALIGN_PTR = { "MAYBE_ASSIGNMENT", "DEFINITELY_ASSIGNMENT", "NOT_ASSIGNMENT", @@ -3682,7 +3682,7 @@ static void free_pipe_list(struct pipe *pi) #ifndef debug_print_tree static void debug_print_tree(struct pipe *pi, int lvl) { - static const char *const PIPE[] = { + static const char *const PIPE[] ALIGN_PTR = { [PIPE_SEQ] = "SEQ", [PIPE_AND] = "AND", [PIPE_OR ] = "OR" , @@ -3717,7 +3717,7 @@ static void debug_print_tree(struct pipe *pi, int lvl) [RES_XXXX ] = "XXXX" , [RES_SNTX ] = "SNTX" , }; - static const char *const CMDTYPE[] = { + static const char *const CMDTYPE[] ALIGN_PTR = { "{}", "()", "[noglob]", @@ -7659,7 +7659,7 @@ static int generate_stream_from_string(const char *s, pid_t *pid_p) if (is_prefixed_with(s, "trap") && skip_whitespace(s + 4)[0] == '\0' ) { - static const char *const argv[] = { NULL, NULL }; + static const char *const argv[] ALIGN_PTR = { NULL, NULL }; builtin_trap((char**)argv); fflush_all(); /* important */ _exit(0); @@ -9826,7 +9826,7 @@ static int run_list(struct pipe *pi) static const char encoded_dollar_at[] ALIGN1 = { SPECIAL_VAR_SYMBOL, '@' | 0x80, SPECIAL_VAR_SYMBOL, '\0' }; /* encoded representation of "$@" */ - static const char *const encoded_dollar_at_argv[] = { + static const char *const encoded_dollar_at_argv[] ALIGN_PTR = { encoded_dollar_at, NULL }; /* argv list with one element: "$@" */ char **vals; -- cgit v1.2.3-55-g6feb