diff --git a/bin/sh/main.c b/bin/sh/main.c --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -95,6 +95,7 @@ static struct stackmark smark, smark2; volatile int state; char *shinit; + int login; (void) setlocale(LC_ALL, ""); initcharset(); @@ -128,13 +129,13 @@ initvar(); setstackmark(&smark); setstackmark(&smark2); - procargs(argc, argv); + login = procargs(argc, argv); trap_init(); pwd_init(iflag); INTON; if (iflag) chkmail(1); - if (argv[0] && argv[0][0] == '-') { + if (login) { state = 1; read_profile("/etc/profile"); state1: diff --git a/bin/sh/options.h b/bin/sh/options.h --- a/bin/sh/options.h +++ b/bin/sh/options.h @@ -109,7 +109,7 @@ extern char *shoptarg; /* set by nextopt */ extern char *nextopt_optptr; /* used by nextopt */ -void procargs(int, char **); +int procargs(int, char **); void optschanged(void); void freeparam(struct shparam *); int nextopt(const char *); diff --git a/bin/sh/options.c b/bin/sh/options.c --- a/bin/sh/options.c +++ b/bin/sh/options.c @@ -64,7 +64,7 @@ char *minusc; /* argument to -c option */ -static void options(int); +static int options(int); static void minus_o(char *, int); static void setoption(int, int); static void setoptionbyindex(int, int); @@ -76,19 +76,20 @@ * Process the shell command line arguments. */ -void +int procargs(int argc, char **argv) { - int i; + int i, login; char *scriptname; argptr = argv; + login = argptr[0] && argptr[0][0] == '-'; if (argc > 0) argptr++; for (i = 0; i < NOPTS; i++) optval[i] = 2; privileged = (getuid() != geteuid() || getgid() != getegid()); - options(1); + login |= options(1); if (*argptr == NULL && minusc == NULL) sflag = 1; if (iflag != 0 && sflag == 1 && isatty(0) && isatty(1)) { @@ -119,6 +120,8 @@ argptr++; } optschanged(); + + return (login); } @@ -139,12 +142,13 @@ * to the set special builtin. */ -static void +static int options(int cmdline) { char *kp, *p; int val; int c; + int login = 0; if (cmdline) minusc = NULL; @@ -190,6 +194,8 @@ if (q == NULL || minusc != NULL) error("Bad -c option"); minusc = q; + } else if (c == 'l') { + login = 1; } else if (c == 'o') { minus_o(*argptr, val); if (*argptr) @@ -198,13 +204,13 @@ setoption(c, val); } } - return; + return (login); /* When processing `set', a single "-" means turn off -x and -v */ end_options1: if (!cmdline) { xflag = vflag = 0; - return; + return (login); } /* @@ -217,7 +223,7 @@ if (!cmdline) { if (*argptr == NULL) setparam(0, argptr); - return; + return (login); } /* @@ -236,6 +242,8 @@ /* We need to keep the final argument */ argptr--; } + + return (login); } static void