update to nix 0.24 / rustyline 9 / proxmox-sys 0.3

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler
2022-06-02 13:10:33 +02:00
parent 68a6e970d4
commit 11ca834317
34 changed files with 95 additions and 78 deletions

View File

@ -5,4 +5,5 @@ authors = ["Proxmox Support Team <support@proxmox.com>"]
edition = "2018"
[dependencies]
nix = "0.19.1"
anyhow = "1"
nix = "0.24"

View File

@ -1,12 +1,29 @@
use anyhow::{format_err, Error};
use std::fmt::Write;
use std::fs;
use std::net::ToSocketAddrs;
use std::os::unix::prelude::OsStrExt;
use nix::sys::utsname::uname;
fn nodename() -> Result<String, Error> {
let uname = uname().map_err(|err| format_err!("uname() failed - {err}"))?; // save on stack to avoid to_owned() allocation below
std::str::from_utf8(uname.nodename().as_bytes())?
.split('.')
.next()
.ok_or_else(|| format_err!("Failed to split FQDN to get hostname"))
.map(|s| s.to_owned())
}
fn main() {
let uname = uname(); // save on stack to avoid to_owned() allocation below
let nodename = uname.nodename().split('.').next().unwrap();
let nodename = match nodename() {
Ok(value) => value,
Err(err) => {
eprintln!("Failed to retrieve hostname: {err}");
"INVALID".to_string()
}
};
let addr = format!("{}:8007", nodename);