mirror of
https://github.com/linux-can/can-utils.git
synced 2026-08-05 06:20:00 +02:00
slcand: daemonise only once setup is complete
Delay the daemon() call until the interface has been configured. This simplifies scripts that wish to use the new interface immediately. Signed-off-by: Mans Rullgard <mans@mansr.com>
This commit is contained in:
@@ -280,23 +280,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
syslogger(LOG_INFO, "starting on TTY device %s", ttypath);
|
syslogger(LOG_INFO, "starting on TTY device %s", ttypath);
|
||||||
|
|
||||||
/* Daemonize */
|
|
||||||
if (run_as_daemon) {
|
|
||||||
if (daemon(0, 0)) {
|
|
||||||
syslogger(LOG_ERR, "failed to daemonize");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* Trap signals that we expect to receive */
|
|
||||||
signal(SIGINT, child_handler);
|
|
||||||
signal(SIGTERM, child_handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
slcand_running = 1;
|
slcand_running = 1;
|
||||||
|
|
||||||
/* Now we are a daemon -- do the work for which we were paid */
|
|
||||||
fd = open(ttypath, O_RDWR | O_NONBLOCK | O_NOCTTY);
|
fd = open(ttypath, O_RDWR | O_NONBLOCK | O_NOCTTY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
syslogger(LOG_NOTICE, "failed to open TTY device %s\n", ttypath);
|
syslogger(LOG_NOTICE, "failed to open TTY device %s\n", ttypath);
|
||||||
@@ -400,6 +386,19 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Daemonize */
|
||||||
|
if (run_as_daemon) {
|
||||||
|
if (daemon(0, 0)) {
|
||||||
|
syslogger(LOG_ERR, "failed to daemonize");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* Trap signals that we expect to receive */
|
||||||
|
signal(SIGINT, child_handler);
|
||||||
|
signal(SIGTERM, child_handler);
|
||||||
|
}
|
||||||
|
|
||||||
/* The Big Loop */
|
/* The Big Loop */
|
||||||
while (slcand_running)
|
while (slcand_running)
|
||||||
sleep(1); /* wait 1 second */
|
sleep(1); /* wait 1 second */
|
||||||
|
|||||||
Reference in New Issue
Block a user