Add an option to not fork and use it

For systemd it is better to not fork. Add an option for that.

Fixes: SYS#1152
This commit is contained in:
Holger Hans Peter Freyther 2015-02-14 23:31:25 +01:00
parent 2326eee789
commit cb50b4bb9f
2 changed files with 10 additions and 4 deletions

View File

@ -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() */

View File

@ -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}