aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil/service.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2025-01-13 11:09:58 +0100
committerDan Engelbrecht <[email protected]>2025-01-13 11:09:58 +0100
commit343d596ba0def12363907bca379e084e96793f96 (patch)
treed38e0273cbb0451402965ace40ae354dc903d3a6 /src/zenutil/service.cpp
parentlinux service (diff)
downloadzen-343d596ba0def12363907bca379e084e96793f96.tar.xz
zen-343d596ba0def12363907bca379e084e96793f96.zip
linux service stop
Diffstat (limited to 'src/zenutil/service.cpp')
-rw-r--r--src/zenutil/service.cpp172
1 files changed, 13 insertions, 159 deletions
diff --git a/src/zenutil/service.cpp b/src/zenutil/service.cpp
index 8926accb3..01ef66431 100644
--- a/src/zenutil/service.cpp
+++ b/src/zenutil/service.cpp
@@ -250,7 +250,7 @@ namespace {
#endif // ZEN_PLATFORM_MAC
-#if ZEN_PLATFORM_MAC || ZEN_PLATFORM_LINUX
+#if ZEN_PLATFORM_MAC
std::pair<int, std::string> ExecuteProgram(std::string_view Cmd)
{
@@ -350,9 +350,10 @@ namespace {
# endif // 0
}
-#endif // ZEN_PLATFORM_MAC || ZEN_PLATFORM_LINUX
+#endif // ZEN_PLATFORM_MAC
+
#if ZEN_PLATFORM_LINUX
- const char* SystemInstallFolder = "/etc/systemd/system/";
+// const char* SystemInstallFolder = "/etc/systemd/system/";
#endif // ZEN_PLATFORM_LINUX
} // namespace
@@ -887,156 +888,26 @@ StopService(std::string_view ServiceName)
std::error_code
InstallService(std::string_view ServiceName, const ServiceSpec& Spec)
{
- const std::string DaemonName = GetDaemonName(ServiceName);
- std::string PList = BuildPlist(ServiceName, Spec.ExecutablePath, Spec.CommandLineOptions, DaemonName, true);
+ ZEN_UNUSED(ServiceName, Spec);
+ ZEN_NOT_IMPLEMENTED("linux service implementation incomplete");
- const std::filesystem::path PListPath = GetPListPath(DaemonName);
- ZEN_INFO("Writing launchd plist to {}", PListPath.string());
- try
- {
- zen::WriteFile(PListPath, IoBuffer(IoBuffer::Wrap, PList.data(), PList.size()));
- }
- catch (const std::system_error& Ex)
- {
- return MakeErrorCode(Ex.code().value());
- }
-
- ZEN_INFO("Changing permissions to 644 for {}", PListPath.string());
- if (chmod(PListPath.string().c_str(), 0644) == -1)
- {
- return MakeErrorCodeFromLastError();
- }
return {};
}
std::error_code
UninstallService(std::string_view ServiceName)
{
- const std::string DaemonName = GetDaemonName(ServiceName);
- const std::filesystem::path PListPath = GetPListPath(DaemonName);
- ZEN_INFO("Attempting to remove launchd plist from {}", PListPath.string());
- std::error_code Ec;
- std::filesystem::remove(PListPath, Ec);
- return Ec;
+ ZEN_UNUSED(ServiceName);
+ ZEN_NOT_IMPLEMENTED("linux service implementation incomplete");
+
+ return {};
}
std::error_code
QueryInstalledService(std::string_view ServiceName, ServiceInfo& OutInfo)
{
ZEN_UNUSED(ServiceName, OutInfo);
-
- OutInfo.Status = ServiceStatus::NotInstalled;
- const std::string DaemonName = GetDaemonName(ServiceName);
-
- const std::filesystem::path PListPath = GetPListPath(DaemonName);
- if (std::filesystem::is_regular_file(PListPath))
- {
- OutInfo.Status = ServiceStatus::Stopped;
-
- {
- // Parse plist :(
- IoBuffer Buffer = ReadFile(PListPath).Flatten();
- MemoryView Data = Buffer.GetView();
- std::string PList((const char*)Data.GetData(), Data.GetSize());
-
- enum class ParseMode
- {
- None,
- ExpectingProgramArgumentsArray,
- ExpectingProgramExecutablePath,
- ExpectingCommandLineOption
- };
-
- ParseMode Mode = ParseMode::None;
-
- ForEachStrTok(PList, '\n', [&](std::string_view Line) {
- switch (Mode)
- {
- case ParseMode::None:
- {
- if (Line.find("<key>ProgramArguments</key>") != std::string_view::npos)
- {
- Mode = ParseMode::ExpectingProgramArgumentsArray;
- return true;
- }
- }
- break;
- case ParseMode::ExpectingProgramArgumentsArray:
- {
- if (Line.find("<array>") != std::string_view::npos)
- {
- Mode = ParseMode::ExpectingProgramExecutablePath;
- return true;
- }
- Mode = ParseMode::None;
- }
- break;
- case ParseMode::ExpectingProgramExecutablePath:
- {
- if (std::string_view::size_type ArgStart = Line.find("<string>"); ArgStart != std::string_view::npos)
- {
- ArgStart += 8;
- if (std::string_view::size_type ArgEnd = Line.find("</string>", ArgStart); ArgEnd != std::string_view::npos)
- {
- std::string_view ProgramString = Line.substr(ArgStart, ArgEnd - ArgStart);
- OutInfo.Spec.ExecutablePath = ProgramString;
- Mode = ParseMode::ExpectingCommandLineOption;
- return true;
- }
- }
- Mode = ParseMode::None;
- }
- break;
- case ParseMode::ExpectingCommandLineOption:
- {
- if (std::string_view::size_type ArgStart = Line.find("</array>"); ArgStart != std::string_view::npos)
- {
- Mode = ParseMode::None;
- return true;
- }
- else if (std::string_view::size_type ArgStart = Line.find("<string>"); ArgStart != std::string_view::npos)
- {
- ArgStart += 8;
- if (std::string_view::size_type ArgEnd = Line.find("</string>", ArgStart); ArgEnd != std::string_view::npos)
- {
- std::string_view ArgumentString = Line.substr(ArgStart, ArgEnd - ArgStart);
- if (!OutInfo.Spec.CommandLineOptions.empty())
- {
- OutInfo.Spec.CommandLineOptions += " ";
- }
- OutInfo.Spec.CommandLineOptions += ArgumentString;
- return true;
- }
- }
- Mode = ParseMode::None;
- }
- break;
- }
- return true;
- });
- }
- {
- std::pair<int, std::string> Res = ExecuteProgram(std::string("launchctl list ") + DaemonName);
- if (Res.first == 0 && !Res.second.empty())
- {
- ForEachStrTok(Res.second, '\n', [&](std::string_view Line) {
- if (Line.find("\"PID\"") != std::string_view::npos)
- {
- std::string_view::size_type PidStart = Line.find('=');
- std::string_view::size_type PidEnd = Line.find(';');
- std::string_view PidString = Line.substr(PidStart + 2, PidEnd - (PidStart + 2));
- if (ParseInt<int>(PidString).has_value())
- {
- OutInfo.Status = ServiceStatus::Running;
- }
- return false;
- }
- return true;
- });
- // Parse installed info
- }
- }
- }
+ ZEN_NOT_IMPLEMENTED("linux service implementation incomplete");
return {};
}
@@ -1045,15 +916,7 @@ std::error_code
StartService(std::string_view ServiceName)
{
ZEN_UNUSED(ServiceName);
-
- const std::string DaemonName = GetDaemonName(ServiceName);
- const std::filesystem::path PListPath = GetPListPath(DaemonName);
-
- std::pair<int, std::string> Res = ExecuteProgram(std::string("launchctl bootstrap system ") + PListPath.string());
- if (Res.first != 0)
- {
- return MakeErrorCode(Res.first);
- }
+ ZEN_NOT_IMPLEMENTED("linux service implementation incomplete");
return {};
}
@@ -1062,16 +925,7 @@ std::error_code
StopService(std::string_view ServiceName)
{
ZEN_UNUSED(ServiceName);
-
- const std::string DaemonName = GetDaemonName(ServiceName);
- const std::filesystem::path PListPath = GetPListPath(DaemonName);
-
- std::pair<int, std::string> Res = ExecuteProgram(std::string("launchctl bootout system ") + PListPath.string());
- if (Res.first != 0)
- {
- return MakeErrorCode(Res.first);
- }
-
+ ZEN_NOT_IMPLEMENTED("linux service implementation incomplete");
return {};
}