diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-31 19:43:47 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-31 19:43:47 +0200 |
commit | ec05df13b0f3bc69074909f078f981f417d95c89 (patch) | |
tree | 3854fd1fc3c1f1c1855362487734b41cd7aad5d0 /shell | |
parent | 78b1b1b07ac2784f67bc65bb1d86cc2559a12446 (diff) | |
download | busybox-w32-ec05df13b0f3bc69074909f078f981f417d95c89.tar.gz busybox-w32-ec05df13b0f3bc69074909f078f981f417d95c89.tar.bz2 busybox-w32-ec05df13b0f3bc69074909f078f981f417d95c89.zip |
ash: align --login code with dash
Upstream commit:
Date: Sun, 13 Jul 2008 22:34:50 +0800
[OPTIONS] Added support for -l
This patch adds support for the -l option (login shell) as required
by the LSB.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
It's a bit bigger, but gets rid of one global variable
function old new delta
options 554 576 +22
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 30 |
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 | } |
10723 | static int | 10721 | static int |
10724 | options(int cmdline) | 10722 | options(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 | */ |
13605 | static void | 13606 | static int |
13606 | procargs(char **argv) | 13607 | procargs(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; |