linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Armin Burchardt <armin@uni-bremen.de>, linux-can@vger.kernel.org
Subject: Re: [PATCH 1/3] slcand: daemonize _after_ interface is created, renamed and up.
Date: Mon, 8 Jun 2015 14:51:26 +0200	[thread overview]
Message-ID: <55758FCE.4050109@pengutronix.de> (raw)
In-Reply-To: <1433764540-24917-1-git-send-email-armin@uni-bremen.de>

[-- Attachment #1: Type: text/plain, Size: 2152 bytes --]

On 06/08/2015 01:55 PM, Armin Burchardt wrote:
> 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 {

Please change to

} else {

> +		/* Trap signals that we expect to receive */
> +		signal(SIGINT, child_handler);
> +		signal(SIGTERM, child_handler);
> +	}
> +
> +	/* */

Empty comment? I know you just moved the code around :)

> +	slcand_running = 1;
> +
>  	/* The Big Loop */
>  	while (slcand_running)
>  		sleep(1); /* wait 1 second */
> 

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

  parent reply	other threads:[~2015-06-08 12:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Marc Kleine-Budde [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55758FCE.4050109@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=armin@uni-bremen.de \
    --cc=linux-can@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).