[PATCH] squash! Remove some ifndef __U_BOOT__ checks in new hush

Tom Rini trini at konsulko.com
Thu Nov 9 20:12:00 CET 2023


Looking at the code, we had a number of places where the blocks were:
#ifndef __U_BOOT__
...
#endif /* !__U_BOOT__ */

#ifndef __U_BOOT__
...
#endif /* !__U_BOOT__ */

And so we can just remove the center endif/ifndef. If the enclosed
functionality gets ported to U-Boot at some point in the future, then we
can re-enclose things as needed. In a similar manner, we sometimes had:

#ifndef __U_BOOT__
void foo(void)
{
...
#ifndef __U_BOOT__
...
#endif /* !__U_BOOT__ */
...
}
#endif /* !__U_BOOT__ */

And we can remove those inner tests, along the same thinking. If
appropriate later, we can add them when we do whatever else is needed
for that particular hush feature to be functional.

After this it would be good to compare the file with the upstream base
and ensure we don't have any extra empty lines, etc, anywhere.

Signed-off-by: Tom Rini <trini at konsulko.com>
---
 common/cli_hush_upstream.c | 58 +-------------------------------------
 1 file changed, 1 insertion(+), 57 deletions(-)

diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index 709c055d2fdd..de9253c44aac 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -794,14 +794,12 @@ enum {
 	WORD_IS_KEYWORD       = 3,
 };
 
-#ifndef __U_BOOT__
 /* On program start, environ points to initial environment.
  * putenv adds new pointers into it, unsetenv removes them.
  * Neither of these (de)allocates the strings.
  * setenv allocates new strings in malloc space and does putenv,
  * and thus setenv is unusable (leaky) for shell's purposes */
 #define setenv(...) setenv_is_leaky_dont_use()
