Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh - add pid to the trace file so that we don't keep ove...



details:   https://anonhg.NetBSD.org/src/rev/c669890b3fe9
branches:  trunk
changeset: 768622:c669890b3fe9
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Aug 23 10:01:32 2011 +0000

description:
- add pid to the trace file so that we don't keep overwriting ourselves
- use va_copy to print the trace arguments so that we don't deplete it for the real printf

diffstat:

 bin/sh/show.c |  12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (48 lines):

diff -r 368eed6376e7 -r c669890b3fe9 bin/sh/show.c
--- a/bin/sh/show.c     Tue Aug 23 09:59:20 2011 +0000
+++ b/bin/sh/show.c     Tue Aug 23 10:01:32 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: show.c,v 1.27 2010/11/14 19:36:07 christos Exp $       */
+/*     $NetBSD: show.c,v 1.28 2011/08/23 10:01:32 christos Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,13 +37,14 @@
 #if 0
 static char sccsid[] = "@(#)show.c     8.3 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: show.c,v 1.27 2010/11/14 19:36:07 christos Exp $");
+__RCSID("$NetBSD: show.c,v 1.28 2011/08/23 10:01:32 christos Exp $");
 #endif
 #endif /* not lint */
 
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include "shell.h"
 #include "parser.h"
@@ -297,9 +298,12 @@
 tracev(const char *fmt, va_list va)
 {
 #ifdef DEBUG
+       va_list ap;
        if (debug != 1 || !tracefile)
                return;
-       (void) vfprintf(tracefile, fmt, va);
+       va_copy(ap, va);
+       (void) vfprintf(tracefile, fmt, ap);
+       va_end(ap);
 #endif
 }
 
@@ -400,7 +404,7 @@
                strcat(s, "/trace");
        }
 #else
-       scopy("./trace", s);
+       snprintf(s, sizeof(s), "./trace.%d", (int)getpid());
 #endif /* not_this_way */
        if (tracefile) {
                if (!freopen(s, "a", tracefile)) {



Home | Main Index | Thread Index | Old Index