blob: c08fdd1ec57ddf4d2b2befc8cd93fa5402f2af74 [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,
Patrick Venture39157582019-08-21 10:02:18 -070028 const std::string& service,
29 const std::string& mode)
Patrick Venture6d7735d2019-06-21 10:03:19 -070030{
Patrick Venture39157582019-08-21 10:02:18 -070031 return std::make_unique<SystemdPreparation>(std::move(bus), service, mode);
Patrick Venture6d7735d2019-06-21 10:03:19 -070032}
33
34bool SystemdPreparation::trigger()
35{
36 static constexpr auto systemdService = "org.freedesktop.systemd1";
37 static constexpr auto systemdRoot = "/org/freedesktop/systemd1";
38 static constexpr auto systemdInterface = "org.freedesktop.systemd1.Manager";
39
40 auto method = bus.new_method_call(systemdService, systemdRoot,
41 systemdInterface, "StartUnit");
42 method.append(triggerService);
Patrick Venture39157582019-08-21 10:02:18 -070043 method.append(mode);
Patrick Venture6d7735d2019-06-21 10:03:19 -070044
45 try
46 {
47 bus.call_noreply(method);
48 }
49 catch (const sdbusplus::exception::SdBusError& ex)
50 {
51 /* TODO: Once logging supports unit-tests, add a log message to test
52 * this failure.
53 */
54 state = ActionStatus::failed;
55 return false;
56 }
57
58 state = ActionStatus::success;
59 return true;
60}
61
62void SystemdPreparation::abort()
63{
64 return;
65}
66
67ActionStatus SystemdPreparation::status()
68{
69 return state;
70}
71
72} // namespace ipmi_flash