-#endif /* !__U_BOOT__ */
 struct variable {
 	struct variable *next;
 	char *varstr;        /* points to "name=" portion */
@@ -1004,11 +1002,9 @@ struct globals {
 #endif /* !__U_BOOT__ */
 	unsigned depth_of_loop;
 #endif
-#ifndef __U_BOOT__
 #if ENABLE_HUSH_GETOPTS
 	unsigned getopt_count;
 #endif
-#endif /* !__U_BOOT__ */
 	const char *ifs;
 #ifdef __U_BOOT__
 	int flag_repeat;
@@ -1881,10 +1877,8 @@ static void restore_G_args(save_arg_t *sv, char **argv)
 	G.global_argc = sv->sv_g_argc;
 	IF_HUSH_SET(G.global_args_malloced = sv->sv_g_malloced;)
 }
-#endif /* !__U_BOOT__ */
 
 
-#ifndef __U_BOOT__
 /* Basic theory of signal handling in shell
  * ========================================
  * This does not describe what hush does, rather, it is current understanding
@@ -2077,9 +2071,7 @@ static sighandler_t install_sighandler(int sig, sighandler_t handler)
 	sigaction(sig, &G.sa, &old_sa);
 	return old_sa.sa_handler;
 }
-#endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 static void hush_exit(int exitcode) NORETURN;
 
 static void restore_ttypgrp_and__exit(void) NORETURN;
@@ -2178,9 +2170,7 @@ static sighandler_t pick_sighandler(unsigned sig)
 	}
 	return handler;
 }
-#endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 /* Restores tty foreground process group, and exits. */
 static void hush_exit(int exitcode)
 {
@@ -2416,7 +2406,6 @@ static const char* FAST_FUNC get_local_var_value(const char *name)
 	return NULL;
 }
 
-#ifndef __U_BOOT__
 #if ENABLE_HUSH_GETOPTS
 static void handle_changed_special_names(const char *name)
 {
@@ -2429,19 +2418,13 @@ static void handle_changed_special_names(const char *name)
 /* Do not even bother evaluating arguments */
 # define handle_changed_special_names(...) ((void)0)
 #endif
-#else /* __U_BOOT__ */
-/* Do not even bother evaluating arguments */
-# define handle_changed_special_names(...) ((void)0)
-#endif /* __U_BOOT__ */
 
 /* str holds "NAME=VAL" and is expected to be malloced.
  * We take ownership of it.
  */
-#ifndef __U_BOOT__
 #define SETFLAG_EXPORT   (1 << 0)
 #define SETFLAG_UNEXPORT (1 << 1)
 #define SETFLAG_MAKE_RO  (1 << 2)
-#endif /* !__U_BOOT__ */
 #define SETFLAG_VARLVL_SHIFT   3
 #ifndef __U_BOOT__
 static int set_local_var(char *str, unsigned flags)
@@ -2926,11 +2909,7 @@ static void get_user_input(struct in_str *i)
 		G.flag_repeat = 0;
 	clear_ctrlc();
 	G.do_repeat = 0;
-#ifndef __U_BOOT__
-	if (G.promptmode == 1) {
-#else /* __U_BOOT__ */
 	if (!G.promptmode) {
-#endif /* __U_BOOT__ */
 		if (console_buffer[0] == '\n'&& G.flag_repeat == 0) {
 			strcpy(the_command, console_buffer);
 		}
@@ -2950,7 +2929,6 @@ static void get_user_input(struct in_str *i)
 			if (strlen(the_command) + strlen(console_buffer)
 				< CONFIG_SYS_CBSIZE) {
 				n = strlen(the_command);
-#ifdef __U_BOOT__
 				/*
 				 * To avoid writing to bad places, we check if
 				 * n is greater than 0.
@@ -2959,10 +2937,6 @@ static void get_user_input(struct in_str *i)
 				if (n > 0)
 					the_command[n-1] = ' ';
 				strcpy(&the_command[n], console_buffer);
-#else /* !__U_BOOT__ */
-			the_command[n-1] = ' ';
-			strcpy(&the_command[n], console_buffer);
-#endif /* !__U_BOOT__ */
 				}
 				else {
 					the_command[0] = '\n';
@@ -3014,14 +2988,12 @@ static int fgetc_interactive(struct in_str *i)
 	return ch;
 }
 #else  /* !INTERACTIVE */
-#ifndef __U_BOOT__
 static ALWAYS_INLINE int fgetc_interactive(struct in_str *i)
 {
 	int ch;
 	do ch = hfgetc(i->file); while (ch == '\0');
 	return ch;
 }
-#endif /* !__U_BOOT__ */
 #endif  /* !INTERACTIVE */
 
 static int i_getch(struct in_str *i)
@@ -3323,7 +3295,6 @@ static void nommu_addchr(o_string *o, int ch)
 # define nommu_addchr(o, str) ((void)0)
 #endif
 
-#ifndef __U_BOOT__
 #if ENABLE_HUSH_MODE_X
 static void x_mode_addchr(int ch)
 {
@@ -3354,7 +3325,6 @@ static void x_mode_flush(void)
 	G.x_mode_buf.length = 0;
 }
 #endif
-#endif /* !__U_BOOT__ */
 
 /*
  * HUSH_BRACE_EXPANSION code needs corresponding quoting on variable expansion side.
@@ -3975,12 +3945,10 @@ static struct pipe *free_pipe(struct pipe *pi)
 	}
 	free(pi->cmds);   /* children are an array, they get freed all at once */
 	//pi->cmds = NULL;
-#ifndef __U_BOOT__
 #if ENABLE_HUSH_JOB
 	free(pi->cmdtext);
 	//pi->cmdtext = NULL;
 #endif
-#endif /* !__U_BOOT__ */
 
 	next = pi->next;
 	free(pi);
@@ -4834,11 +4802,7 @@ static char *fetch_till_str(o_string *as_string,
 			nommu_addchr(as_string, ch);
 		if (ch == '\n' || ch == EOF) {
  check_heredoc_end:
-#ifndef __U_BOOT__
 			if ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\') {
-#else /* __U_BOOT__ */
-			if (prev != '\\') {
-#endif
 				/* End-of-line, and not a line continuation */
 				if (strcmp(heredoc.data + past_EOL, word) == 0) {
 					heredoc.data[past_EOL] = '\0';
@@ -4858,11 +4822,7 @@ static char *fetch_till_str(o_string *as_string,
 						ch = i_getch(input);
 						if (ch != EOF)
 							nommu_addchr(as_string, ch);
-#ifndef __U_BOOT__
 					} while ((heredoc_flags & HEREDOC_SKIPTABS) && ch == '\t');
-#else /* __U_BOOT__ */
-				} while (ch == '\t');
-#endif
 					/* If this immediately ended the line,
 					 * go back to end-of-line checks.
 					 */
@@ -6913,7 +6873,6 @@ static NOINLINE int encode_then_append_var_plusminus(o_string *output, int n,
 }
 #endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 #if ENABLE_FEATURE_SH_MATH
 static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p)
 {
@@ -6934,9 +6893,7 @@ static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p)
 	return res;
 }
 #endif
-#endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 #if BASH_PATTERN_SUBST
 /* ${var/[/]pattern[/repl]} helpers */
 static char *strstr_pattern(char *val, const char *pattern, int *size)
@@ -7009,7 +6966,6 @@ static char *replace_pattern(char *val, const char *pattern, const char *repl, c
 	return result;
 }
 #endif /* BASH_PATTERN_SUBST */
-#endif /* !__U_BOOT__ */
 
 static int append_str_maybe_ifs_split(o_string *output, int n,
 		int first_ch, const char *val)
@@ -7800,9 +7756,7 @@ static void switch_off_special_sigs(unsigned mask)
 		install_sighandler(sig, SIG_DFL);
 	}
 }
-#endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 #if BB_MMU
 /* never called */
 void re_execute_shell(char ***to_free, const char *s,
@@ -8153,7 +8107,6 @@ void parse_and_run_file(void)
 #endif /* !__U_BOOT__ */
 }
 
-#ifndef __U_BOOT__
 #if ENABLE_HUSH_TICK
 static int generate_stream_from_string(const char *s, pid_t *pid_p)
 {
@@ -8299,6 +8252,7 @@ static int process_command_subs(o_string *dest, const char *s)
 #endif /* ENABLE_HUSH_TICK */
 
 
+#ifndef __U_BOOT__
 static void setup_heredoc(struct redir_struct *redir)
 {
 	struct fd_pair pair;
@@ -8769,9 +8723,7 @@ static const char * FAST_FUNC hush_command_name(int i)
 	return NULL;
 }
 #endif
-#endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 static void remove_nested_vars(void)
 {
 	struct variable *cur;
@@ -9041,10 +8993,8 @@ static void exec_builtin(char ***to_free,
 			argv);
 #endif
 }
-#endif /* !__U_BOOT__ */
 
 
-#ifndef __U_BOOT__
 static void execvp_or_die(char **argv) NORETURN;
 static void execvp_or_die(char **argv)
 {
@@ -9126,9 +9076,7 @@ static void dump_cmd_in_x_mode(char **argv)
 #else
 # define dump_cmd_in_x_mode(argv) ((void)0)
 #endif
-#endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 #if ENABLE_HUSH_COMMAND
 static void if_command_vV_print_and_exit(char opt_vV, char *cmd, const char *explanation)
 {
@@ -9154,7 +9102,6 @@ static void if_command_vV_print_and_exit(char opt_vV, char *cmd, const char *exp
 #else
 # define if_command_vV_print_and_exit(a,b,c) ((void)0)
 #endif
-#endif /* !__U_BOOT__ */
 
 #if BB_MMU
 #define pseudo_exec_argv(nommu_save, argv, assignment_cnt, argv_expanded) \
@@ -9163,7 +9110,6 @@ static void if_command_vV_print_and_exit(char opt_vV, char *cmd, const char *exp
 	pseudo_exec(command, argv_expanded)
 #endif
 
-#ifndef __U_BOOT__
 /* Called after [v]fork() in run_pipe, or from builtin_exec.
  * Never returns.
  * Don't exit() here.  If you don't exec, use _exit instead.
@@ -11300,7 +11246,6 @@ int hush_main(int argc, char **argv)
 		}
 	}
 
-#ifndef __U_BOOT__
 	/* -c takes effect *after* -l */
 	if (G.opt_c) {
 		/* Possibilities:
@@ -11377,7 +11322,6 @@ int hush_main(int argc, char **argv)
 	/* "implicit" -s: bare interactive hush shows 's' in $- */
 	G.opt_s = 1;
 
-#endif /* __U_BOOT__ */
 	/* Up to here, shell was non-interactive. Now it may become one.
 	 * NB: don't forget to (re)run install_special_sighandlers() as needed.
 	 */
-- 
2.34.1



More information about the U-Boot mailing list