don't clobber term, path if -p (but always set user, home and shell)
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Fri, 20 Sep 1985 09:41:52 +0000 (01:41 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Fri, 20 Sep 1985 09:41:52 +0000 (01:41 -0800)
SCCS-vsn: usr.bin/login/login.c 5.7
SCCS-vsn: usr.bin/login/login.c.1 5.7

usr/src/usr.bin/login/login.c
usr/src/usr.bin/login/login.c.1

index ac2dedc..3852e50 100644 (file)
@@ -11,7 +11,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)login.c    5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)login.c    5.7 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -332,13 +332,13 @@ main(argc, argv)
                envnew[i] = environ[i];
        environ = envnew;
 
                envnew[i] = environ[i];
        environ = envnew;
 
-       setenv("HOME=", pwd->pw_dir);
-       setenv("SHELL=", pwd->pw_shell);
+       setenv("HOME=", pwd->pw_dir, 1);
+       setenv("SHELL=", pwd->pw_shell, 1);
        if (term[0] == '\0')
                strncpy(term, stypeof(tty), sizeof(term));
        if (term[0] == '\0')
                strncpy(term, stypeof(tty), sizeof(term));
-       setenv("TERM=", term);
-       setenv("USER=", pwd->pw_name);
-       setenv("PATH=", ":/usr/ucb:/bin:/usr/bin");
+       setenv("TERM=", term, 0);
+       setenv("USER=", pwd->pw_name, 1);
+       setenv("PATH=", ":/usr/ucb:/bin:/usr/bin", 0);
 
        if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
                namep = pwd->pw_shell;
 
        if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
                namep = pwd->pw_shell;
@@ -551,7 +551,7 @@ done:
  * This procedure assumes the memory for the first level of environ
  * was allocated using malloc.
  */
  * This procedure assumes the memory for the first level of environ
  * was allocated using malloc.
  */
-setenv(var, value)
+setenv(var, value, clobber)
        char *var, *value;
 {
        extern char **environ;
        char *var, *value;
 {
        extern char **environ;
@@ -562,6 +562,8 @@ setenv(var, value)
        for (index = 0; environ[index] != NULL; index++) {
                if (strncmp(environ[index], var, varlen) == 0) {
                        /* found it */
        for (index = 0; environ[index] != NULL; index++) {
                if (strncmp(environ[index], var, varlen) == 0) {
                        /* found it */
+                       if (!clobber)
+                               return;
                        environ[index] = malloc(varlen + vallen + 1);
                        strcpy(environ[index], var);
                        strcat(environ[index], value);
                        environ[index] = malloc(varlen + vallen + 1);
                        strcpy(environ[index], var);
                        strcat(environ[index], value);
index e14af97..d4ddb89 100644 (file)
@@ -11,7 +11,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)login.c.1  5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)login.c.1  5.7 (Berkeley) %G%";
 #endif not lint
 
 /*
 #endif not lint
 
 /*
@@ -332,13 +332,13 @@ main(argc, argv)
                envnew[i] = environ[i];
        environ = envnew;
 
                envnew[i] = environ[i];
        environ = envnew;
 
-       setenv("HOME=", pwd->pw_dir);
-       setenv("SHELL=", pwd->pw_shell);
+       setenv("HOME=", pwd->pw_dir, 1);
+       setenv("SHELL=", pwd->pw_shell, 1);
        if (term[0] == '\0')
                strncpy(term, stypeof(tty), sizeof(term));
        if (term[0] == '\0')
                strncpy(term, stypeof(tty), sizeof(term));
-       setenv("TERM=", term);
-       setenv("USER=", pwd->pw_name);
-       setenv("PATH=", ":/usr/ucb:/bin:/usr/bin");
+       setenv("TERM=", term, 0);
+       setenv("USER=", pwd->pw_name, 1);
+       setenv("PATH=", ":/usr/ucb:/bin:/usr/bin", 0);
 
        if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
                namep = pwd->pw_shell;
 
        if ((namep = rindex(pwd->pw_shell, '/')) == NULL)
                namep = pwd->pw_shell;
@@ -551,7 +551,7 @@ done:
  * This procedure assumes the memory for the first level of environ
  * was allocated using malloc.
  */
  * This procedure assumes the memory for the first level of environ
  * was allocated using malloc.
  */
-setenv(var, value)
+setenv(var, value, clobber)
        char *var, *value;
 {
        extern char **environ;
        char *var, *value;
 {
        extern char **environ;
@@ -562,6 +562,8 @@ setenv(var, value)
        for (index = 0; environ[index] != NULL; index++) {
                if (strncmp(environ[index], var, varlen) == 0) {
                        /* found it */
        for (index = 0; environ[index] != NULL; index++) {
                if (strncmp(environ[index], var, varlen) == 0) {
                        /* found it */
+                       if (!clobber)
+                               return;
                        environ[index] = malloc(varlen + vallen + 1);
                        strcpy(environ[index], var);
                        strcat(environ[index], value);
                        environ[index] = malloc(varlen + vallen + 1);
                        strcpy(environ[index], var);
                        strcat(environ[index], value);