From d363254f6e5e5e1dc4f660cbec873c94fb733ce7 Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Tue, 9 Dec 2025 22:08:22 +0100 Subject: [PATCH] Use OsStr for systemd unit exec value --- src/builder.rs | 4 ++-- src/resources/mod.rs | 7 ++++--- src/templates/systemd.rs | 7 ++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 5652a07..cefa680 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -456,11 +456,11 @@ impl> ImplementationBuilder> for De FileSymbol::new( conf_path.clone_rc(), if resource.4 { - systemd_nodejs_service(&resource.2, socket_path, &resource.3) + systemd_nodejs_service(resource.2.as_ref(), socket_path, &resource.3) } else { systemd_socket_service( socket_path, - resource.2.as_ref().to_str().unwrap(), + &resource.2, &resource.3, "", ) diff --git a/src/resources/mod.rs b/src/resources/mod.rs index 06daa5f..9115201 100644 --- a/src/resources/mod.rs +++ b/src/resources/mod.rs @@ -5,6 +5,7 @@ use crate::artifacts::{ use crate::templates::php::FpmPoolConfig; use std::hash::Hash; use std::path::Path; +use std::ffi::OsStr; pub trait Resource { type Artifact; @@ -136,7 +137,7 @@ impl Resource for User { } #[derive(Debug, Hash, PartialEq, Eq)] -pub struct SystemdSocketService(pub D, pub &'static str, pub P, pub P, pub bool); +pub struct SystemdSocketService(pub D, pub &'static str, pub Rc, pub P, pub bool); impl Resource for SystemdSocketService { type Artifact = (PathArtifact, PathArtifact, UserNameArtifact); } @@ -179,7 +180,7 @@ impl Resource for ServePhp { // Domain, service name, exec, static, dir #[derive(Debug, Hash, PartialEq, Eq)] -pub struct ServeService(pub D, pub &'static str, pub P, pub P, pub P, pub bool); +pub struct ServeService(pub D, pub &'static str, pub Rc, pub P, pub P, pub bool); impl Resource for ServeService { type Artifact = PathArtifact; } @@ -187,7 +188,7 @@ impl ServeService> { pub fn new( domain: D, service_name: &'static str, - exec: impl Into>, + exec: impl Into>, static_path: impl Into>, working_directory: impl Into>, is_nodejs: bool, diff --git a/src/templates/systemd.rs b/src/templates/systemd.rs index 58f84da..4fb8aa1 100644 --- a/src/templates/systemd.rs +++ b/src/templates/systemd.rs @@ -1,8 +1,9 @@ use std::path::Path; +use std::ffi::OsStr; pub fn socket_service( socket_path: impl AsRef, - exec: &str, + exec: &OsStr, dir: impl AsRef, additional: &str, ) -> String { @@ -18,7 +19,7 @@ Restart=always WantedBy=default.target ", socket_path.as_ref().to_str().unwrap(), - exec, + exec.display(), dir.as_ref().to_str().unwrap(), additional ) @@ -31,7 +32,7 @@ pub fn nodejs_service, S: AsRef>( ) -> String { socket_service( &socket_path, - &format!("/usr/bin/nodejs {}", nodejs_path.as_ref().to_str().unwrap()), + format!("/usr/bin/nodejs {}", nodejs_path.as_ref().to_str().unwrap()).as_ref(), dir, &format!( "Environment=NODE_ENV=production