Skip to content

Can't mount cgroups #572

Open
Open
@singron

Description

@singron

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @singron@Susurrus

        Issue actions

          Can't mount cgroups · Issue #572 · nix-rust/nix