From bae5b895f6c80dc25e605ba4e5a5e713572cb40a Mon Sep 17 00:00:00 2001 From: Brett Gordon Date: Fri, 29 May 2015 11:36:21 -0400 Subject: [PATCH] FUZIX: ssh.c: environment assignment bugfix + prettier prompting 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 | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Applications/util/ssh.c b/Applications/util/ssh.c index 99c14179..35f9df4d 100644 --- a/Applications/util/ssh.c +++ b/Applications/util/ssh.c @@ -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 */ -- 2.34.1