aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLiam Mitchell <[email protected]>2025-07-25 20:58:17 +0000
committerLiam Mitchell <[email protected]>2025-07-25 20:58:17 +0000
commitbaa420dbc358cb48d26e0aa94a36196f737b3f04 (patch)
treebc2f7c70c18e9ecc7b0186fdb797bf85ab755bef /src
parentIncrease service stop timeout to 30 seconds during full install (diff)
downloadzen-baa420dbc358cb48d26e0aa94a36196f737b3f04.tar.xz
zen-baa420dbc358cb48d26e0aa94a36196f737b3f04.zip
Fix permissions and ownership issues with service binary copy and remove unnecessary alias from unit file
Diffstat (limited to 'src')
-rw-r--r--src/zen/cmds/service_cmd.cpp11
-rw-r--r--src/zencore/filesystem.cpp2
-rw-r--r--src/zenutil/service.cpp7
3 files changed, 14 insertions, 6 deletions
diff --git a/src/zen/cmds/service_cmd.cpp b/src/zen/cmds/service_cmd.cpp
index 2125e49f1..a734504b8 100644
--- a/src/zen/cmds/service_cmd.cpp
+++ b/src/zen/cmds/service_cmd.cpp
@@ -7,6 +7,7 @@
#include <zencore/logging.h>
#include <zencore/zencore.h>
#include <zenutil/service.h>
+#include <filesystem>
#if ZEN_PLATFORM_WINDOWS
# include <zencore/windows.h>
@@ -456,13 +457,21 @@ ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
for (const std::filesystem::path& File : FilesToCopy)
{
std::filesystem::path Destination = m_InstallPath / File.filename();
- if (!CopyFile(File, Destination, {}))
+ if (!CopyFile(File, Destination, {.EnableClone = false}))
{
ZEN_CONSOLE("Failed to copy '{}' to '{}'", File, Destination);
return 1;
}
+
+ ZEN_INFO("Copied '{}' to '{}'", File, Destination);
+
+ if (File.extension() != "pdb")
+ {
+ std::filesystem::permissions(Destination, std::filesystem::perms::owner_exec, std::filesystem::perm_options::add);
+ }
}
+
m_ServerExecutable = m_InstallPath / m_ServerExecutable.filename();
}
diff --git a/src/zencore/filesystem.cpp b/src/zencore/filesystem.cpp
index 05e2bf049..783f01b6c 100644
--- a/src/zencore/filesystem.cpp
+++ b/src/zencore/filesystem.cpp
@@ -603,6 +603,8 @@ CopyFile(const std::filesystem::path& FromPath, const std::filesystem::path& ToP
size_t FileSizeBytes = Stat.st_size;
+ fchown(ToFd, Stat.st_uid, Stat.st_gid);
+
// Copy impl
const size_t BufferSize = Min(FileSizeBytes, 64u << 10);
void* Buffer = malloc(BufferSize);
diff --git a/src/zenutil/service.cpp b/src/zenutil/service.cpp
index 6e68a01fa..25941bde1 100644
--- a/src/zenutil/service.cpp
+++ b/src/zenutil/service.cpp
@@ -321,7 +321,6 @@ namespace {
std::string BuildUnitFile(std::string_view ServiceName,
const std::filesystem::path& ExecutablePath,
std::string_view CommandLineOptions,
- std::string_view AliasName,
std::string_view UserName)
{
return fmt::format(
@@ -341,14 +340,12 @@ namespace {
"ExecStart={} {}\n"
"RuntimeDirectory={}\n"
"[Install]\n"
- "Alias={}\n"
"WantedBy=multi-user.target",
ServiceName,
UserName,
ExecutablePath,
CommandLineOptions,
- ExecutablePath.parent_path(),
- AliasName);
+ ExecutablePath.parent_path());
}
#endif // ZEN_PLATFORM_LINUX
@@ -917,7 +914,7 @@ InstallService(std::string_view ServiceName, const ServiceSpec& Spec)
UserName = UserResult.second;
}
- std::string UnitFile = BuildUnitFile(ServiceName, Spec.ExecutablePath, Spec.CommandLineOptions, UnitName, UserName);
+ std::string UnitFile = BuildUnitFile(ServiceName, Spec.ExecutablePath, Spec.CommandLineOptions, UserName);
ZEN_DEBUG("Writing systemd unit file to {}", ServiceUnitPath.string());
try
{