summaryrefslogtreecommitdiff
path: root/gpsd.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2005-07-14 13:43:40 +0000
committerEric S. Raymond <esr@thyrsus.com>2005-07-14 13:43:40 +0000
commit827c0946340e883075657836c251909c9daff96f (patch)
treefcb398e815d49dee918ee282c790ab448e9dab79 /gpsd.c
parentee581ccd6a9b1f1e9f1e3bafc672d3813827ae79 (diff)
downloadgpsd-827c0946340e883075657836c251909c9daff96f.tar.gz
Don't emit binary characters when logging messages with raw binary in them.
Diffstat (limited to 'gpsd.c')
-rw-r--r--gpsd.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/gpsd.c b/gpsd.c
index 4000c8a0..67bcb60c 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -134,7 +134,7 @@ void gpsd_report(int errlevel, const char *fmt, ... )
/* assemble command in printf(3) style, use stderr or syslog */
{
if (errlevel <= debuglevel) {
- char buf[BUFSIZ];
+ char buf[BUFSIZ], buf2[BUFSIZ], *sp;
va_list ap;
#if defined(PPS_ENABLE)
@@ -145,10 +145,17 @@ void gpsd_report(int errlevel, const char *fmt, ... )
(void)vsnprintf(buf + strlen(buf), sizeof(buf)-strlen(buf), fmt, ap);
va_end(ap);
+ buf2[0] = '\0';
+ for (sp = buf; *sp; sp++)
+ if (isprint(*sp) || isspace(*sp) && (sp[1]=='\0' || sp[2]=='\0'))
+ (void)snprintf(buf2 + strlen(buf2), 2, "%c", *sp);
+ else
+ (void)snprintf(buf2 + strlen(buf2), 6, "\\x%02x", *sp);
+
if (in_background)
- syslog((errlevel == 0) ? LOG_ERR : LOG_NOTICE, "%s", buf);
+ syslog((errlevel == 0) ? LOG_ERR : LOG_NOTICE, "%s", buf2);
else
- (void)fputs(buf, stderr);
+ (void)fputs(buf2, stderr);
#if defined(PPS_ENABLE)
(void)pthread_mutex_unlock(&report_mutex);
#endif /* PPS_ENABLE */