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

Can't mount cgroups #572

Open
singron opened this issue Apr 8, 2017 · 0 comments
Open

Can't mount cgroups #572

singron opened this issue Apr 8, 2017 · 0 comments

Comments

@singron
Copy link

singron commented Apr 8, 2017

Mounting cgroupsv2 in linux requires passing NULL as the data parameter of the mount syscall. NixPath coerces None into an empty string instead. Constructing a null CStr is a little tricky and requires unsafe.

You can see the check in kernel/cgroup/cgroup.c. Mount returns EINVAL and the kernel prints cgroup2: unknown option "".

I was able to workaround by defining this struct

struct NullString;

impl nix::NixPath for NullString {
    fn len(&self) -> usize { 0 }
    fn with_nix_path<T, F>(&self, f: F) -> nix::Result<T>
        where F: FnOnce(&CStr) -> T {
        Ok(f(unsafe {
            // CStr::from_ptr calls strlen and segfaults
            CStr::from_bytes_with_nul_unchecked(
                std::slice::from_raw_parts(std::ptr::null(), 0))
        }))
    }
}

And then providing Some(&NullString) as the data argument of mount. I saw #221 about redesigning NixPath so I didn't want to attempt "fixing" this.

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

No branches or pull requests

2 participants