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