quote init systemd execstart paths

This commit is contained in:
sabraman 2026-03-22 23:52:01 +03:00
parent e35d69c61f
commit 25d72ac039
1 changed files with 18 additions and 4 deletions

View File

@ -7,11 +7,17 @@ use std::process::Command;
/// Options for the init command /// Options for the init command
pub struct InitOptions { pub struct InitOptions {
/// Listen port for the generated proxy configuration.
pub port: u16, pub port: u16,
/// TLS masking domain written into the generated configuration.
pub domain: String, pub domain: String,
/// Optional user-provided MTProxy secret in hex form.
pub secret: Option<String>, pub secret: Option<String>,
/// Username inserted into the generated access configuration.
pub username: String, pub username: String,
/// Destination directory for the generated config file.
pub config_dir: PathBuf, pub config_dir: PathBuf,
/// Skips starting the service after installation.
pub no_start: bool, pub no_start: bool,
} }
@ -265,6 +271,16 @@ weight = 10
} }
fn generate_systemd_unit(exe_path: &Path, config_path: &Path) -> String { fn generate_systemd_unit(exe_path: &Path, config_path: &Path) -> String {
let exe = exe_path
.display()
.to_string()
.replace('\\', "\\\\")
.replace('"', "\\\"");
let config = config_path
.display()
.to_string()
.replace('\\', "\\\\")
.replace('"', "\\\"");
format!( format!(
r#"[Unit] r#"[Unit]
Description=Telemt MTProxy Description=Telemt MTProxy
@ -274,7 +290,7 @@ Wants=network-online.target
[Service] [Service]
Type=simple Type=simple
ExecStart={exe} {config} ExecStart="{exe}" "{config}"
Restart=always Restart=always
RestartSec=5 RestartSec=5
LimitNOFILE=65535 LimitNOFILE=65535
@ -287,9 +303,7 @@ PrivateTmp=true
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
"#, "#
exe = exe_path.display(),
config = config_path.display(),
) )
} }