rest-server: remove lazy_static dependency
Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
This commit is contained in:
parent
692231d2a4
commit
25f83bce19
@ -6,6 +6,7 @@ edition.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
description = "REST server implementation"
|
||||
rust-version.workspace = true
|
||||
|
||||
exclude.workspace = true
|
||||
|
||||
@ -19,7 +20,6 @@ futures.workspace = true
|
||||
handlebars = { workspace = true, optional = true }
|
||||
http.workspace = true
|
||||
hyper = { workspace = true, features = [ "full" ] }
|
||||
lazy_static.workspace = true
|
||||
libc.workspace = true
|
||||
log.workspace = true
|
||||
nix.workspace = true
|
||||
|
@ -1,13 +1,12 @@
|
||||
use std::collections::HashMap;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::{LazyLock, Mutex};
|
||||
|
||||
use anyhow::{bail, format_err, Error};
|
||||
use http::request::Parts;
|
||||
use http::HeaderMap;
|
||||
use hyper::{Body, Method, Response};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use proxmox_router::{
|
||||
list_subdirs_api_method, Router, RpcEnvironmentType, SubdirMap, UserInformation,
|
||||
@ -70,9 +69,8 @@ fn ping() -> Result<String, Error> {
|
||||
Ok("pong".to_string())
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref ITEM_MAP: Mutex<HashMap<String, String>> = Mutex::new(HashMap::new());
|
||||
}
|
||||
static ITEM_MAP: LazyLock<Mutex<HashMap<String, String>>> =
|
||||
LazyLock::new(|| Mutex::new(HashMap::new()));
|
||||
|
||||
#[api]
|
||||
/// Lists all current items
|
||||
|
@ -17,6 +17,7 @@
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||
|
||||
use std::fmt;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use anyhow::{format_err, Error};
|
||||
use nix::unistd::Pid;
|
||||
@ -46,10 +47,12 @@ pub use worker_task::*;
|
||||
mod h2service;
|
||||
pub use h2service::*;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref PID: i32 = unsafe { libc::getpid() };
|
||||
static ref PSTART: u64 = PidStat::read_from_pid(Pid::from_raw(*PID)).unwrap().starttime;
|
||||
}
|
||||
static PID: LazyLock<i32> = LazyLock::new(|| unsafe { libc::getpid() });
|
||||
static PSTART: LazyLock<u64> = LazyLock::new(|| {
|
||||
PidStat::read_from_pid(Pid::from_raw(*PID))
|
||||
.unwrap()
|
||||
.starttime
|
||||
});
|
||||
|
||||
/// Returns the current process ID (see [libc::getpid])
|
||||
///
|
||||
|
@ -4,7 +4,7 @@ use std::hash::BuildHasher;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::pin::Pin;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, LazyLock, Mutex};
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use anyhow::{bail, format_err, Error};
|
||||
@ -14,7 +14,6 @@ use hyper::body::HttpBody;
|
||||
use hyper::header::{self, HeaderMap};
|
||||
use hyper::http::request::Parts;
|
||||
use hyper::{Body, Request, Response, StatusCode};
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use serde_json::Value;
|
||||
use tokio::fs::File;
|
||||
@ -289,9 +288,7 @@ fn log_response(
|
||||
}
|
||||
|
||||
fn get_proxied_peer(headers: &HeaderMap) -> Option<std::net::SocketAddr> {
|
||||
lazy_static! {
|
||||
static ref RE: Regex = Regex::new(r#"for="([^"]+)""#).unwrap();
|
||||
}
|
||||
static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r#"for="([^"]+)""#).unwrap());
|
||||
let forwarded = headers.get(header::FORWARDED)?.to_str().ok()?;
|
||||
let capture = RE.captures(forwarded)?;
|
||||
let rhost = capture.get(1)?.as_str();
|
||||
|
@ -4,12 +4,11 @@ use std::io::{BufRead, BufReader, Read, Write};
|
||||
use std::panic::UnwindSafe;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
use std::sync::{Arc, Mutex, OnceLock};
|
||||
use std::sync::{Arc, LazyLock, Mutex, OnceLock};
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use anyhow::{bail, format_err, Error};
|
||||
use futures::*;
|
||||
use lazy_static::lazy_static;
|
||||
use nix::fcntl::OFlag;
|
||||
use once_cell::sync::OnceCell;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -497,10 +496,8 @@ pub fn upid_read_status(upid: &UPID) -> Result<TaskState, Error> {
|
||||
Ok(TaskState::Unknown { endtime }) // no last line with both, end-time and task-state, found.
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref WORKER_TASK_LIST: Mutex<HashMap<usize, Arc<WorkerTask>>> =
|
||||
Mutex::new(HashMap::new());
|
||||
}
|
||||
static WORKER_TASK_LIST: LazyLock<Mutex<HashMap<usize, Arc<WorkerTask>>>> =
|
||||
LazyLock::new(|| Mutex::new(HashMap::new()));
|
||||
|
||||
/// checks if the task UPID refers to a worker from this process
|
||||
fn is_local_worker(upid: &UPID) -> bool {
|
||||
|
Loading…
Reference in New Issue
Block a user