all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 03/16] move src/tools/daemon.rs to proxmox-rest-server workspace
Date: Tue, 21 Sep 2021 07:58:41 +0200	[thread overview]
Message-ID: <20210921055854.3799470-4-dietmar@proxmox.com> (raw)
In-Reply-To: <20210921055854.3799470-1-dietmar@proxmox.com>

---
 proxmox-rest-server/Cargo.toml                |  1 +
 .../src}/daemon.rs                            | 13 ++++----
 proxmox-rest-server/src/lib.rs                | 31 ++++++++++++++++++-
 src/api2/node/mod.rs                          |  2 +-
 src/bin/proxmox-backup-api.rs                 |  3 +-
 src/bin/proxmox-backup-proxy.rs               |  3 +-
 src/tools/mod.rs                              | 27 ----------------
 7 files changed, 43 insertions(+), 37 deletions(-)
 rename {src/tools => proxmox-rest-server/src}/daemon.rs (97%)

diff --git a/proxmox-rest-server/Cargo.toml b/proxmox-rest-server/Cargo.toml
index 33ed6f39..4d1f1459 100644
--- a/proxmox-rest-server/Cargo.toml
+++ b/proxmox-rest-server/Cargo.toml
@@ -13,6 +13,7 @@ http = "0.2"
 hyper = { version = "0.14", features = [ "full" ] }
 lazy_static = "1.4"
 libc = "0.2"
+log = "0.4"
 nix = "0.19.1"
 serde = { version = "1.0", features = [] }
 serde_json = "1.0"
diff --git a/src/tools/daemon.rs b/proxmox-rest-server/src/daemon.rs
similarity index 97%
rename from src/tools/daemon.rs
rename to proxmox-rest-server/src/daemon.rs
index 1291601b..5401e30c 100644
--- a/src/tools/daemon.rs
+++ b/proxmox-rest-server/src/daemon.rs
@@ -15,8 +15,9 @@ use anyhow::{bail, format_err, Error};
 use futures::future::{self, Either};
 
 use proxmox::tools::io::{ReadExt, WriteExt};
+use proxmox::tools::fd::Fd;
 
