~vpzom/shoved

737c06e7556a31e629386002b6b299a420822372 — Colin Reeder 1 year, 19 days ago ac0ad5d
Make register command work with system daemon
1 files changed, 13 insertions(+), 6 deletions(-)

M examples/register.rs
M examples/register.rs => examples/register.rs +13 -6
@@ 1,20 1,27 @@
use std::io::Write;

fn main() {
    let system = false;

    let exec = std::env::args().skip(1).next().expect("Missing executable");

    let client_socket_path = if system {
        std::path::PathBuf::from("/var/run/shoved.sock")
    } else {
    let user_path = {
        let mut path = dirs::runtime_dir().unwrap_or_else(|| std::path::PathBuf::from("/tmp"));
        path.push("shoved.sock");

        path
    };

    let mut stream = std::os::unix::net::UnixStream::connect(client_socket_path).unwrap();
    let system_path = "/var/run/shoved.sock";

    let mut stream = match std::os::unix::net::UnixStream::connect(user_path) {
        Ok(stream) => Ok(stream),
        Err(err) => match err.kind() {
            std::io::ErrorKind::NotFound | std::io::ErrorKind::ConnectionRefused => {
                std::os::unix::net::UnixStream::connect(system_path)
            }
            _ => Err(err),
        },
    }
    .unwrap();

    stream
        .write_all(