diff --git a/gpsdate.c b/gpsdate.c index e80aac8..513ca77 100644 --- a/gpsdate.c +++ b/gpsdate.c @@ -45,6 +45,7 @@ #define NUM_RETRIES 60 /* Number of gpsd re-connects */ #define RETRY_SLEEP 1 /* Seconds to sleep between re-connects */ +static int no_detach = 0; static struct gps_data_t gpsdata; static void callback(struct gps_data_t *gpsdata) @@ -181,10 +182,11 @@ int main(int argc, char **argv) static struct option long_options[] = { {"num-retries", 1, 0, 'n'}, {"retry-sleep", 1, 0, 's'}, + {"no-detach", 0, 0, 'd'}, {0,0,0,0} }; - c = getopt_long(argc, argv, "n:s:", + c = getopt_long(argc, argv, "n:s:d", long_options, &option_index); if (c == -1) break; @@ -196,6 +198,9 @@ int main(int argc, char **argv) case 's': retry_sleep = atoi(optarg); break; + case 'd': + no_detach = 1; + break; } } @@ -223,7 +228,8 @@ int main(int argc, char **argv) } state = S_CONNECTED; - osmo_daemonize(); + if (!no_detach) + osmo_daemonize(); /* We run in an endless loop. The only reasonable way to exit is after * a correct GPS timestamp has been received in callback() */ diff --git a/gpsdate.service b/gpsdate.service index d4a26b4..869f076 100644 --- a/gpsdate.service +++ b/gpsdate.service @@ -2,6 +2,6 @@ Description=Set time based on GPS [Service] -Type=forking +Type=simple EnvironmentFile=/etc/default/gpsdate -ExecStart=/usr/sbin/gpsdate ${GPSDATE_HOST} ${GPSDATE_PORT} +ExecStart=/usr/sbin/gpsdate --no-detach ${GPSDATE_HOST} ${GPSDATE_PORT}