summaryrefslogtreecommitdiff
path: root/src/systemd/job.rs
blob: 68fb18d996c74d792a20d6ff7da8383b0e85e3bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::collections::HashMap;
use std::process::Command;

use std::io;

#[derive(Debug)]
pub struct Unit {
    name: String,
    type_: String
}

pub fn get_jobs() -> io::Result<Vec<Unit>> {
    let mut units = Vec::new();
    let status = try!(Command::new("systemctl")
        .args(&["show", "*"]).output());

    for line in String::from_utf8_lossy(&status.stdout).split('\n') {
        let words = line.split('=').collect::<Vec<&str>>();
        if words.len() == 2 && words[0] == "Id" {
            units.push(Unit { name: words[1].to_owned(), type_: "Unknown".to_owned() });
        }
    }
    return Ok(units);
}