From 7be810122b48af0c095c1d1d5e8bd0b124026ed4 Mon Sep 17 00:00:00 2001 From: Ankit Kumar Date: Tue, 5 Dec 2017 14:56:13 +0530 Subject: [PATCH 4/6] diags: Remove timestamp from disk health log file This patch removes timestamp from filename. Function call sequence is changed as old and new file will have same name. Signed-off-by: Ankit Kumar [Modified to continue with file creation even if remove_old_log_file fails - Vasant] Signed-off-by: Vasant Hegde --- diags/diag_disk.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/diags/diag_disk.c b/diags/diag_disk.c index 9c1acbe..f524774 100644 --- a/diags/diag_disk.c +++ b/diags/diag_disk.c @@ -344,7 +344,7 @@ static int sysfs_sg_disk_scan(const char *dir_name, char *disk_name) return rc; } -static int remove_old_log_file(char *xml_filename) +static int remove_old_log_file(void) { DIR *d; struct dirent *namelist; @@ -359,9 +359,6 @@ static int remove_old_log_file(char *xml_filename) if (namelist->d_name[0] == '.') continue; - if (!strcmp(xml_filename, namelist->d_name)) - continue; - snprintf(filename, sizeof(filename) - 1, "%s/%s", OUTPUT_PATH, namelist->d_name); if (unlink(filename) < 0) { @@ -416,10 +413,11 @@ int diag_disk(char *disk_name) /* file format */ snprintf(xml_filename, sizeof(xml_filename) - 1, - "%s~%s~%s~diskAnalytics~%d%02d%02d%02d%02d%02d.xml", - mach_type_model, mach_model, serial_num, - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); + "%s~%s~%s~diskAnalytics.xml", + mach_type_model, mach_model, serial_num); + + /* Try to remove old log file. We will continue even if this fails */ + remove_old_log_file(); /* open file */ ret = open_output_xml_file(xml_filename); @@ -441,12 +439,5 @@ int diag_disk(char *disk_name) /* close output xml file descriptor */ close_output_xml_file(); - /* remove old log file */ - ret = remove_old_log_file(xml_filename); - if (ret) { - fprintf(stderr, "Unable to remove old output log file.\n"); - return -1; - } - return 0; } -- 2.14.3