aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 9c61ce618..1deae7c2f 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -328,7 +328,6 @@ struct globals_misc {
328#define EXERROR 1 /* a generic error */ 328#define EXERROR 1 /* a generic error */
329#define EXEXIT 4 /* exit the shell */ 329#define EXEXIT 4 /* exit the shell */
330 330
331 smallint isloginsh;
332 char nullstr[1]; /* zero length string */ 331 char nullstr[1]; /* zero length string */
333 332
334 char optlist[NOPTS]; 333 char optlist[NOPTS];
@@ -397,7 +396,6 @@ extern struct globals_misc *const ash_ptr_to_globals_misc;
397#define pending_int (G_misc.pending_int ) 396#define pending_int (G_misc.pending_int )
398#define got_sigchld (G_misc.got_sigchld ) 397#define got_sigchld (G_misc.got_sigchld )
399#define pending_sig (G_misc.pending_sig ) 398#define pending_sig (G_misc.pending_sig )
400#define isloginsh (G_misc.isloginsh )
401#define nullstr (G_misc.nullstr ) 399#define nullstr (G_misc.nullstr )
402#define optlist (G_misc.optlist ) 400#define optlist (G_misc.optlist )
403#define sigmode (G_misc.sigmode ) 401#define sigmode (G_misc.sigmode )
@@ -10721,7 +10719,7 @@ setoption(int flag, int val)
10721 /* NOTREACHED */ 10719 /* NOTREACHED */
10722} 10720}
10723static int 10721static int
10724options(int cmdline) 10722options(int cmdline, int *login_sh)
10725{ 10723{
10726 char *p; 10724 char *p;
10727 int val; 10725 int val;
@@ -10762,11 +10760,14 @@ options(int cmdline)
10762 if (*argptr) 10760 if (*argptr)
10763 argptr++; 10761 argptr++;
10764 } else if (cmdline && (c == 'l')) { /* -l or +l == --login */ 10762 } else if (cmdline && (c == 'l')) { /* -l or +l == --login */
10765 isloginsh = 1; 10763 if (login_sh)
10764 *login_sh = 1;
10766 /* bash does not accept +-login, we also won't */ 10765 /* bash does not accept +-login, we also won't */
10767 } else if (cmdline && val && (c == '-')) { /* long options */ 10766 } else if (cmdline && val && (c == '-')) { /* long options */
10768 if (strcmp(p, "login") == 0) 10767 if (strcmp(p, "login") == 0) {
10769 isloginsh = 1; 10768 if (login_sh)
10769 *login_sh = 1;
10770 }
10770 break; 10771 break;
10771 } else { 10772 } else {
10772 setoption(c, val); 10773 setoption(c, val);
@@ -10850,7 +10851,7 @@ setcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
10850 return showvars(nullstr, 0, VUNSET); 10851 return showvars(nullstr, 0, VUNSET);
10851 10852
10852 INT_OFF; 10853 INT_OFF;
10853 retval = options(/*cmdline:*/ 0); 10854 retval = options(/*cmdline:*/ 0, NULL);
10854 if (retval == 0) { /* if no parse error... */ 10855 if (retval == 0) { /* if no parse error... */
10855 optschanged(); 10856 optschanged();
10856 if (*argptr != NULL) { 10857 if (*argptr != NULL) {
@@ -13602,21 +13603,23 @@ init(void)
13602/* 13603/*
13603 * Process the shell command line arguments. 13604 * Process the shell command line arguments.
13604 */ 13605 */
13605static void 13606static int
13606procargs(char **argv) 13607procargs(char **argv)
13607{ 13608{
13608 int i; 13609 int i;
13609 const char *xminusc; 13610 const char *xminusc;
13610 char **xargv; 13611 char **xargv;
13612 int login_sh;
13611 13613
13612 xargv = argv; 13614 xargv = argv;
13615 login_sh = xargv[0] && xargv[0][0] == '-';
13613 arg0 = xargv[0]; 13616 arg0 = xargv[0];
13614 /* if (xargv[0]) - mmm, this is always true! */ 13617 /* if (xargv[0]) - mmm, this is always true! */
13615 xargv++; 13618 xargv++;
13616 for (i = 0; i < NOPTS; i++) 13619 for (i = 0; i < NOPTS; i++)
13617 optlist[i] = 2; 13620 optlist[i] = 2;
13618 argptr = xargv; 13621 argptr = xargv;
13619 if (options(/*cmdline:*/ 1)) { 13622 if (options(/*cmdline:*/ 1, &login_sh)) {
13620 /* it already printed err message */ 13623 /* it already printed err message */
13621 raise_exception(EXERROR); 13624 raise_exception(EXERROR);
13622 } 13625 }
@@ -13660,6 +13663,8 @@ procargs(char **argv)
13660 xargv++; 13663 xargv++;
13661 } 13664 }
13662 optschanged(); 13665 optschanged();
13666
13667 return login_sh;
13663} 13668}
13664 13669
13665/* 13670/*
@@ -13720,6 +13725,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
13720 volatile smallint state; 13725 volatile smallint state;
13721 struct jmploc jmploc; 13726 struct jmploc jmploc;
13722 struct stackmark smark; 13727 struct stackmark smark;
13728 int login_sh;
13723 13729
13724 /* Initialize global data */ 13730 /* Initialize global data */
13725 INIT_G_misc(); 13731 INIT_G_misc();
@@ -13768,15 +13774,13 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
13768 13774
13769 init(); 13775 init();
13770 setstackmark(&smark); 13776 setstackmark(&smark);
13771 procargs(argv); 13777 login_sh = procargs(argv);
13772#if DEBUG 13778#if DEBUG
13773 TRACE(("Shell args: ")); 13779 TRACE(("Shell args: "));
13774 trace_puts_args(argv); 13780 trace_puts_args(argv);
13775#endif 13781#endif
13776 13782
13777 if (argv[0] && argv[0][0] == '-') 13783 if (login_sh) {
13778 isloginsh = 1;
13779 if (isloginsh) {
13780 const char *hp; 13784 const char *hp;
13781 13785
13782 state = 1; 13786 state = 1;