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 --preserve-fds flag #177

Merged
merged 5 commits into from
Aug 2, 2021
Merged

Implement --preserve-fds flag #177

merged 5 commits into from
Aug 2, 2021

Conversation

yihuaf
Copy link
Collaborator

@yihuaf yihuaf commented Aug 2, 2021

Fix #145.

Note, the "LISTEN_FDS" and "LISTEN_PID" are not addressed in this PR. They are used for systemd and require us to also set the environment variables correctly. I or someone else will/should address these two in a different PR. This PR only addressed the --preserve-fds flag.

Test:
Using busy box, before --preserve-fds flag, a number of fds that should be closed.

/ # ls -ahl /proc/1/fd
total 0      
dr-x------    2 root     root           0 Aug  2 02:52 .
dr-xr-xr-x    9 root     root           0 Aug  2 02:52 ..
lrwx------    1 root     root          64 Aug  2 02:52 0 -> /4
lrwx------    1 root     root          64 Aug  2 02:52 1 -> /4
lrwx------    1 root     root          64 Aug  2 02:52 10 -> /dev/tty
lrwx------    1 root     root          64 Aug  2 02:52 13 -> /ptmx
lrwx------    1 root     root          64 Aug  2 02:52 14 -> /4
lrwx------    1 root     root          64 Aug  2 02:52 2 -> /4
lrwx------    1 root     root          64 Aug  2 02:52 3 -> socket:[1496697]
lr-x------    1 root     root          64 Aug  2 02:52 5 -> /

after, correctly only leaving 0,1,2 fds. 10 is tty opened for shell.

/ # ls -ahl /proc/1/fd
total 0      
dr-x------    2 root     root           0 Aug  2 02:53 .
dr-xr-xr-x    9 root     root           0 Aug  2 02:53 ..
lrwx------    1 root     root          64 Aug  2 02:53 0 -> /4
lrwx------    1 root     root          64 Aug  2 02:53 1 -> /4
lrwx------    1 root     root          64 Aug  2 02:53 10 -> /dev/tty
lrwx------    1 root     root          64 Aug  2 02:53 2 -> /4
/ # 

@Furisto
Copy link
Collaborator

Furisto commented Aug 2, 2021

@yihuaf Looks good to me. Just for my own understanding: Why does the tty stay open? If you close all file descriptors above 2, wouldn't it also be closed?

@Furisto Furisto merged commit 4c0fee1 into youki-dev:main Aug 2, 2021
@yihuaf
Copy link
Collaborator Author

yihuaf commented Aug 2, 2021

@yihuaf Looks good to me. Just for my own understanding: Why does the tty stay open? If you close all file descriptors above 2, wouldn't it also be closed?

I believe the tty is newly opened after we launch into a shell through docker, after the execvp.

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

Successfully merging this pull request may close these issues.

implementation of --preserve-fds
2 participants