diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2013-09-29 06:28:38 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2013-09-29 06:28:38 -0400 |
commit | f628764ea400bb6e14342908ca595a0c91e5c5ab (patch) | |
tree | d154b1afc040d5be58f4e932e2f1774ed88a8859 | |
parent | f6953c4bed4ee5bb010f52f689258825b7a0d8e5 (diff) | |
download | gpsd-f628764ea400bb6e14342908ca595a0c91e5c5ab.tar.gz |
Properly label debug reports from different programs.
All regression tests pass.
-rw-r--r-- | gpsctl.c | 11 | ||||
-rw-r--r-- | gpsd.c | 11 | ||||
-rw-r--r-- | gpsd.h-tail | 3 | ||||
-rw-r--r-- | gpsdecode.c | 11 | ||||
-rw-r--r-- | libgpsd_core.c | 12 | ||||
-rw-r--r-- | test_geoid.c | 12 |
6 files changed, 51 insertions, 9 deletions
@@ -31,6 +31,17 @@ static struct gps_context_t context; */ #define REDIRECT_SNIFF 15 +void gpsd_report(const int debuglevel, const int errlevel, + const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + gpsd_labeled_report(debuglevel, errlevel, "gpsctl:", fmt, ap); + va_end(ap); + +} + /*@ -noret @*/ static gps_mask_t get_packet(struct gps_device_t *session) /* try to get a well-formed packet from the GPS */ @@ -162,6 +162,17 @@ static void onsig(int sig) signalled = (sig_atomic_t) sig; } +void gpsd_report(const int debuglevel, const int errlevel, + const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + gpsd_labeled_report(debuglevel, errlevel, "gpsd:", fmt, ap); + va_end(ap); + +} + static void typelist(void) /* list installed drivers and enabled features */ { diff --git a/gpsd.h-tail b/gpsd.h-tail index 2cee2f8f..f5dac310 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -843,7 +843,8 @@ extern void libgps_dump_state(struct gps_data_t *); # define libgps_debug_trace(args) /*@i1@*/do { } while (0) #endif /* LIBGPS_DEBUG */ -/* caller should supply this */ +void gpsd_labeled_report(const int, const int, + const char *, const char *, va_list) # if __GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) __attribute__((__format__(__printf__, 3, 4))) void gpsd_report(const int, const int, const char *, ...); # else /* not a new enough GCC, use the unprotected prototype */ diff --git a/gpsdecode.c b/gpsdecode.c index 90799f3d..27137cb9 100644 --- a/gpsdecode.c +++ b/gpsdecode.c @@ -27,6 +27,17 @@ static unsigned int typelist[32]; * **************************************************************************/ +void gpsd_report(const int debuglevel, const int errlevel, + const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + gpsd_labeled_report(debuglevel, errlevel, "gpsdecode:", fmt, ap); + va_end(ap); + +} + #ifdef AIVDM_ENABLE static void aivdm_csv_dump(struct ais_t *ais, char *buf, size_t buflen) { diff --git a/libgpsd_core.c b/libgpsd_core.c index 5223f0ce..42c6be39 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -49,15 +49,14 @@ static void visibilize(/*@out@*/char *buf2, size_t len, const char *buf) 0x00ff & (unsigned)*sp); } -void gpsd_report(const int debuglevel, const int errlevel, - const char *fmt, ...) +void gpsd_labeled_report(const int debuglevel, const int errlevel, + const char *label, const char *fmt, va_list ap) /* assemble command in printf(3) style, use stderr or syslog */ { #ifndef SQUELCH_ENABLE if (errlevel <= debuglevel) { char buf[BUFSIZ], buf2[BUFSIZ]; char *err_str; - va_list ap; #if defined(PPS_ENABLE) /*@ -unrecog (splint has no pthread declarations as yet) @*/ @@ -96,12 +95,9 @@ void gpsd_report(const int debuglevel, const int errlevel, err_str = "UNK: "; } - (void)strlcpy(buf, "gpsd:", sizeof(buf)); + (void)strlcpy(buf, label, sizeof(buf)); (void)strncat(buf, err_str, sizeof(buf) - 1 - strlen(buf)); - va_start(ap, fmt); - (void)vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), fmt, - ap); - va_end(ap); + (void)vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), fmt, ap); visibilize(buf2, sizeof(buf2), buf); diff --git a/test_geoid.c b/test_geoid.c index e88251df..19e926ba 100644 --- a/test_geoid.c +++ b/test_geoid.c @@ -6,9 +6,21 @@ #include <stdio.h> #include <stdlib.h> +#include <stdarg.h> #include "gpsd.h" +void gpsd_report(const int debuglevel, const int errlevel, + const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + gpsd_labeled_report(debuglevel, errlevel, "geoid:", fmt, ap); + va_end(ap); + +} + int main(int argc, char **argv) { double lat, lon; |