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>
This commit is contained in:
Denys Vlasenko 2020-12-13 22:00:56 +01:00
parent 1b367cbeda
commit 63139b531f

View File

@ -9992,7 +9992,9 @@ int hush_main(int argc, char **argv)
OPT_login = (1 << 0), OPT_login = (1 << 0),
}; };
unsigned flags; unsigned flags;
unsigned builtin_argc; #if !BB_MMU
unsigned builtin_argc = 0;
#endif
char **e; char **e;
struct variable *cur_var; struct variable *cur_var;
struct variable *shell_ver; struct variable *shell_ver;
@ -10122,7 +10124,6 @@ int hush_main(int argc, char **argv)
/* Parse options */ /* Parse options */
/* http://www.opengroup.org/onlinepubs/9699919799/utilities/sh.html */ /* http://www.opengroup.org/onlinepubs/9699919799/utilities/sh.html */
flags = (argv[0] && argv[0][0] == '-') ? OPT_login : 0; flags = (argv[0] && argv[0][0] == '-') ? OPT_login : 0;
builtin_argc = 0;
while (1) { while (1) {
int opt = getopt(argc, argv, "+cexinsl" int opt = getopt(argc, argv, "+cexinsl"
#if !BB_MMU #if !BB_MMU
@ -10222,13 +10223,7 @@ int hush_main(int argc, char **argv)
if (set_mode(1, opt, NULL) == 0) /* no error */ if (set_mode(1, opt, NULL) == 0) /* no error */
break; break;
default: default:
#ifndef BB_VER
fprintf(stderr, "Usage: sh [FILE]...\n"
" or: sh -c command [args]...\n\n");
exit(EXIT_FAILURE);
#else
bb_show_usage(); bb_show_usage();
#endif
} }
} /* option parsing loop */ } /* option parsing loop */
@ -10244,9 +10239,12 @@ int hush_main(int argc, char **argv)
/* If we are login shell... */ /* If we are login shell... */
if (flags & OPT_login) { if (flags & OPT_login) {
const char *hp = NULL;
HFILE *input; HFILE *input;
debug_printf("sourcing /etc/profile\n"); debug_printf("sourcing /etc/profile\n");
input = hfopen("/etc/profile"); input = hfopen("/etc/profile");
run_profile:
if (input != NULL) { if (input != NULL) {
install_special_sighandlers(); install_special_sighandlers();
parse_and_run_file(input); parse_and_run_file(input);
@ -10259,6 +10257,16 @@ int hush_main(int argc, char **argv)
* bash also sources ~/.bash_logout on exit. * bash also sources ~/.bash_logout on exit.
* If called as sh, skips .bash_XXX files. * If called as sh, skips .bash_XXX files.
*/ */
if (!hp) { /* unless we looped on the "goto" already */
hp = get_local_var_value("HOME");
if (hp && hp[0]) {
debug_printf("sourcing ~/.profile\n");
hp = concat_path_file(hp, ".profile");
input = hfopen(hp);
free((char*)hp);
goto run_profile;
}
}
} }
/* -c takes effect *after* -l */ /* -c takes effect *after* -l */