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

Follow o_cloexe semantics when calling the exec function #11036

Merged
merged 4 commits into from Oct 27, 2023

Conversation

Donny9
Copy link
Contributor

@Donny9 Donny9 commented Oct 25, 2023

Summary

sched/task: close file descriptor with O_CLOEXEC before active task or exec

modify:

  1. Ensure that the child task copies all fds of the parent task,
    including those with O_CLOEXE.
  2. Make sure spawn_file_action is executed under fd with O_CLOEXEC,
    otherwise it will fail.
  3. When a new task is activated or exec is called, close all fds
    with O_CLOEXEC flags.

fs/dup3: impletement dup3/nx_dup3_from_tcb function

 refs: https://man7.org/linux/man-pages/man2/dup.2.html

fs/dup/dup2: don't add O_CLOEXEC for new file descriptor

refs: https://man7.org/linux/man-pages/man2/dup.2.html

The two file descriptors do not share file descriptor flags (the
close-on-exec flag).  The close-on-exec flag (FD_CLOEXEC; see
fcntl(2)) for the duplicate descriptor is off.

libs/lib_psfa_adddup2.c: remove workaround aboud dup2

Because popen no longer needs to rely on intermediate
tasks to start command tasks.

Impact

posix_spawn/exec_module/task_create/... with exec or start new task

Testing

Vela

@acassis
Copy link
Contributor

acassis commented Oct 25, 2023

@Donny9 I think it should be a nice idea to include a popen test to apps/testing/ostest. Testing only on Vela will be like "It works on my machine" TM! :-D

@xiaoxiang781216
Copy link
Contributor

@Donny9 I think it should be a nice idea to include a popen test to apps/testing/ostest. Testing only on Vela will be like "It works on my machine" TM! :-D

apache/nuttx-apps#2163 contain the related change to make popen more conform the standard

@acassis
Copy link
Contributor

acassis commented Oct 25, 2023

@Donny9 I think it should be a nice idea to include a popen test to apps/testing/ostest. Testing only on Vela will be like "It works on my machine" TM! :-D

apache/nuttx-apps#2163 contain the related change to make popen more conform the standard

@xiaoxiang781216 actually it only created the popen() function. I'm talking about adding a popen() test into ostest

@Donny9
Copy link
Contributor Author

Donny9 commented Oct 26, 2023

@Donny9 I think it should be a nice idea to include a popen test to apps/testing/ostest. Testing only on Vela will be like "It works on my machine" TM! :-D

apache/nuttx-apps#2163 contain the related change to make popen more conform the standard

@xiaoxiang781216 actually it only created the popen() function. I'm talking about adding a popen() test into ostest

@acassis OK, I will add popen test to ostest in another PR soon~, so we can merge this pr first, thanks~

@xiaoxiang781216
Copy link
Contributor

@Donny9 please rebase the patch

@Donny9
Copy link
Contributor Author

Donny9 commented Oct 26, 2023

@Donny9 please rebase the patch

Done~

Because popen no longer needs to rely on intermediate
tasks to start command tasks.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
refs: https://man7.org/linux/man-pages/man2/dup.2.html

The two file descriptors do not share file descriptor flags (the
close-on-exec flag).  The close-on-exec flag (FD_CLOEXEC; see
fcntl(2)) for the duplicate descriptor is off.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
…r exec

VELAPLATFO-18473

refs:
https://man7.org/linux/man-pages/man2/fcntl.2.html
If the FD_CLOEXEC bit is set, the file descriptor will automatically
be closed during a successful execve(2).
(If the execve(2) fails, the file descriptor is left open.)

modify:
1. Ensure that the child task copies all fds of the parent task,
   including those with O_CLOEXE.
2. Make sure spawn_file_action is executed under fd with O_CLOEXEC,
   otherwise it will fail.
3. When a new task is activated or exec is called, close all fds
   with O_CLOEXEC flags.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
@xiaoxiang781216 xiaoxiang781216 merged commit 18819b6 into apache:master Oct 27, 2023
26 checks passed
@jerpelea jerpelea added this to To-Add in Release Notes - 12.4.0 Dec 27, 2023
@jerpelea jerpelea moved this from To-Add to processed in Release Notes - 12.4.0 Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants