summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2008-07-13 22:34:50 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2008-07-13 22:34:50 +0800
commit3b7c8442bfe7c2fd0a6b0415df6ddf66a399fd55 (patch)
treed9206d6ab90177745dd075d22b77f8fca7c5da75 /src
parent[SHELL] Expand ENV before using it (diff)
downloaddash-3b7c8442bfe7c2fd0a6b0415df6ddf66a399fd55.tar.gz
dash-3b7c8442bfe7c2fd0a6b0415df6ddf66a399fd55.zip
[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>
Diffstat (limited to '')
-rw-r--r--src/dash.14
-rw-r--r--src/main.c5
-rw-r--r--src/options.c17
-rw-r--r--src/options.h2
4 files changed, 20 insertions, 8 deletions
diff --git a/src/dash.1 b/src/dash.1
index b4140eb..c8cb3ce 100644
--- a/src/dash.1
+++ b/src/dash.1
@@ -170,7 +170,7 @@ positional parameters of the shell ($1, $2, etc).
 Otherwise, the shell
 reads commands from its standard input.
 .Ss Argument List Processing
-All of the single letter options have a corresponding name that can be
+All of the single letter options that have a corresponding name can be
 used as an argument to the
 .Fl o
 option.
@@ -235,6 +235,8 @@ Useful for debugging.
 Ignore EOF's from input when interactive.
 .It Fl i Em interactive
 Force the shell to behave interactively.
+.It Fl l
+Make dash act as if it had been invoked as a login shell.
 .It Fl m Em monitor
 Turn on job control (set automatically when interactive).
 .It Fl s Em stdin
diff --git a/src/main.c b/src/main.c
index cf34931..7d07e2d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -96,6 +96,7 @@ main(int argc, char **argv)
 	volatile int state;
 	struct jmploc jmploc;
 	struct stackmark smark;
+	int login;
 
 #ifdef __GLIBC__
 	dash_errno = __errno_location();
@@ -148,8 +149,8 @@ main(int argc, char **argv)
 	rootpid = getpid();
 	init();
 	setstackmark(&smark);
-	procargs(argc, argv);
-	if (argv[0] && argv[0][0] == '-') {
+	login = procargs(argc, argv);
+	if (login) {
 		state = 1;
 		read_profile("/etc/profile");
 state1:
diff --git a/src/options.c b/src/options.c
index 48c9671..6f381e6 100644
--- a/src/options.c
+++ b/src/options.c
@@ -106,7 +106,7 @@ const char optletters[NOPTS] = {
 char optlist[NOPTS];
 
 
-STATIC void options(int);
+static int options(int);
 STATIC void minus_o(char *, int);
 STATIC void setoption(int, int);
 STATIC int getopts(char *, char *, char **);
@@ -116,21 +116,23 @@ STATIC int getopts(char *, char *, char **);
  * Process the shell command line arguments.
  */
 
-void
+int
 procargs(int argc, char **argv)
 {
 	int i;
 	const char *xminusc;
 	char **xargv;
+	int login;
 
 	xargv = argv;
+	login = xargv[0] && xargv[0][0] == '-';
 	arg0 = xargv[0];
 	if (argc > 0)
 		xargv++;
 	for (i = 0; i < NOPTS; i++)
 		optlist[i] = 2;
 	argptr = xargv;
-	options(1);
+	login |= options(1);
 	xargv = argptr;
 	xminusc = minusc;
 	if (*xargv == NULL) {
@@ -169,6 +171,8 @@ setarg0:
 		xargv++;
 	}
 	optschanged();
+
+	return login;
 }
 
 
@@ -190,12 +194,13 @@ optschanged(void)
  * to the argument list; we advance it past the options.
  */
 
-STATIC void
+STATIC int
 options(int cmdline)
 {
 	char *p;
 	int val;
 	int c;
+	int login = 0;
 
 	if (cmdline)
 		minusc = NULL;
@@ -223,6 +228,8 @@ options(int cmdline)
 		while ((c = *p++) != '\0') {
 			if (c == 'c' && cmdline) {
 				minusc = p;	/* command is after shell args*/
+			} else if (c == 'l' && cmdline) {
+				login = 1;
 			} else if (c == 'o') {
 				minus_o(*argptr, val);
 				if (*argptr)
@@ -232,6 +239,8 @@ options(int cmdline)
 			}
 		}
 	}
+
+	return login;
 }
 
 STATIC void
diff --git a/src/options.h b/src/options.h
index 45bbe5a..975fe33 100644
--- a/src/options.h
+++ b/src/options.h
@@ -75,7 +75,7 @@ extern char **argptr;		/* argument list for builtin commands */
 extern char *optionarg;		/* set by nextopt */
 extern char *optptr;		/* used by nextopt */
 
-void procargs(int, char **);
+int procargs(int, char **);
 void optschanged(void);
 void setparam(char **);
 void freeparam(volatile struct shparam *);