All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Blanc <julien.blanc@sprinte.eu>
To: Steve Freyder <steve@freyder.net>,
	xenomai@xenomai.org, Philippe Gerum <rpm@xenomai.org>
Subject: Re: having problems with daemonizing
Date: Mon, 29 Apr 2019 09:12:37 +0200	[thread overview]
Message-ID: <acf4207114cc324d0b7001985eade534d6e3c4be.camel@sprinte.eu> (raw)
In-Reply-To: <5CC38412.8030107@freyder.net>

Le vendredi 26 avril 2019 à 17:20 -0500, Steve Freyder via Xenomai a
écrit :
> 
> I can tell you that I have a hang issue due to fork() in a Xenomai
> program if, after the fork(), I don't do an exec().  I believe
> the hang is related to registry access, and the fact that the
> Unix domain socket connecting to sysregd that is inherited by
> the forked process (which has FD_CLOEXEC set) hasn't yet gotten
> closed (no exec() yet so no action on FD_CLOEXEC flags yet).

We ran into a similar issue (still using 3.0.5, which seems not to have
the FD_CLOEXEC flag set).

If you don’t share any file descriptors with the child process, the
following (after the fork and before the exec) did help in our case :

DIR* dirs = opendir("/proc/self/fd");
int fd = dirfd(dirs);
dirent* d = readdir(dirs);
while (d != nullptr)
{
	int a = 0;
	a = std::strtol(d->d_name, nullptr, 10);
	if (errno == 0 && a > 2 && a != fd)
	{
		close(a);
	}
	d = readdir(dirs);
}
closedir(dirs);

Basically it closes any open file descriptor by the child process,
except stdout/stderr.

Note that we are forking from a linux domain thread hosted in a xenomai
application, creating a pure linux application. In that case the
registry stuff is complete nonsense in the child process. But this
should also be ok for other use cases.

Regards,

Julien



  parent reply	other threads:[~2019-04-29  7:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-26 21:18 having problems with daemonizing Lowell Gilbert
2019-04-26 22:20 ` Steve Freyder
2019-04-28 15:26   ` Philippe Gerum
2019-04-29 15:05     ` Lowell Gilbert
2019-05-03 11:12     ` Philippe Gerum
2019-05-03 14:26       ` Lowell Gilbert
2019-05-03 15:10         ` Philippe Gerum
2019-04-29  7:12   ` Julien Blanc [this message]
2019-04-29 12:35 ` Lange Norbert

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=acf4207114cc324d0b7001985eade534d6e3c4be.camel@sprinte.eu \
    --to=julien.blanc@sprinte.eu \
    --cc=rpm@xenomai.org \
    --cc=steve@freyder.net \
    --cc=xenomai@xenomai.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.