Geal / rust-syslog

Send syslog messages from Rust
MIT License
109 stars 55 forks source link

Formatter*::pid takes i32, but std::process::id returns u32 #46

Closed jac-leadnav closed 2 years ago

jac-leadnav commented 4 years ago

All,

In order to run properly, I must do the following:

    /* get our process id (syslog takes i32, but we get u32) */
    let p = process::id();
    let pid = if p > std::i32::MAX as u32 {
        0
    } else {
        p as i32
    };

    /* format for our syslog messages */
    let formatter = Formatter3164 {
        facility: Facility::LOG_USER,
        hostname: None,
        process: "myrustprocess".into(),
        pid: pid,
    };

If we could change the type of pid to be u32, then we wouldn't have to jump through the overflow check...

I've checked and both Formatter* structs are i32 for pid

Thanks!

Jason

carnott-snap commented 4 years ago

It looks like internally libc::getpid, not std::process::id is used (see syslog::get_process_info), and that is the source of the i32.

It would be a breaking change to fix this, and there may be good reason to use libc over std, but I cannot conceive of it, thus would appreciate a new major version to make this more ergonomic.