aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiam Mitchell <[email protected]>2026-01-07 18:00:16 -0800
committerLiam Mitchell <[email protected]>2026-01-07 18:00:16 -0800
commit609f8fce1ce61c461c5a84ff7cbf97e084f05be3 (patch)
tree15668f002ad023c1ff566a7f13bf6504fd2dcb9a
parentadded early-out check in GcManager::ScrubStorage(ScrubContext& GcCtx) (#698) (diff)
downloadzen-609f8fce1ce61c461c5a84ff7cbf97e084f05be3.tar.xz
zen-609f8fce1ce61c461c5a84ff7cbf97e084f05be3.zip
Implement final changes required for daemon mode on Mac
-rw-r--r--src/zen/cmds/service_cmd.cpp6
-rw-r--r--src/zenutil/service.cpp55
2 files changed, 28 insertions, 33 deletions
diff --git a/src/zen/cmds/service_cmd.cpp b/src/zen/cmds/service_cmd.cpp
index 8be76de7c..c7df6c640 100644
--- a/src/zen/cmds/service_cmd.cpp
+++ b/src/zen/cmds/service_cmd.cpp
@@ -102,7 +102,11 @@ namespace {
}
}
-#else // ZEN_PLATFORM_WINDOWS
+#elif ZEN_PLATFORM_MAC
+
+ bool IsElevated() { return true; } // Mac service mode commands can run without elevation, so we lie a little bit here
+
+#else
bool IsElevated() { return geteuid() == 0; }
diff --git a/src/zenutil/service.cpp b/src/zenutil/service.cpp
index 103fdaa2f..9aa866e2c 100644
--- a/src/zenutil/service.cpp
+++ b/src/zenutil/service.cpp
@@ -229,12 +229,13 @@ namespace {
std::filesystem::path GetPListPath(const std::string& DaemonName)
{
- const std::filesystem::path PListFolder = "/Library/LaunchDaemons";
+ char* HomeDir = getenv("HOME");
+ std::filesystem::path PListFolder = HomeDir;
+ PListFolder /= "Library/LaunchAgents";
return PListFolder / (DaemonName + ".plist");
}
- std::string BuildPlist(std::string_view ServiceName,
- const std::filesystem::path& ExecutablePath,
+ std::string BuildPlist(const std::filesystem::path& ExecutablePath,
std::string_view CommandLineOptions,
std::string_view DaemonName,
bool Debug)
@@ -265,14 +266,8 @@ namespace {
" <key>RunAtLoad</key>\n"
" <true/>\n"
" \n"
- // " <key>KeepAlive</key>\n"
- // " <true/>\n"
- // " \n"
- " <key>StandardOutPath</key>\n"
- " <string>/var/log/{}.log</string>\n"
- " \n"
- " <key>StandardErrorPath</key>\n"
- " <string>/var/log/{}.err.log</string>\n"
+ " <key>KeepAlive</key>\n"
+ " <true/>\n"
" \n"
" <key>Debug</key>\n"
" <{}/>\n"
@@ -282,22 +277,7 @@ namespace {
DaemonName,
ExecutablePath,
ProgramArguments.ToView(),
- ServiceName,
- ServiceName,
Debug ? "true"sv : "false"sv);
-
- // "<key>Sockets</key>"
- // "<dict>"
- // "<key>Listeners</key>"
- // "<dict>"
- // "<key>SockServiceName</key>"
- // "<string>{}</string>" // Listen socket
- // "<key>SockType</key>"
- // "<string>tcp</string>"
- // "<key>SockFamily</key>"
- // "<string>IPv4</string>"
- // "</dict>"
- // "</dict>"
}
#endif // ZEN_PLATFORM_MAC
@@ -752,9 +732,8 @@ StopService(std::string_view ServiceName)
std::error_code
InstallService(std::string_view ServiceName, const ServiceSpec& Spec)
{
- // TODO: Do we need to create a separate user for the service or is running as the default service user OK?
const std::string DaemonName = GetDaemonName(ServiceName);
- std::string PList = BuildPlist(ServiceName, Spec.ExecutablePath, Spec.CommandLineOptions, DaemonName, true);
+ std::string PList = BuildPlist(Spec.ExecutablePath, Spec.CommandLineOptions, DaemonName, true);
const std::filesystem::path PListPath = GetPListPath(DaemonName);
ZEN_INFO("Writing launchd plist to {}", PListPath.string());
@@ -910,8 +889,14 @@ StartService(std::string_view ServiceName)
{
const std::string DaemonName = GetDaemonName(ServiceName);
const std::filesystem::path PListPath = GetPListPath(DaemonName);
+ std::pair<int, std::string> User = ExecuteProgram("id -u");
- std::pair<int, std::string> Res = ExecuteProgram(fmt::format("launchctl bootstrap system {}", PListPath));
+ if (User.first != 0)
+ {
+ return MakeErrorCode(User.first);
+ }
+
+ std::pair<int, std::string> Res = ExecuteProgram(fmt::format("launchctl bootstrap gui/{} {}", User.second, PListPath));
if (Res.first != 0)
{
return MakeErrorCode(Res.first);
@@ -926,13 +911,19 @@ StopService(std::string_view ServiceName)
const std::string DaemonName = GetDaemonName(ServiceName);
const std::filesystem::path PListPath = GetPListPath(DaemonName);
- /*
- std::pair<int, std::string> Res = ExecuteProgram(fmt::format("launchctl bootout system ", PListPath.));
+ std::pair<int, std::string> User = ExecuteProgram("id -u");
+
+ if (User.first != 0)
+ {
+ return MakeErrorCode(User.first);
+ }
+
+ std::pair<int, std::string> Res = ExecuteProgram(fmt::format("launchctl bootout gui/{} {}", User.second, PListPath));
if (Res.first != 0)
{
return MakeErrorCode(Res.first);
}
- */
+
return {};
}