diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2005-07-14 13:43:40 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2005-07-14 13:43:40 +0000 |
commit | 827c0946340e883075657836c251909c9daff96f (patch) | |
tree | fcb398e815d49dee918ee282c790ab448e9dab79 /gpsd.c | |
parent | ee581ccd6a9b1f1e9f1e3bafc672d3813827ae79 (diff) | |
download | gpsd-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.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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 */ |