Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement FD_CLOEXEC #217

Open
afxgroup opened this issue Nov 30, 2024 · 0 comments
Open

Implement FD_CLOEXEC #217

afxgroup opened this issue Nov 30, 2024 · 0 comments

Comments

@afxgroup
Copy link
Collaborator

When you have a piece of code like this:

/* Make sure we close the file descriptor on exec.  */
int flags = fcntl (fileno (mallstream), F_GETFD, 0);
if (flags >= 0) {
  flags |= FD_CLOEXEC;
  fcntl (fileno (mallstream), F_SETFD, flags);
}

We need to take care on file destructor to close the stream when an exe is spawned.

in init_exit.c on stdio folder there is a test when to close a file:

if (FLAG_IS_SET(__clib4->__fd[i]->fd_Flags, FDF_IN_USE) && FLAG_IS_CLEAR(__clib4->__fd[i]->fd_Flags, FDF_NO_CLOSE)) {

We can add a test on FDF_CLOEXEC there. However FDF_CLOEXEC is only set on pipe2 function and needs to be set also on fcntl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant