blob: d8f232994c7837e6c8efc82a71b57eb32bca177d [file] [log] [blame]
Patrick Venture6f81b162019-05-20 14:02:59 -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 "update_systemd.hpp"
18
19#include "status.hpp"
Patrick Venture6f81b162019-05-20 14:02:59 -070020
21#include <memory>
22#include <sdbusplus/bus.hpp>
23#include <string>
24
25namespace ipmi_flash
26{
27
Patrick Venture1d66fe62019-06-03 14:57:27 -070028std::unique_ptr<TriggerableActionInterface>
Patrick Venture6f81b162019-05-20 14:02:59 -070029 SystemdUpdateMechanism::CreateSystemdUpdate(sdbusplus::bus::bus&& bus,
30 const std::string& target,
31 const std::string& mode)
32{
33 return std::make_unique<SystemdUpdateMechanism>(std::move(bus), target,
34 mode);
35}
36
Patrick Venture1d66fe62019-06-03 14:57:27 -070037bool SystemdUpdateMechanism::trigger()
Patrick Venture6f81b162019-05-20 14:02:59 -070038{
39 /* TODO: Add a util method for triggering a service with optional additional
40 * parameter. */
41 static constexpr auto systemdService = "org.freedesktop.systemd1";
42 static constexpr auto systemdRoot = "/org/freedesktop/systemd1";
43 static constexpr auto systemdInterface = "org.freedesktop.systemd1.Manager";
44
45 auto method = bus.new_method_call(systemdService, systemdRoot,
46 systemdInterface, "StartUnit");
47 method.append(target);
48
49 if (!mode.empty())
50 {
51 method.append(mode);
52 }
53
54 try
55 {
56 bus.call_noreply(method);
57 return true;
58 }
59 catch (const sdbusplus::exception::SdBusError& ex)
60 {
61 return false;
62 }
63}
64
Patrick Venture1d66fe62019-06-03 14:57:27 -070065void SystemdUpdateMechanism::abort()
Patrick Venture6f81b162019-05-20 14:02:59 -070066{
67 return;
68}
69
Patrick Ventureda66fd82019-06-03 11:11:24 -070070ActionStatus SystemdUpdateMechanism::status()
Patrick Venture6f81b162019-05-20 14:02:59 -070071{
72 /* For now, don't check if the target failed. */
Patrick Ventureda66fd82019-06-03 11:11:24 -070073 return ActionStatus::running;
Patrick Venture6f81b162019-05-20 14:02:59 -070074}
75
76} // namespace ipmi_flash