2003-10-15 Paul Jakma <paul@dishone.st>

	* lib/vty.c: (vty_save_cwd) dont crash if getcwd fails. try fallback
          to SYSCONFDIR. Allocate cwd from the stack rather than relying on
          (non-portable) getcwd() allocation (which we didnt seem to be
	  freeing).
diff --git a/lib/vty.c b/lib/vty.c
index 90e1dad..4e341bf 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -2757,9 +2757,15 @@
 void
 vty_save_cwd ()
 {
-  char *cwd;
+  char cwd[MAXPATHLEN];
 
-  cwd = getcwd (NULL, MAXPATHLEN);
+  cwd[0] = getcwd (cwd, MAXPATHLEN);
+
+  if (!cwd)
+    {
+      chdir (SYSCONFDIR);
+      cwd[0] = getcwd (cwd, MAXPATHLEN);
+    }
 
   vty_cwd = XMALLOC (MTYPE_TMP, strlen (cwd) + 1);
   strcpy (vty_cwd, cwd);