-use crate::tools::{fd_change_cloexec, self};
+use crate::fd_change_cloexec;
 
 #[link(name = "systemd")]
 extern "C" {
@@ -218,7 +219,7 @@ impl Reloadable for tokio::net::TcpListener {
     // FIXME: We could become "independent" of the TcpListener and its reference to the file
     // descriptor by `dup()`ing it (and check if the listener still exists via kcmp()?)
     fn get_store_func(&self) -> Result<BoxedStoreFunc, Error> {
-        let mut fd_opt = Some(tools::Fd(
+        let mut fd_opt = Some(Fd(
             nix::fcntl::fcntl(self.as_raw_fd(), nix::fcntl::FcntlArg::F_DUPFD_CLOEXEC(0))?
         ));
         Ok(Box::new(move || {
@@ -273,11 +274,11 @@ where
     ).await?;
 
     let server_future = create_service(listener, NotifyReady)?;
-    let shutdown_future = proxmox_rest_server::shutdown_future();
+    let shutdown_future = crate::shutdown_future();
 
     let finish_future = match future::select(server_future, shutdown_future).await {
         Either::Left((_, _)) => {
-            proxmox_rest_server::request_shutdown(); // make sure we are in shutdown mode
+            crate::request_shutdown(); // make sure we are in shutdown mode
             None
         }
         Either::Right((_, server_future)) => Some(server_future),
@@ -285,7 +286,7 @@ where
 
     let mut reloader = Some(reloader);
 
-    if proxmox_rest_server::is_reload_request() {
+    if crate::is_reload_request() {
         log::info!("daemon reload...");
         if let Err(e) = systemd_notify(SystemdNotify::Reloading) {
             log::error!("failed to notify systemd about the state change: {}", e);
@@ -304,7 +305,7 @@ where
     }
 
     // FIXME: this is a hack, replace with sd_notify_barrier when available
-    if proxmox_rest_server::is_reload_request() {
+    if crate::is_reload_request() {
         wait_service_is_not_state(service_name, "reloading").await?;
     }
 
diff --git a/proxmox-rest-server/src/lib.rs b/proxmox-rest-server/src/lib.rs
index 38dd610c..21a91115 100644
--- a/proxmox-rest-server/src/lib.rs
+++ b/proxmox-rest-server/src/lib.rs
@@ -1,4 +1,10 @@
-use anyhow::{bail, Error};
+use std::os::unix::io::RawFd;
+
+use anyhow::{bail, format_err, Error};
+
+use proxmox::tools::fd::Fd;
+
+pub mod daemon;
 
 mod state;
 pub use state::*;
@@ -52,3 +58,26 @@ pub fn fail_on_shutdown() -> Result<(), Error> {
     Ok(())
 }
 
+/// Helper to set/clear the FD_CLOEXEC flag on file descriptors
+pub fn fd_change_cloexec(fd: RawFd, on: bool) -> Result<(), Error> {
+    use nix::fcntl::{fcntl, FdFlag, F_GETFD, F_SETFD};
+    let mut flags = FdFlag::from_bits(fcntl(fd, F_GETFD)?)
+        .ok_or_else(|| format_err!("unhandled file flags"))?; // nix crate is stupid this way...
+    flags.set(FdFlag::FD_CLOEXEC, on);
+    fcntl(fd, F_SETFD(flags))?;
+    Ok(())
+}
+
+/// safe wrapper for `nix::sys::socket::socketpair` defaulting to `O_CLOEXEC` and guarding the file
+/// descriptors.
+pub fn socketpair() -> Result<(Fd, Fd), Error> {
+    use nix::sys::socket;
+    let (pa, pb) = socket::socketpair(
+        socket::AddressFamily::Unix,
+        socket::SockType::Stream,
+        None,
+        socket::SockFlag::SOCK_CLOEXEC,
+    )?;
+    Ok((Fd(pa), Fd(pb)))
+}
+
diff --git a/src/api2/node/mod.rs b/src/api2/node/mod.rs
index ecc1e2e0..9b31d595 100644
--- a/src/api2/node/mod.rs
+++ b/src/api2/node/mod.rs
@@ -151,7 +151,7 @@ async fn termproxy(cmd: Option<String>, rpcenv: &mut dyn RpcEnvironment) -> Resu
         move |worker| async move {
             // move inside the worker so that it survives and does not close the port
             // remove CLOEXEC from listenere so that we can reuse it in termproxy
-            tools::fd_change_cloexec(listener.as_raw_fd(), false)?;
+            proxmox_rest_server::fd_change_cloexec(listener.as_raw_fd(), false)?;
 
             let mut arguments: Vec<&str> = Vec::new();
             let fd_string = listener.as_raw_fd().to_string();
diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs
index 452bbc3a..17b6f184 100644
--- a/src/bin/proxmox-backup-api.rs
+++ b/src/bin/proxmox-backup-api.rs
@@ -13,7 +13,8 @@ use proxmox_backup::server::{
     auth::default_api_auth,
     rest::*,
 };
-use proxmox_backup::tools::daemon;
+use proxmox_rest_server::daemon;
+
 use proxmox_backup::auth_helpers::*;
 use proxmox_backup::config;
 
diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index de534a65..d4ac2a85 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -39,11 +39,12 @@ use pbs_api_types::{
     PruneOptions,
 };
 
+use proxmox_rest_server::daemon;
+
 use proxmox_backup::server;
 use proxmox_backup::auth_helpers::*;
 use proxmox_backup::tools::{
     PROXMOX_BACKUP_TCP_KEEPALIVE_TIME,
-    daemon,
     disks::{
         DiskManage,
         zfs_pool_stats,
diff --git a/src/tools/mod.rs b/src/tools/mod.rs
index f8b363f5..8fd441b5 100644
--- a/src/tools/mod.rs
+++ b/src/tools/mod.rs
@@ -2,13 +2,10 @@
 //!
 //! This is a collection of small and useful tools.
 use std::any::Any;
-use std::os::unix::io::RawFd;
 
 use anyhow::{bail, format_err, Error};
 use openssl::hash::{hash, DigestBytes, MessageDigest};
 
-pub use proxmox::tools::fd::Fd;
-
 use proxmox_http::{
     client::SimpleHttp,
     client::SimpleHttpOptions,
@@ -19,7 +16,6 @@ pub mod apt;
 pub mod async_io;
 pub mod compression;
 pub mod config;
-pub mod daemon;
 pub mod disks;
 
 pub mod serde_filter;
@@ -111,29 +107,6 @@ pub fn normalize_uri_path(path: &str) -> Result<(String, Vec<&str>), Error> {
     Ok((path, components))
 }
 
-pub fn fd_change_cloexec(fd: RawFd, on: bool) -> Result<(), Error> {
-    use nix::fcntl::{fcntl, FdFlag, F_GETFD, F_SETFD};
-    let mut flags = FdFlag::from_bits(fcntl(fd, F_GETFD)?)
-        .ok_or_else(|| format_err!("unhandled file flags"))?; // nix crate is stupid this way...
-    flags.set(FdFlag::FD_CLOEXEC, on);
-    fcntl(fd, F_SETFD(flags))?;
-    Ok(())
-}
-
-/// safe wrapper for `nix::sys::socket::socketpair` defaulting to `O_CLOEXEC` and guarding the file
-/// descriptors.
-pub fn socketpair() -> Result<(Fd, Fd), Error> {
-    use nix::sys::socket;
-    let (pa, pb) = socket::socketpair(
-        socket::AddressFamily::Unix,
-        socket::SockType::Stream,
-        None,
-        socket::SockFlag::SOCK_CLOEXEC,
-    )?;
-    Ok((Fd(pa), Fd(pb)))
-}
-
-
 /// An easy way to convert types to Any
 ///
 /// Mostly useful to downcast trait objects (see RpcEnvironment).
-- 
2.30.2





  parent reply	other threads:[~2021-09-21  5:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-21  5:58 [pbs-devel] [PATCH proxmox-backup v2 00/16] move rest server into extra crate Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 01/16] start new proxmox-rest-server workspace Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 02/16] move ApiConfig, FileLogger and CommandoSocket to " Dietmar Maurer
2021-09-21  5:58 ` Dietmar Maurer [this message]
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 04/16] move src/server/environment.rs to proxmox-rest-server crate Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 05/16] move src/server/formatter.rs " Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 06/16] move src/tools/compression.rs " Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 07/16] move normalize_uri_path and extract_cookie " Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 08/16] rest server: simplify get_index() method signature Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 09/16] make get_index and ApiConfig property (callback) Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 10/16] rest server: return UserInformation from ApiAuth::check_auth Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 11/16] rest server: do not use pbs_api_types::Authid Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 12/16] rest server: cleanup auth-log handling Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 13/16] move src/server/rest.rs to proxmox-rest-server crate Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 14/16] move proxmox_restore_daemon code into extra crate Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 15/16] basically a (semantic) revert of commit 991be99c37c6f55f43a3d9a2c54edb2a8dc6d4f2 "buildsys: workaround linkage issues from openid/curl build server stuff separate" Dietmar Maurer
2021-09-21  5:58 ` [pbs-devel] [PATCH proxmox-backup v2 16/16] worker_state: move tasktype() code to src/api2/node/tasks.rs Dietmar Maurer
2021-09-21  7:37 ` [pbs-devel] applied-series: [PATCH proxmox-backup v2 00/16] move rest server into extra crate Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210921055854.3799470-4-dietmar@proxmox.com \
    --to=dietmar@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal