From f2c218206e155bd0552cac490fa752eb523874d8 Mon Sep 17 00:00:00 2001 From: Jonathan McCrohan Date: Mon, 5 Mar 2012 02:10:23 +0000 Subject: Fix copypasta error wrong variable used. --- src/modbuslog.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/modbuslog.c b/src/modbuslog.c index 0adf566..ec0e10e 100644 --- a/src/modbuslog.c +++ b/src/modbuslog.c @@ -252,10 +252,10 @@ int main(int argc, char *argv[]) { struct tm midnight = *localtime(&unixtime_day); - char filename[50]; + char log_filename[50]; //_YYYY_MM_DD_HH_MM_SS.log - sprintf(filename, + sprintf(log_filename, "/var/modbuslog/%s_%04i_%02i_%02i_%02i_%02i_%02i.log", mac_address(), midnight.tm_year + 1900, midnight.tm_mon + 1, midnight.tm_mday, midnight.tm_hour, @@ -263,23 +263,23 @@ int main(int argc, char *argv[]) { //printf("%s\n",filename); - FILE *fp = fopen(filename, "r"); + FILE *fp = fopen(log_filename, "r"); if (fp) { fclose(fp); } else { // file doesn't exist. create it. syslog(LOG_NOTICE, "logfile does not exist"); - syslog(LOG_INFO, "creating file: %s", filename); - FILE *fp = fopen(filename, "w"); + syslog(LOG_INFO, "creating file: %s", log_filename); + FILE *fp = fopen(log_filename, "w"); fprintf( fp, "IntervalID|UTCDate|UTCTime|LOCALDate|LOCALTime|SensorID|RegisterID|Reading\n"); fclose(fp); } - FILE *filehandle = fopen(filename, "a+"); + FILE *filehandle = fopen(log_filename, "a+"); - syslog(LOG_DEBUG, "opening file for append: %s", filename); + syslog(LOG_DEBUG, "opening file for append: %s", log_filename); int16_t registervalue = 0; @@ -312,8 +312,13 @@ int main(int argc, char *argv[]) { struct tm lc = *localtime(&unixtime_min); int intervalid; + char interval_filename[50]; + sprintf(interval_filename, "/var/modbuslog/interval/interval.txt"); + + syslog(LOG_DEBUG, "opening interval file: %s", interval_filename); + FILE *intervalfile = fopen( - "/var/modbuslog/interval/interval.txt", "r+"); + interval_filename, "r+"); if (intervalfile) { fclose(intervalfile); @@ -321,12 +326,15 @@ int main(int argc, char *argv[]) { // file doesn't exist. create it. syslog(LOG_NOTICE, "interval file does not exist"); syslog(LOG_INFO, "attempting to create file: %s", - intervalfile); - FILE *intervalfile = fopen(filename, "w"); + interval_filename); + intervalfile = fopen(interval_filename, "w"); fprintf(intervalfile, "0\n"); fclose(intervalfile); } + // file now exists, try opening again + intervalfile = fopen(interval_filename, "r+"); + fscanf(intervalfile, "%d", &intervalid); //handle 32bit signed overflow if (intervalid == 2147483647) { -- cgit v1.2.3