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

Use close_range #39

Merged
merged 1 commit into from
Aug 8, 2022
Merged

Use close_range #39

merged 1 commit into from
Aug 8, 2022

Conversation

kazuho
Copy link
Member

@kazuho kazuho commented Aug 8, 2022

This PR:

  • refactors the code, we always rely on closefrom
  • on non-BSD systems, use a loop-based implementation of closefrom, with a tweak on linux to try close_range at first (a syscall available on linux 5.09 and above).

…e_range` at first then falling-back to a loop.
@jhatala
Copy link

jhatala commented Aug 8, 2022

The syscall fails with EPERM under docker unless I start the container with --privileged.

It appears that it is due to docker's allow-list approach to new syscalls: docker/for-linux#1262.

#include <sys/syscall.h>
#include <unistd.h>
#include <err.h>
#include <stdio.h>
#include <fcntl.h>

int main(void)
{
        for (int i = 0; i < 10; ++i) {
                (void)open("/dev/null", O_RDONLY);
        }

        if (syscall(__NR_close_range, 3, ~0, 0) == 0) {
                printf("Success.\n");
        } else {
                err(1, "close_range");
        }
        return 0;
}
$ docker run --rm -it -v $PWD:$PWD ubuntu:latest $PWD/doit
doit: close_range: Operation not permitted

$ docker run --privileged --rm -it -v $PWD:$PWD ubuntu:latest $PWD/doit
Success.

$ docker --version
Docker version 20.10.5, build 55c4c88966

@kazuho
Copy link
Member Author

kazuho commented Aug 8, 2022

@jhatala

The syscall fails with EPERM under docker unless I start the container with --privileged.

Oh that's understandable but unfortunate.

OTOH, I do not think that's an blocker for us, as we have a fallback. Note also that h2o uses --privileged option (https://github.com/h2o/h2o/blob/f7eeb02b7fe4933bab57ee1922baf1cad2e3087f/misc/docker-ci/check.mk#L8).

Please let me know if you have issues.

@kazuho kazuho merged commit a4184b3 into master Aug 8, 2022
@kazuho kazuho mentioned this pull request Aug 8, 2022
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.

2 participants