2004-11-23 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* log.c: (vzlog) Take a single va_list argument and use va_copy
as necessary for multiple traversals.
(zlog) Pass only one va_list to vzlog.
(zlog_*,plog_*) Use a macro for boilerplate code; pass only one
va_list to vzlog.
(zlog_set_file) Remove unused 2nd argument (flags).
(zlog_save_cwd,zlog_get_cwd,zlog_free_cwd) Remove unused functions.
* log.h: Remove ZLOG_*_INDEX defines (no longer used).
Remove unused 2nd argument from zlog_set_file prototype.
Fix prototype for zlog_rotate.
* command.c: (config_log_file) Remove unused 2nd arg to zlog_set_file.
* vty.c: (vty_out) Fix stdarg usage to perform multiple traversals
properly.
(vty_log) Must use va_copy for multiple traversals of va_list arg.
diff --git a/lib/vty.c b/lib/vty.c
index 016e52a..2f3bac2 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -95,21 +95,27 @@
int size = 1024;
char buf[1024];
char *p = NULL;
-
- va_start (args, format);
if (vty_shell (vty))
- vprintf (format, args);
+ {
+ va_start (args, format);
+ vprintf (format, args);
+ va_end (args);
+ }
else
{
/* Try to write to initial buffer. */
+ va_start (args, format);
len = vsnprintf (buf, sizeof buf, format, args);
+ va_end (args);
/* Initial buffer is not enough. */
if (len < 0 || len >= size)
{
while (1)
{
+ va_list ac;
+
if (len > -1)
size = len + 1;
else
@@ -119,7 +125,9 @@
if (! p)
return -1;
+ va_start (args, format);
len = vsnprintf (p, size, format, args);
+ va_end (args);
if (len > -1 && len < size)
break;
@@ -138,12 +146,10 @@
XFREE (MTYPE_VTY_OUT_BUF, p);
}
- va_end (args);
-
return len;
}
-int
+static int
vty_log_out (struct vty *vty, const char *proto_str, const char *format,
va_list va)
{
@@ -2277,7 +2283,12 @@
for (i = 0; i < vector_max (vtyvec); i++)
if ((vty = vector_slot (vtyvec, i)) != NULL)
if (vty->monitor)
- vty_log_out (vty, proto_str, format, va);
+ {
+ va_list ac;
+ va_copy(ac, va);
+ vty_log_out (vty, proto_str, format, ac);
+ va_end(ac);
+ }
}
int