aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-12-13 22:00:56 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-12-13 22:00:56 +0100
commit63139b531f7f1d71d8274810b163da1a78d4609e (patch)
tree94719fa121457162e30ce0025db6a2174a3f7ab2
parent1b367cbeda9447d771b09831c1e9c83cadbee55e (diff)
downloadbusybox-w32-63139b531f7f1d71d8274810b163da1a78d4609e.tar.gz
busybox-w32-63139b531f7f1d71d8274810b163da1a78d4609e.tar.bz2
busybox-w32-63139b531f7f1d71d8274810b163da1a78d4609e.zip
hush: if login shell, also source ~/.profile
function old new delta hush_main 1101 1151 +50 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/shell/hush.c b/shell/hush.c
index f9b5623fd..ba9540c98 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -9992,7 +9992,9 @@ int hush_main(int argc, char **argv)
9992 OPT_login = (1 << 0), 9992 OPT_login = (1 << 0),
9993 }; 9993 };
9994 unsigned flags; 9994 unsigned flags;
9995 unsigned builtin_argc; 9995#if !BB_MMU
9996 unsigned builtin_argc = 0;
9997#endif
9996 char **e; 9998 char **e;
9997 struct variable *cur_var; 9999 struct variable *cur_var;
9998 struct variable *shell_ver; 10000 struct variable *shell_ver;
@@ -10122,7 +10124,6 @@ int hush_main(int argc, char **argv)
10122 /* Parse options */ 10124 /* Parse options */
10123 /* http://www.opengroup.org/onlinepubs/9699919799/utilities/sh.html */ 10125 /* http://www.opengroup.org/onlinepubs/9699919799/utilities/sh.html */
10124 flags = (argv[0] && argv[0][0] == '-') ? OPT_login : 0; 10126 flags = (argv[0] && argv[0][0] == '-') ? OPT_login : 0;
10125 builtin_argc = 0;
10126 while (1) { 10127 while (1) {
10127 int opt = getopt(argc, argv, "+cexinsl" 10128 int opt = getopt(argc, argv, "+cexinsl"
10128#if !BB_MMU 10129#if !BB_MMU
@@ -10222,13 +10223,7 @@ int hush_main(int argc, char **argv)
10222 if (set_mode(1, opt, NULL) == 0) /* no error */ 10223 if (set_mode(1, opt, NULL) == 0) /* no error */
10223 break; 10224 break;
10224 default: 10225 default:
10225#ifndef BB_VER
10226 fprintf(stderr, "Usage: sh [FILE]...\n"
10227 " or: sh -c command [args]...\n\n");
10228 exit(EXIT_FAILURE);
10229#else
10230 bb_show_usage(); 10226 bb_show_usage();
10231#endif
10232 } 10227 }
10233 } /* option parsing loop */ 10228 } /* option parsing loop */
10234 10229
@@ -10244,9 +10239,12 @@ int hush_main(int argc, char **argv)
10244 10239
10245 /* If we are login shell... */ 10240 /* If we are login shell... */
10246 if (flags & OPT_login) { 10241 if (flags & OPT_login) {
10242 const char *hp = NULL;
10247 HFILE *input; 10243 HFILE *input;
10244
10248 debug_printf("sourcing /etc/profile\n"); 10245 debug_printf("sourcing /etc/profile\n");
10249 input = hfopen("/etc/profile"); 10246 input = hfopen("/etc/profile");
10247 run_profile:
10250 if (input != NULL) { 10248 if (input != NULL) {
10251 install_special_sighandlers(); 10249 install_special_sighandlers();
10252 parse_and_run_file(input); 10250 parse_and_run_file(input);
@@ -10259,6 +10257,16 @@ int hush_main(int argc, char **argv)
10259 * bash also sources ~/.bash_logout on exit. 10257 * bash also sources ~/.bash_logout on exit.
10260 * If called as sh, skips .bash_XXX files. 10258 * If called as sh, skips .bash_XXX files.
10261 */ 10259 */
10260 if (!hp) { /* unless we looped on the "goto" already */
10261 hp = get_local_var_value("HOME");
10262 if (hp && hp[0]) {
10263 debug_printf("sourcing ~/.profile\n");
10264 hp = concat_path_file(hp, ".profile");
10265 input = hfopen(hp);
10266 free((char*)hp);
10267 goto run_profile;
10268 }
10269 }
10262 } 10270 }
10263 10271
10264 /* -c takes effect *after* -l */ 10272 /* -c takes effect *after* -l */