From 314eba9db4e70a4c4131d96bbbc76a8ccc6d0b0d Mon Sep 17 00:00:00 2001 From: eeb Date: Mon, 7 Mar 2005 12:24:23 +0000 Subject: [PATCH] * further lctl debug_file fixes - truncate output file - close streams --- lnet/utils/debug.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lnet/utils/debug.c b/lnet/utils/debug.c index f8d94ed..16186ee 100644 --- a/lnet/utils/debug.c +++ b/lnet/utils/debug.c @@ -446,8 +446,12 @@ int jt_dbg_debug_kernel(int argc, char **argv) int jt_dbg_debug_file(int argc, char **argv) { - int fdin,fdout; - FILE *in, *out = stdout; + int fdin; + int fdout; + FILE *in; + FILE *out = stdout; + int rc; + if (argc > 3 || argc < 2) { fprintf(stderr, "usage: %s [output]\n", argv[0]); return 0; @@ -467,7 +471,9 @@ int jt_dbg_debug_file(int argc, char **argv) return 1; } if (argc > 2) { - fdout = open(argv[2], O_CREAT | O_WRONLY | O_LARGEFILE, 0600); + fdout = open(argv[2], + O_CREAT | O_TRUNC | O_WRONLY | O_LARGEFILE, + 0600); if (fdout == -1) { fprintf(stderr, "open(%s) failed: %s\n", argv[2], strerror(errno)); @@ -484,7 +490,13 @@ int jt_dbg_debug_file(int argc, char **argv) } } - return parse_buffer(in, out); + rc = parse_buffer(in, out); + + fclose(in); + if (out != stdout) + fclose(out); + + return rc; } static int -- 1.8.3.1