From f56f16539b8a8ccf6d167ac3ff5fec9f940c5f39 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 10 Apr 2013 12:16:33 +0200 Subject: [PATCH] use syslog() for reporting errors and status --- gpsdate.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gpsdate.c b/gpsdate.c index 55a2af6..f78537a 100644 --- a/gpsdate.c +++ b/gpsdate.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -57,11 +58,13 @@ static void callback(struct gps_data_t *gpsdata) rc = settimeofday(&tv, NULL); gps_close(gpsdata); if (rc == 0) { - printf("Successfully set RTC time to GPSD time\n"); + syslog(LOG_NOTICE, "Successfully set RTC time to GPSD time\n"); + closelog(); exit(EXIT_SUCCESS); } else { - fprintf(stderr, "Error setting RTC: %d (%s)\n", + syslog(LOG_ERR, "Error setting RTC: %d (%s)\n", errno, strerror(errno)); + closelog(); exit(EXIT_FAILURE); } } @@ -71,6 +74,8 @@ int main(int argc, char **argv) char *host = "localhost"; int i, rc; + openlog("gpsdate", LOG_PERROR, LOG_CRON); + if (argc > 1) host = argv[1]; @@ -83,8 +88,9 @@ int main(int argc, char **argv) } if (rc) { - fprintf(stderr, "no gpsd running or network error: %d, %s\n", + syslog(LOG_ERR, "no gpsd running or network error: %d, %s\n", errno, gps_errstr(errno)); + closelog(); exit(EXIT_FAILURE); } @@ -94,5 +100,6 @@ int main(int argc, char **argv) gps_close(&gpsdata); + closelog(); exit(EXIT_SUCCESS); }