blob: d6dded6cb7a80e88cd0758fe62ec559f4f03c4b6 [file] [log] [blame]
Vernon Maueryba2c0832020-07-15 10:02:38 -07001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17#include <boost/asio.hpp>
18#include <phosphor-logging/elog-errors.hpp>
George Liucb267c82022-01-05 17:53:28 +080019#include <phosphor-logging/lg2.hpp>
Vernon Maueryba2c0832020-07-15 10:02:38 -070020#include <sdbusplus/asio/object_server.hpp>
21#include <xyz/openbmc_project/Common/error.hpp>
22
23#include <chrono>
24#include <ctime>
25#include <filesystem>
26#include <string>
27
28static constexpr const char* sysdStartUnit = "StartUnit";
29static constexpr const char* sysdStopUnit = "StopUnit";
30static constexpr const char* sysdRestartUnit = "RestartUnit";
31static constexpr const char* sysdReloadMethod = "Reload";
32static constexpr const char* sysdGetJobMethod = "GetJob";
33static constexpr const char* sysdReplaceMode = "replace";
34static constexpr const char* dBusGetAllMethod = "GetAll";
35static constexpr const char* dBusGetMethod = "Get";
36static constexpr const char* sysdService = "org.freedesktop.systemd1";
37static constexpr const char* sysdObjPath = "/org/freedesktop/systemd1";
38static constexpr const char* sysdMgrIntf = "org.freedesktop.systemd1.Manager";
39static constexpr const char* sysdUnitIntf = "org.freedesktop.systemd1.Unit";
40static constexpr const char* sysdSocketIntf = "org.freedesktop.systemd1.Socket";
41static constexpr const char* dBusPropIntf = "org.freedesktop.DBus.Properties";
42static constexpr const char* stateMasked = "masked";
43static constexpr const char* stateEnabled = "enabled";
44static constexpr const char* stateDisabled = "disabled";
45static constexpr const char* subStateRunning = "running";
George Liua19b5092021-05-24 15:54:02 +080046static constexpr const char* subStateListening = "listening";
Jiaqing Zhaod2a99a42022-02-25 17:26:30 +080047static constexpr const char* loadStateNotFound = "not-found";
Andrew Geissler67e41862025-04-22 09:50:30 -050048static constexpr const char* srvDataBaseDir =
49 "/var/lib/service-config-manager/";
George Liua19b5092021-05-24 15:54:02 +080050
51using ListUnitsType =
52 std::tuple<std::string, std::string, std::string, std::string, std::string,
53 std::string, sdbusplus::message::object_path, uint32_t,
54 std::string, sdbusplus::message::object_path>;
55
56enum class ListUnitElements
57{
58 name,
59 descriptionString,
60 loadState,
61 activeState,
62 subState,
63 followedUnit,
64 objectPath,
65 queuedJobType,
66 jobType,
67 jobObject
68};
Vernon Maueryba2c0832020-07-15 10:02:38 -070069
70static inline std::string addInstanceName(const std::string& instanceName,
71 const std::string& suffix)
72{
73 return (instanceName.empty() ? "" : suffix + instanceName);
74}
75
George Liua19b5092021-05-24 15:54:02 +080076void checkAndThrowInternalFailure(boost::system::error_code& ec,
77 const std::string& msg);
78
Vernon Maueryba2c0832020-07-15 10:02:38 -070079void systemdDaemonReload(
80 const std::shared_ptr<sdbusplus::asio::connection>& conn,
81 boost::asio::yield_context yield);
82
83void systemdUnitAction(const std::shared_ptr<sdbusplus::asio::connection>& conn,
84 boost::asio::yield_context yield,
85 const std::string& unitName,
86 const std::string& actionMethod);
87
88void systemdUnitFilesStateChange(
89 const std::shared_ptr<sdbusplus::asio::connection>& conn,
90 boost::asio::yield_context yield, const std::vector<std::string>& unitFiles,
91 const std::string& unitState, bool maskedState, bool enabledState);