summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2013-04-10 12:16:33 +0200
committerHarald Welte <laforge@gnumonks.org>2013-04-10 12:16:33 +0200
commitf56f16539b8a8ccf6d167ac3ff5fec9f940c5f39 (patch)
tree3b3f3515120b4d571b88573cf628ae8a1e0870d9
parente3708f5040b5e2a832f85ce86cdd2b933b18744d (diff)
downloadgpsdate-f56f16539b8a8ccf6d167ac3ff5fec9f940c5f39.tar.gz
gpsdate-f56f16539b8a8ccf6d167ac3ff5fec9f940c5f39.tar.bz2
gpsdate-f56f16539b8a8ccf6d167ac3ff5fec9f940c5f39.tar.xz
gpsdate-f56f16539b8a8ccf6d167ac3ff5fec9f940c5f39.zip
use syslog() for reporting errors and status
-rw-r--r--gpsdate.c13
1 files 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 <errno.h>
#include <unistd.h>
#include <string.h>
+#include <syslog.h>
#include <sys/time.h>
#include <gps.h>
@@ -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);
}