Re: patch to add -l option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 06, 2008 at 04:51:58PM +0100, Matthias Klose wrote:
Content-Description: message body text
> LSB-3.1 requires /bin/sh to understand -l option. Patch by Eric.

Thank you.  Since -l shouldn't be set by set, I've added this
patch instead.  The profile part is fixed in a previous patch.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
commit b95e608112199964bd1f37f1b48d6604d5c0f47b
Author: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Date:   Sun Jul 13 22:27:00 2008 +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@xxxxxxxxxxxxxxxxxxx>

diff --git a/ChangeLog b/ChangeLog
index 58bed78..89f5c13 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
 	* Made t_lex reentrant.
 	* Made setinputfd static.
 	* Expand ENV before using it.
+	* Added support for -l.
 
 2008-05-19  Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
 
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 *);
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux