linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] slcand: daemonize _after_ interface is created, renamed and up.
@ 2015-06-08 11:55 Armin Burchardt
  2015-06-08 11:55 ` [PATCH 2/3] slcand: add option -p<file> to write pid to a file Armin Burchardt
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Armin Burchardt @ 2015-06-08 11:55 UTC (permalink / raw)
  To: linux-can; +Cc: Armin Burchardt

Create interface, then daemonize to avoid race-conditions,
ie. in init.d-scripts.

Signed-off-by: Armin Burchardt <armin@uni-bremen.de>
---
 slcand.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/slcand.c b/slcand.c
index e5e4752..af7ca98 100644
--- a/slcand.c
+++ b/slcand.c
@@ -255,23 +255,7 @@ int main(int argc, char *argv[])
 
 	syslog(LOG_INFO, "starting on TTY device %s", ttypath);
 
-	/* Daemonize */
-	if (run_as_daemon) {
-		if (daemon(0, 0)) {
-			syslog(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;
-
-	/* Now we are a daemon -- do the work for which we were paid */
+	/* Create file handle for tty device. */
 	fd = open(ttypath, O_RDWR | O_NONBLOCK | O_NOCTTY);
 	if (fd < 0) {
 		syslog(LOG_NOTICE, "failed to open TTY device %s\n", ttypath);
@@ -365,6 +349,23 @@ int main(int argc, char *argv[])
 		}	
 	}
 
+	/* Daemonize (_after_ interface is up to avoid race-conditions,
+	 * ie. between init.d-scripts). */
+	if (run_as_daemon) {
+		if (daemon(0, 0)) {
+			syslog(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;
+
 	/* The Big Loop */
 	while (slcand_running)
 		sleep(1); /* wait 1 second */
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-06-09  9:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-08 11:55 [PATCH 1/3] slcand: daemonize _after_ interface is created, renamed and up Armin Burchardt
2015-06-08 11:55 ` [PATCH 2/3] slcand: add option -p<file> to write pid to a file Armin Burchardt
2015-06-08 13:00   ` Marc Kleine-Budde
2015-06-08 13:43     ` Armin Burchardt
2015-06-08 13:55       ` Marc Kleine-Budde
2015-06-08 11:55 ` [PATCH 3/3] slcand: add option -u to set interface up/down state Armin Burchardt
2015-06-08 12:51 ` [PATCH 1/3] slcand: daemonize _after_ interface is created, renamed and up Marc Kleine-Budde
2015-06-09  9:15 ` [PATCH v2 0/3] slcand: improved patches Armin Burchardt
2015-06-09  9:15   ` [PATCH v2 1/3] slcand: daemonize _after_ interface is created and renamed Armin Burchardt
2015-06-09  9:15   ` [PATCH v2 2/3] slcand: add option -p<file> to write pid to a file Armin Burchardt
2015-06-09  9:15   ` [PATCH v2 3/3] slcand: add option -u to set interface up/down state Armin Burchardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).