From ce03fbbea7afac02032af1639e41cbe3156afb0a Mon Sep 17 00:00:00 2001 From: adilger Date: Sat, 11 Dec 2004 09:55:24 +0000 Subject: [PATCH] Fix lconf --dump handling: - don't generate a temp filename for a raw dump - don't unlink non-regular files (e.g. /dev/null) - don't report an error if kernel doesn't dump anything (fix mismerge?) --- lnet/utils/debug.c | 21 ++++++++++++++------- lustre/portals/utils/debug.c | 21 ++++++++++++++------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lnet/utils/debug.c b/lnet/utils/debug.c index 16af0b5..17a124c 100644 --- a/lnet/utils/debug.c +++ b/lnet/utils/debug.c @@ -377,6 +377,7 @@ static int parse_buffer(FILE *in, FILE *out) int jt_dbg_debug_kernel(int argc, char **argv) { char filename[4096]; + struct stat st; int rc, raw = 0, fd; FILE *in, *out = stdout; @@ -390,18 +391,21 @@ int jt_dbg_debug_kernel(int argc, char **argv) } else if (argc > 1 && (argv[1][0] == '0' || argv[1][0] == '1')) { raw = atoi(argv[1]); argc--; - } else { - sprintf(filename, "%s.%lu.%u", argc > 1 ? argv[1] : - "/tmp/lustre-log", time(NULL), getpid()); } - unlink(filename); + /* If we are dumping raw (which means no conversion step to ASCII) + * then dump directly to any supplied filename, otherwise this is + * just a temp file and we dump to the real file at convert time. */ + if (argc > 1 && raw) + strcpy(filename, argv[1]); + else + sprintf(filename, "/tmp/lustre-log.%lu.%u",time(NULL),getpid()); + + if (stat(filename, &st) == 0 && S_ISREG(st.st_mode)) + unlink(filename); fd = open("/proc/sys/portals/dump_kernel", O_WRONLY); if (fd < 0) { - if (errno == ENOENT) /* no dump file created */ - return 0; - fprintf(stderr, "open(dump_kernel) failed: %s\n", strerror(errno)); return 1; @@ -421,6 +425,9 @@ int jt_dbg_debug_kernel(int argc, char **argv) in = fopen(filename, "r"); if (in == NULL) { + if (errno == ENOENT) /* no dump file created */ + return 0; + fprintf(stderr, "fopen(%s) failed: %s\n", filename, strerror(errno)); return 1; diff --git a/lustre/portals/utils/debug.c b/lustre/portals/utils/debug.c index 16af0b5..17a124c 100644 --- a/lustre/portals/utils/debug.c +++ b/lustre/portals/utils/debug.c @@ -377,6 +377,7 @@ static int parse_buffer(FILE *in, FILE *out) int jt_dbg_debug_kernel(int argc, char **argv) { char filename[4096]; + struct stat st; int rc, raw = 0, fd; FILE *in, *out = stdout; @@ -390,18 +391,21 @@ int jt_dbg_debug_kernel(int argc, char **argv) } else if (argc > 1 && (argv[1][0] == '0' || argv[1][0] == '1')) { raw = atoi(argv[1]); argc--; - } else { - sprintf(filename, "%s.%lu.%u", argc > 1 ? argv[1] : - "/tmp/lustre-log", time(NULL), getpid()); } - unlink(filename); + /* If we are dumping raw (which means no conversion step to ASCII) + * then dump directly to any supplied filename, otherwise this is + * just a temp file and we dump to the real file at convert time. */ + if (argc > 1 && raw) + strcpy(filename, argv[1]); + else + sprintf(filename, "/tmp/lustre-log.%lu.%u",time(NULL),getpid()); + + if (stat(filename, &st) == 0 && S_ISREG(st.st_mode)) + unlink(filename); fd = open("/proc/sys/portals/dump_kernel", O_WRONLY); if (fd < 0) { - if (errno == ENOENT) /* no dump file created */ - return 0; - fprintf(stderr, "open(dump_kernel) failed: %s\n", strerror(errno)); return 1; @@ -421,6 +425,9 @@ int jt_dbg_debug_kernel(int argc, char **argv) in = fopen(filename, "r"); if (in == NULL) { + if (errno == ENOENT) /* no dump file created */ + return 0; + fprintf(stderr, "fopen(%s) failed: %s\n", filename, strerror(errno)); return 1; -- 1.8.3.1