summaryrefslogtreecommitdiff
path: root/lib/vty.c
diff options
context:
space:
mode:
authorajs <ajs>2004-11-23 17:35:08 +0000
committerajs <ajs>2004-11-23 17:35:08 +0000
commitd246bd965898f0ba6781f2b2048af9a5eba079d3 (patch)
tree80ed32d986e3845d041cc2bc08bcc2b03a8ec75d /lib/vty.c
parent8686fc746cad9fda26812c88df5faaff0f418650 (diff)
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.
Diffstat (limited to 'lib/vty.c')
-rw-r--r--lib/vty.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/vty.c b/lib/vty.c
index 016e52a9..2f3bac2e 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -95,21 +95,27 @@ vty_out (struct vty *vty, const char *format, ...)
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 @@ vty_out (struct vty *vty, const char *format, ...)
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 @@ vty_out (struct vty *vty, const char *format, ...)
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 @@ vty_log (const char *proto_str, const char *format, va_list va)
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