blob: b16bc99b7d6b2e5d06733e1c33475d3491dde05a [file] [log] [blame]
Patrick Venture6d7735d2019-06-21 10:03:19 -07001/*
2 * Copyright 2019 Google Inc.
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
17#include "prepare_systemd.hpp"
18
19#include "status.hpp"
20
21#include <memory>
22
23namespace ipmi_flash
24{
25
26std::unique_ptr<TriggerableActionInterface>
27 SystemdPreparation::CreatePreparation(sdbusplus::bus::bus&& bus,
28 const std::string& service)
29{
30 return std::make_unique<SystemdPreparation>(std::move(bus), service);
31}
32
33bool SystemdPreparation::trigger()
34{
35 static constexpr auto systemdService = "org.freedesktop.systemd1";
36 static constexpr auto systemdRoot = "/org/freedesktop/systemd1";
37 static constexpr auto systemdInterface = "org.freedesktop.systemd1.Manager";
38
39 auto method = bus.new_method_call(systemdService, systemdRoot,
40 systemdInterface, "StartUnit");
41 method.append(triggerService);
42 method.append("replace");
43
44 try
45 {
46 bus.call_noreply(method);
47 }
48 catch (const sdbusplus::exception::SdBusError& ex)
49 {
50 /* TODO: Once logging supports unit-tests, add a log message to test
51 * this failure.
52 */
53 state = ActionStatus::failed;
54 return false;
55 }
56
57 state = ActionStatus::success;
58 return true;
59}
60
61void SystemdPreparation::abort()
62{
63 return;
64}
65
66ActionStatus SystemdPreparation::status()
67{
68 return state;
69}
70
71} // namespace ipmi_flash