]> git.puffer.fish Git - mirror/frr.git/commitdiff
2005-03-08 Paul Jakma <paul.jakma@sun.com>
authorpaul <paul>
Tue, 8 Mar 2005 15:16:57 +0000 (15:16 +0000)
committerpaul <paul>
Tue, 8 Mar 2005 15:16:57 +0000 (15:16 +0000)
* command.c: (banner_motd_file_cmd) use XSTRDUP/XFREE
* vty.c: (vty_hello) suggestions from Andrew, read by line and
  stub out trailling non-printable characters on each line thus
  allowing us to specify VTY_NEWLINE to vty_out.

lib/ChangeLog
lib/command.c
lib/vty.c

index 3b60e294a2bd98780ca9c235bdd6893aa5814c7f..ca5d4c3c8a7963ab80b74a5681706568362104ef 100644 (file)
@@ -1,3 +1,10 @@
+2005-03-08 Paul Jakma <paul.jakma@sun.com>
+
+       * command.c: (banner_motd_file_cmd) use XSTRDUP/XFREE
+       * vty.c: (vty_hello) suggestions from Andrew, read by line and
+         stub out trailling non-printable characters on each line thus
+         allowing us to specify VTY_NEWLINE to vty_out.
+
 2005-03-08 Jeroen Massar <jeroen@unfix.org>
 
        * vty.c: (vty_hello) display motd file, if set
index ca1100da78888aecb56967268e0ed258ea8a44ae..7656f68061a50e1d027a4e29db9e7bede0d7b432 100644 (file)
@@ -1,5 +1,5 @@
 /*
-   $Id: command.c,v 1.38 2005/03/08 10:43:43 paul Exp $
+   $Id: command.c,v 1.39 2005/03/08 15:16:57 paul Exp $
 
    Command interpreter routine for virtual terminal [aka TeletYpe]
    Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
@@ -3409,8 +3409,10 @@ DEFUN (banner_motd_file,
        "Banner from a file\n"
        "Filename\n")
 {
-  if (host.motdfile) free(host.motdfile);
-  host.motdfile = strdup(argv[0]);
+  if (host.motdfile)
+    XFREE (MTYPE_TMP, host.motdfile);
+  host.motdfile = XSTRDUP (MTYPE_TMP, argv[0]);
+
   return CMD_SUCCESS;
 }
 
index bb3f14a50c7cabbffe776f8082b5cb2ae052c1e6..2ea24b8e7cda699a1acb182240f90c08146afcc9 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -220,22 +220,23 @@ vty_hello (struct vty *vty)
     {
       FILE *f;
       char buf[4096];
-      int r;
+      
       f = fopen (host.motdfile, "r");
       if (f)
        {
-         while (!feof (f))
+         while (fgets (buf, sizeof (buf), f))
            {
-             memset (buf, '\0', sizeof (buf));
-             r = fread (&buf, sizeof (buf) - 1, 1, f);
-             if (r < 0)
-               break;
-             vty_out (vty, buf);
-           }
+             char *s;
+             /* work backwards and squash all isspace() chars
+              * we want nul terminated for vty_out */
+             for (s = buf+strlen(buf); (s > buf) && isspace(*(s-1)); s--);
+               *s = '\0';
+              vty_out (vty, "%s%s", buf, VTY_NEWLINE);
+            }
          fclose (f);
        }
       else
-       vty_out (vty, "MOTD file not found\n");
+       vty_out (vty, "MOTD file not found%s", VTY_NEWLINE);
     }
   else if (host.motd)
     vty_out (vty, host.motd);