diff options
author | Jonathan McCrohan <jmccrohan@gmail.com> | 2012-03-05 02:10:23 +0000 |
---|---|---|
committer | Jonathan McCrohan <jmccrohan@gmail.com> | 2012-03-05 02:24:14 +0000 |
commit | f2c218206e155bd0552cac490fa752eb523874d8 (patch) | |
tree | 7974f5122b2fccd01e18cb9f3350df3fc955ad55 /src/modbuslog.c | |
parent | 9d9a73b1709516600cf7c14cb3662660e2607531 (diff) | |
download | verteco-1.1.tar.gz |
Fix copypasta errorv1.1
wrong variable used.
Diffstat (limited to '')
-rw-r--r-- | src/modbuslog.c | 28 |
1 files 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]; //<mac address>_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) { |