Skip to content

update cgroups-rs in crates.io to v0.4.1 #155

Description

@was-saw

When will the package version on crates.io be updated? The style of systemd's version is sometimes different, and the current cgroups-rs v0.4 will crash sometiomes because it fails to parse the systemd version.

old code:

    fn set(&mut self, resources: &LinuxResources) -> Result<()> {
        let mut props = vec![];

        let systemd_version = self.systemd_client.systemd_version()?;

        if let Some(linux_cpu) = resources.cpu() {
            self.set_cpuset(&mut props, linux_cpu, systemd_version)?;
            self.set_cpu(&mut props, linux_cpu, systemd_version)?;
        }

        if let Some(linux_memory) = resources.memory() {
            self.set_memory(&mut props, linux_memory)?;
        }

        if let Some(linux_pids) = resources.pids() {
            self.set_pids(&mut props, linux_pids)?;
        }

        self.systemd_client.set_properties(&props)?;

        Ok(())
    }
--------------------------------------------------------------------------
    pub fn systemd_version(&self) -> Result<usize> {
        let sys_proxy = systemd_manager_proxy()?;

        // Parse 249 from "249.11-0ubuntu3.16"
        let version = sys_proxy.version()?;
        let version = version
            .split('.')
            .next()
            .and_then(|v| v.parse::<usize>().ok())
            .ok_or(Error::CorruptedSystemdVersion(version))?;

        Ok(version)
    }

new code:

fn set(&mut self, resources: &LinuxResources) -> Result<()> {
let mut props = vec![];
if let Some(linux_cpu) = resources.cpu() {
self.set_cpuset(&mut props, linux_cpu)?;
self.set_cpu(&mut props, linux_cpu)?;
}
if let Some(linux_memory) = resources.memory() {
self.set_memory(&mut props, linux_memory)?;
}
if let Some(linux_pids) = resources.pids() {
self.set_pids(&mut props, linux_pids)?;
}
self.systemd_client.set_properties(&props)?;
Ok(())
}

$ systemctl --version    
systemd 258 (258-4-arch)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions