use syslog() for reporting errors and status
This commit is contained in:
parent
e3708f5040
commit
f56f16539b
13
gpsdate.c
13
gpsdate.c
|
@ -33,6 +33,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <syslog.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <gps.h>
|
#include <gps.h>
|
||||||
|
@ -57,11 +58,13 @@ static void callback(struct gps_data_t *gpsdata)
|
||||||
rc = settimeofday(&tv, NULL);
|
rc = settimeofday(&tv, NULL);
|
||||||
gps_close(gpsdata);
|
gps_close(gpsdata);
|
||||||
if (rc == 0) {
|
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);
|
exit(EXIT_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Error setting RTC: %d (%s)\n",
|
syslog(LOG_ERR, "Error setting RTC: %d (%s)\n",
|
||||||
errno, strerror(errno));
|
errno, strerror(errno));
|
||||||
|
closelog();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,6 +74,8 @@ int main(int argc, char **argv)
|
||||||
char *host = "localhost";
|
char *host = "localhost";
|
||||||
int i, rc;
|
int i, rc;
|
||||||
|
|
||||||
|
openlog("gpsdate", LOG_PERROR, LOG_CRON);
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
host = argv[1];
|
host = argv[1];
|
||||||
|
|
||||||
|
@ -83,8 +88,9 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc) {
|
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));
|
errno, gps_errstr(errno));
|
||||||
|
closelog();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,5 +100,6 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
gps_close(&gpsdata);
|
gps_close(&gpsdata);
|
||||||
|
|
||||||
|
closelog();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue