FUZIX: ssh.c: environment assignment bugfix + prettier prompting
authorBrett Gordon <beretta42@gmail.com>
Fri, 29 May 2015 15:36:21 +0000 (11:36 -0400)
committerAlan Cox <alan@linux.intel.com>
Sat, 30 May 2015 09:44:38 +0000 (10:44 +0100)
here's a patch to ssh.c that:

1. Sets the prompt to include a space
2. Prints a newline in the output of the built-in "pwd"
3. Fixes environment variable assignment

As to no. 3:  The original code used "putenv()", which, on a new
variable, inserts the tmp char *  in to the env[] array.  "ssh"
proceeded to reuse this string for more input, thereby screwing up the
environment.  I changed it to "setenv()" which makes a new copy of the
string, then inserts it into env[].

This way at least us poor "ssh" users can set PATH until the real "sh"
and "init" are working better for the 6809.

--
Brett M. Gordon,
beretta42@gmail.com

Applications/util/ssh.c

index 99c1417..35f9df4 100644 (file)
@@ -69,12 +69,12 @@ int main(int argc, char *argval[])
        chdir(getenv("HOME"));
     }
 
-    cprompt = (getuid() == 0) ? "ssh#" : "ssh$";
+    cprompt = (getuid() == 0) ? "ssh# " : "ssh$ ";
 
     for (;;) {
         for (i = 0; i < MAX_ARGS; i++) arg[i] = NULL;
         do {
-            write(1, cprompt, 4);
+            write(1, cprompt, 5);
             if ((i = read(0, buf, 127)) <= 0)
                 return 0;
             buf[i - 1] = '\0';   /* Strip newline from fgets */
@@ -96,8 +96,12 @@ int main(int argc, char *argval[])
         }
 
         else if (strcmp(cmd, "pwd") == 0) {
-            if (getcwd(buf, 128))
-                write(1, buf, strlen(buf));
+           if (getcwd(buf, 128)){
+               char *ptr=&buf[strlen(buf)];
+               *ptr++='\n';
+               *ptr=0;
+               write(1, buf, strlen(buf));
+           }
             else
                 write(1, "pwd: cannot get current directory\n",34);
         }
@@ -145,8 +149,9 @@ int main(int argc, char *argval[])
 
         /* Check for environmen variable assignment */
         else if ((tp = strchr(cmd, '=')) != NULL) {
-            if (*(tp+1) == '\0') *tp = '\0';
-            putenv(cmd);
+         *tp='\0';
+         if( *(tp+1) == '\0' ) unsetenv( cmd );
+         else setenv(cmd,tp+1,1);
         }
 
         /* No built-in Command, Try to find Executable Command File */