From: eeb Date: Mon, 7 Mar 2005 12:24:23 +0000 (+0000) Subject: * further lctl debug_file fixes X-Git-Tag: 1.3.4~80 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=314eba9db4e70a4c4131d96bbbc76a8ccc6d0b0d;p=fs%2Flustre-release.git * further lctl debug_file fixes - truncate output file - close streams --- 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