From 1961aea305e258ba7ab3910d084451220f55ed44 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 26 Feb 2013 00:36:53 +0100 Subject: move endofname() to libbb Signed-off-by: Denys Vlasenko --- shell/ash.c | 24 +++--------------------- shell/math.c | 12 ------------ shell/math.h | 5 ----- 3 files changed, 3 insertions(+), 38 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 31fbc550a..0b5111a39 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -385,6 +385,9 @@ static void trace_vprintf(const char *fmt, va_list va); /* ============ Utility functions */ #define xbarrier() do { __asm__ __volatile__ ("": : :"memory"); } while (0) +#define is_name(c) ((c) == '_' || isalpha((unsigned char)(c))) +#define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c))) + static int isdigit_str9(const char *str) { int maxlen = 9 + 1; /* max 9 digits: 999999999 */ @@ -2008,27 +2011,6 @@ getoptsreset(const char *value) } #endif -/* math.h has these, otherwise define our private copies */ -#if !ENABLE_SH_MATH_SUPPORT -#define is_name(c) ((c) == '_' || isalpha((unsigned char)(c))) -#define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c))) -/* - * Return the pointer to the first char which is not part of a legal variable name - * (a letter or underscore followed by letters, underscores, and digits). - */ -static const char* -endofname(const char *name) -{ - if (!is_name(*name)) - return name; - while (*++name) { - if (!is_in_name(*name)) - break; - } - return name; -} -#endif - /* * Compares two strings up to the first = or '\0'. The first * string must be terminated by '='; the second may be terminated by diff --git a/shell/math.c b/shell/math.c index 15c003965..3da151137 100644 --- a/shell/math.c +++ b/shell/math.c @@ -494,18 +494,6 @@ static const char op_tokens[] ALIGN1 = { }; #define ptr_to_rparen (&op_tokens[sizeof(op_tokens)-7]) -const char* FAST_FUNC -endofname(const char *name) -{ - if (!is_name(*name)) - return name; - while (*++name) { - if (!is_in_name(*name)) - break; - } - return name; -} - static arith_t FAST_FUNC evaluate_string(arith_state_t *math_state, const char *expr) { diff --git a/shell/math.h b/shell/math.h index 2d305eb12..864bee691 100644 --- a/shell/math.h +++ b/shell/math.h @@ -73,11 +73,6 @@ typedef long arith_t; #define strto_arith_t strtoul #endif -/* ash's and hush's endofname is the same, so... */ -# define is_name(c) ((c) == '_' || isalpha((unsigned char)(c))) -# define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c))) -const char* FAST_FUNC endofname(const char *name); - typedef const char* FAST_FUNC (*arith_var_lookup_t)(const char *name); typedef void FAST_FUNC (*arith_var_set_t)(const char *name, const char *val); //typedef const char* FAST_FUNC (*arith_var_endofname_t)(const char *name); -- cgit v1.2.3-55-g6feb From aeb717aa5e8a5ae650a283306091a2872628cffd Mon Sep 17 00:00:00 2001 From: Stefan Hellermann Date: Sun, 3 Mar 2013 15:29:32 +0100 Subject: ash: move code to allow setting $HOME in /etc/profile move HISTFILE=$HOME/.ash_history below reading /etc/profile, so that /etc/profile can set $HOME. HOME can be unset when directly invoking ash --login from init without going through getty. Signed-off-by: Stefan Hellermann Signed-off-by: Denys Vlasenko --- shell/ash.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 0b5111a39..5f09fd474 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -13191,19 +13191,6 @@ int ash_main(int argc UNUSED_PARAM, char **argv) setstackmark(&smark); procargs(argv); -#if ENABLE_FEATURE_EDITING_SAVEHISTORY - if (iflag) { - const char *hp = lookupvar("HISTFILE"); - if (!hp) { - hp = lookupvar("HOME"); - if (hp) { - char *defhp = concat_path_file(hp, ".ash_history"); - setvar("HISTFILE", defhp, 0); - free(defhp); - } - } - } -#endif if (argv[0] && argv[0][0] == '-') isloginsh = 1; if (isloginsh) { @@ -13243,6 +13230,15 @@ int ash_main(int argc UNUSED_PARAM, char **argv) #if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY if (iflag) { const char *hp = lookupvar("HISTFILE"); + if (!hp) { + hp = lookupvar("HOME"); + if(hp) { + hp = concat_path_file(hp, ".ash_history"); + setvar("HISTFILE", hp, 0); + free((char*)hp); + hp = lookupvar("HISTFILE"); + } + } if (hp) line_input_state->hist_file = hp; # if ENABLE_FEATURE_SH_HISTFILESIZE -- cgit v1.2.3-55-g6feb From 4ef1439c593daadeffb3f00eaaf49e190a3039e1 Mon Sep 17 00:00:00 2001 From: Stefan Hellermann Date: Fri, 15 Mar 2013 02:45:50 +0100 Subject: ash: read $HOME/.profile instead of $(pwd)/.profile ash --login should read ~/.profile instead of .profile in the current directory. I noticed it while trying to figure out why /root/.profile is only read sometimes. function old new delta ash_main 1374 1398 +24 Signed-off-by: Stefan Hellermann Signed-off-by: Denys Vlasenko --- shell/ash.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 5f09fd474..fbbdb06b0 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -13194,11 +13194,18 @@ int ash_main(int argc UNUSED_PARAM, char **argv) if (argv[0] && argv[0][0] == '-') isloginsh = 1; if (isloginsh) { + const char *hp; + state = 1; read_profile("/etc/profile"); state1: state = 2; - read_profile(".profile"); + hp = lookupvar("HOME"); + if (hp) { + hp = concat_path_file(hp, ".profile"); + read_profile(hp); + free((char*)hp); + } } state2: state = 3; @@ -13232,7 +13239,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv) const char *hp = lookupvar("HISTFILE"); if (!hp) { hp = lookupvar("HOME"); - if(hp) { + if (hp) { hp = concat_path_file(hp, ".ash_history"); setvar("HISTFILE", hp, 0); free((char*)hp); -- cgit v1.2.3-55-g6feb From 88b532d59af81f3b788864b2d6d42e1f86bc8de0 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 17 Mar 2013 14:11:04 +0100 Subject: hush: source builtin should override $N only if it has args function old new delta builtin_source 174 184 +10 Signed-off-by: Denys Vlasenko --- shell/hush.c | 9 +++++++-- shell/hush_test/hush-misc/source2.right | 4 ++++ shell/hush_test/hush-misc/source2.tests | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 shell/hush_test/hush-misc/source2.right create mode 100755 shell/hush_test/hush-misc/source2.tests (limited to 'shell') diff --git a/shell/hush.c b/shell/hush.c index e2dc1e2d0..b23325725 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -8880,6 +8880,9 @@ static int FAST_FUNC builtin_source(char **argv) free(arg_path); if (!input) { /* bb_perror_msg("%s", *argv); - done by fopen_or_warn */ + /* POSIX: non-interactive shell should abort here, + * not merely fail. So far no one complained :) + */ return EXIT_FAILURE; } close_on_exec_on(fileno(input)); @@ -8889,12 +8892,14 @@ static int FAST_FUNC builtin_source(char **argv) /* "we are inside sourced file, ok to use return" */ G.flag_return_in_progress = -1; #endif - save_and_replace_G_args(&sv, argv); + if (argv[1]) + save_and_replace_G_args(&sv, argv); parse_and_run_file(input); fclose(input); - restore_G_args(&sv, argv); + if (argv[1]) + restore_G_args(&sv, argv); #if ENABLE_HUSH_FUNCTIONS G.flag_return_in_progress = sv_flg; #endif diff --git a/shell/hush_test/hush-misc/source2.right b/shell/hush_test/hush-misc/source2.right new file mode 100644 index 000000000..0587bad67 --- /dev/null +++ b/shell/hush_test/hush-misc/source2.right @@ -0,0 +1,4 @@ +0:arg0 1:arg1 2:arg2 +Ok1:0 +0:arg0 1:q 2:w +Ok2:0 diff --git a/shell/hush_test/hush-misc/source2.tests b/shell/hush_test/hush-misc/source2.tests new file mode 100755 index 000000000..40b6b83cd --- /dev/null +++ b/shell/hush_test/hush-misc/source2.tests @@ -0,0 +1,8 @@ +echo 'echo "0:$0 1:$1 2:$2"' >sourced1 +set -- 1 2 3 +"$THIS_SH" -c '. ./sourced1' arg0 arg1 arg2 +echo Ok1:$? +"$THIS_SH" -c '. ./sourced1 q w e' arg0 arg1 arg2 +echo Ok2:$? + +rm sourced1 -- cgit v1.2.3-55-g6feb From 091f831424e8aa2052484ef07f0225f5405d086f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 17 Mar 2013 14:25:22 +0100 Subject: ash: add comment about failures in source builtin. No code changes. Signed-off-by: Denys Vlasenko --- shell/ash.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index fbbdb06b0..edcb7c028 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -12258,6 +12258,9 @@ dotcmd(int argc, char **argv) /* "false; . empty_file; echo $?" should print 0, not 1: */ exitstatus = 0; + /* This aborts if file isn't found, which is POSIXly correct. + * bash returns exitcode 1 instead. + */ fullname = find_dot_file(argv[1]); argv += 2; @@ -12269,6 +12272,9 @@ dotcmd(int argc, char **argv) shellparam.p = argv; }; + /* This aborts if file can't be opened, which is POSIXly correct. + * bash returns exitcode 1 instead. + */ setinputfile(fullname, INPUT_PUSH_FILE); commandname = fullname; cmdloop(0); -- cgit v1.2.3-55-g6feb