[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gpsd-dev] [PATCH 2/3] Ensure gpxlogger doesn't crash on bad filename
From: |
Robert Norris |
Subject: |
[gpsd-dev] [PATCH 2/3] Ensure gpxlogger doesn't crash on bad filename |
Date: |
Mon, 20 Feb 2017 01:44:50 +0000 |
Need to ensure logfile is reset to 'stdout' when the specified output file
is not available (e.g. no permission to write it) otherwise it is continued
to be used when it is NULL and bad things happen.
TESTED:
Running as a normal user it doesn't crash with a bad filename:
./gpxlogger -f /root/CannotWriteHere.gpx
---
gpxlogger.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/gpxlogger.c b/gpxlogger.c
index e8e37169..57e8f05c 100644
--- a/gpxlogger.c
+++ b/gpxlogger.c
@@ -258,10 +258,12 @@ int main(int argc, char **argv)
}
fname[s] = '\0';;
logfile = fopen(fname, "w");
- if (logfile == NULL)
+ if (logfile == NULL) {
syslog(LOG_ERR,
"Failed to open %s: %s, logging to stdout.",
fname, strerror(errno));
+ logfile = stdout;
+ }
bailout:
free(fname);
break;
--
2.11.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gpsd-dev] [PATCH 2/3] Ensure gpxlogger doesn't crash on bad filename,
Robert Norris <=