aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorJames Byrne <james.byrne@origamienergy.com>2019-07-02 11:35:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-07-02 11:35:03 +0200
commit6937487be73cd4563b876413277a295a5fe2f32c (patch)
treef16cc9999a7c827891e6ec8d99c699fc791008ee /shell
parentcaecfdc20d450686cd1f7e9b5f650322f894b3c2 (diff)
downloadbusybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.tar.gz
busybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.tar.bz2
busybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.zip
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c32
-rw-r--r--shell/shell_common.c2
2 files changed, 17 insertions, 17 deletions
diff --git a/shell/hush.c b/shell/hush.c
index f82747f74..19b97e2a5 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1398,7 +1398,7 @@ static void syntax_error(unsigned lineno UNUSED_PARAM, const char *msg)
1398 if (msg) 1398 if (msg)
1399 bb_error_msg("syntax error: %s", msg); 1399 bb_error_msg("syntax error: %s", msg);
1400 else 1400 else
1401 bb_error_msg("syntax error"); 1401 bb_simple_error_msg("syntax error");
1402 die_if_script(); 1402 die_if_script();
1403} 1403}
1404 1404
@@ -1637,7 +1637,7 @@ static int refill_HFILE_and_getc(HFILE *fp)
1637 fp->cur = fp->buf; 1637 fp->cur = fp->buf;
1638 n = safe_read(fp->fd, fp->buf, sizeof(fp->buf)); 1638 n = safe_read(fp->fd, fp->buf, sizeof(fp->buf));
1639 if (n < 0) { 1639 if (n < 0) {
1640 bb_perror_msg("read error"); 1640 bb_simple_perror_msg("read error");
1641 n = 0; 1641 n = 0;
1642 } 1642 }
1643 fp->end = fp->buf + n; 1643 fp->end = fp->buf + n;
@@ -2282,7 +2282,7 @@ static int set_local_var(char *str, unsigned flags)
2282 2282
2283 eq_sign = strchr(str, '='); 2283 eq_sign = strchr(str, '=');
2284 if (HUSH_DEBUG && !eq_sign) 2284 if (HUSH_DEBUG && !eq_sign)
2285 bb_error_msg_and_die("BUG in setvar"); 2285 bb_simple_error_msg_and_die("BUG in setvar");
2286 2286
2287 name_len = eq_sign - str + 1; /* including '=' */ 2287 name_len = eq_sign - str + 1; /* including '=' */
2288 cur_pp = &G.top_var; 2288 cur_pp = &G.top_var;
@@ -2505,7 +2505,7 @@ static void set_vars_and_save_old(char **strings)
2505 2505
2506 eq = strchr(*s, '='); 2506 eq = strchr(*s, '=');
2507 if (HUSH_DEBUG && !eq) 2507 if (HUSH_DEBUG && !eq)
2508 bb_error_msg_and_die("BUG in varexp4"); 2508 bb_simple_error_msg_and_die("BUG in varexp4");
2509 var_pp = get_ptr_to_local_var(*s, eq - *s); 2509 var_pp = get_ptr_to_local_var(*s, eq - *s);
2510 if (var_pp) { 2510 if (var_pp) {
2511 var_p = *var_pp; 2511 var_p = *var_pp;
@@ -4246,7 +4246,7 @@ static int parse_redir_right_fd(o_string *as_string, struct in_str *input)
4246 4246
4247//TODO: this is the place to catch ">&file" bashism (redirect both fd 1 and 2) 4247//TODO: this is the place to catch ">&file" bashism (redirect both fd 1 and 2)
4248 4248
4249 bb_error_msg("ambiguous redirect"); 4249 bb_simple_error_msg("ambiguous redirect");
4250 return REDIRFD_SYNTAX_ERR; 4250 return REDIRFD_SYNTAX_ERR;
4251} 4251}
4252 4252
@@ -6956,7 +6956,7 @@ static char *expand_string_to_string(const char *str, int EXP_flags, int do_unba
6956 } else { 6956 } else {
6957 if (HUSH_DEBUG) 6957 if (HUSH_DEBUG)
6958 if (list[1]) 6958 if (list[1])
6959 bb_error_msg_and_die("BUG in varexp2"); 6959 bb_simple_error_msg_and_die("BUG in varexp2");
6960 /* actually, just move string 2*sizeof(char*) bytes back */ 6960 /* actually, just move string 2*sizeof(char*) bytes back */
6961 overlapping_strcpy((char*)list, list[0]); 6961 overlapping_strcpy((char*)list, list[0]);
6962 if (do_unbackslash) 6962 if (do_unbackslash)
@@ -7217,7 +7217,7 @@ static void re_execute_shell(char ***to_free, const char *s,
7217 if (argv[0][0] == '/') 7217 if (argv[0][0] == '/')
7218 execve(argv[0], argv, pp); 7218 execve(argv[0], argv, pp);
7219 xfunc_error_retval = 127; 7219 xfunc_error_retval = 127;
7220 bb_error_msg_and_die("can't re-execute the shell"); 7220 bb_simple_error_msg_and_die("can't re-execute the shell");
7221} 7221}
7222#endif /* !BB_MMU */ 7222#endif /* !BB_MMU */
7223 7223
@@ -7919,7 +7919,7 @@ static void leave_var_nest_level(void)
7919 G.var_nest_level--; 7919 G.var_nest_level--;
7920 debug_printf_env("var_nest_level-- %u\n", G.var_nest_level); 7920 debug_printf_env("var_nest_level-- %u\n", G.var_nest_level);
7921 if (HUSH_DEBUG && (int)G.var_nest_level < 0) 7921 if (HUSH_DEBUG && (int)G.var_nest_level < 0)
7922 bb_error_msg_and_die("BUG: nesting underflow"); 7922 bb_simple_error_msg_and_die("BUG: nesting underflow");
7923 7923
7924 remove_nested_vars(); 7924 remove_nested_vars();
7925} 7925}
@@ -8776,7 +8776,7 @@ static int checkjobs(struct pipe *fg_pipe, pid_t waitfor_pid)
8776 childpid = waitpid(-1, &status, attributes); 8776 childpid = waitpid(-1, &status, attributes);
8777 if (childpid <= 0) { 8777 if (childpid <= 0) {
8778 if (childpid && errno != ECHILD) 8778 if (childpid && errno != ECHILD)
8779 bb_perror_msg("waitpid"); 8779 bb_simple_perror_msg("waitpid");
8780#if ENABLE_HUSH_FAST 8780#if ENABLE_HUSH_FAST
8781 else { /* Until next SIGCHLD, waitpid's are useless */ 8781 else { /* Until next SIGCHLD, waitpid's are useless */
8782 G.we_have_children = (childpid == 0); 8782 G.we_have_children = (childpid == 0);
@@ -9308,7 +9308,7 @@ static NOINLINE int run_pipe(struct pipe *pi)
9308 argv_expanded = NULL; 9308 argv_expanded = NULL;
9309 if (command->pid < 0) { /* [v]fork failed */ 9309 if (command->pid < 0) { /* [v]fork failed */
9310 /* Clearly indicate, was it fork or vfork */ 9310 /* Clearly indicate, was it fork or vfork */
9311 bb_perror_msg(BB_MMU ? "vfork"+1 : "vfork"); 9311 bb_simple_perror_msg(BB_MMU ? "vfork"+1 : "vfork");
9312 } else { 9312 } else {
9313 pi->alive_cmds++; 9313 pi->alive_cmds++;
9314#if ENABLE_HUSH_JOB 9314#if ENABLE_HUSH_JOB
@@ -10617,7 +10617,7 @@ static int FAST_FUNC builtin_read(char **argv)
10617 } 10617 }
10618 10618
10619 if ((uintptr_t)r > 1) { 10619 if ((uintptr_t)r > 1) {
10620 bb_error_msg("%s", r); 10620 bb_simple_error_msg(r);
10621 r = (char*)(uintptr_t)1; 10621 r = (char*)(uintptr_t)1;
10622 } 10622 }
10623 10623
@@ -10862,7 +10862,7 @@ static int FAST_FUNC builtin_unset(char **argv)
10862 if (opts == (unsigned)-1) 10862 if (opts == (unsigned)-1)
10863 return EXIT_FAILURE; 10863 return EXIT_FAILURE;
10864 if (opts == 3) { 10864 if (opts == 3) {
10865 bb_error_msg("unset: -v and -f are exclusive"); 10865 bb_simple_error_msg("unset: -v and -f are exclusive");
10866 return EXIT_FAILURE; 10866 return EXIT_FAILURE;
10867 } 10867 }
10868 argv += optind; 10868 argv += optind;
@@ -11025,7 +11025,7 @@ Test that VAR is a valid variable name?
11025 11025
11026 optstring = *++argv; 11026 optstring = *++argv;
11027 if (!optstring || !(var = *++argv)) { 11027 if (!optstring || !(var = *++argv)) {
11028 bb_error_msg("usage: getopts OPTSTRING VAR [ARGS]"); 11028 bb_simple_error_msg("usage: getopts OPTSTRING VAR [ARGS]");
11029 return EXIT_FAILURE; 11029 return EXIT_FAILURE;
11030 } 11030 }
11031 11031
@@ -11254,7 +11254,7 @@ static int FAST_FUNC builtin_trap(char **argv)
11254 } 11254 }
11255 11255
11256 if (!argv[1]) { /* no second arg */ 11256 if (!argv[1]) { /* no second arg */
11257 bb_error_msg("trap: invalid arguments"); 11257 bb_simple_error_msg("trap: invalid arguments");
11258 return EXIT_FAILURE; 11258 return EXIT_FAILURE;
11259 } 11259 }
11260 11260
@@ -11295,7 +11295,7 @@ static struct pipe *parse_jobspec(const char *str)
11295 /* It is "%%", "%+" or "%" - current job */ 11295 /* It is "%%", "%+" or "%" - current job */
11296 jobnum = G.last_jobid; 11296 jobnum = G.last_jobid;
11297 if (jobnum == 0) { 11297 if (jobnum == 0) {
11298 bb_error_msg("no current job"); 11298 bb_simple_error_msg("no current job");
11299 return NULL; 11299 return NULL;
11300 } 11300 }
11301 } 11301 }
@@ -11372,7 +11372,7 @@ static int FAST_FUNC builtin_fg_bg(char **argv)
11372 delete_finished_job(pi); 11372 delete_finished_job(pi);
11373 return EXIT_SUCCESS; 11373 return EXIT_SUCCESS;
11374 } 11374 }
11375 bb_perror_msg("kill (SIGCONT)"); 11375 bb_simple_perror_msg("kill (SIGCONT)");
11376 } 11376 }
11377 11377
11378 if (argv[0][0] == 'f') { 11378 if (argv[0][0] == 'f') {
diff --git a/shell/shell_common.c b/shell/shell_common.c
index e0582adfb..a93533903 100644
--- a/shell/shell_common.c
+++ b/shell/shell_common.c
@@ -619,7 +619,7 @@ shell_builtin_ulimit(char **argv)
619 limit.rlim_cur = val; 619 limit.rlim_cur = val;
620//bb_error_msg("setrlimit(%d, %lld, %lld)", limits_tbl[i].cmd, (long long)limit.rlim_cur, (long long)limit.rlim_max); 620//bb_error_msg("setrlimit(%d, %lld, %lld)", limits_tbl[i].cmd, (long long)limit.rlim_cur, (long long)limit.rlim_max);
621 if (setrlimit(limits_tbl[i].cmd, &limit) < 0) { 621 if (setrlimit(limits_tbl[i].cmd, &limit) < 0) {
622 bb_perror_msg("error setting limit"); 622 bb_simple_perror_msg("error setting limit");
623 return EXIT_FAILURE; 623 return EXIT_FAILURE;
624 } 624 }
625 } 625 }