blob: 0802f4395a3495e1278f088cb906a73a5f3b8484 [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"
20#include "update.hpp"
21
22#include <memory>
23#include <sdbusplus/bus.hpp>
24#include <string>
25
26namespace ipmi_flash
27{
28
29std::unique_ptr<UpdateInterface>
30 SystemdUpdateMechanism::CreateSystemdUpdate(sdbusplus::bus::bus&& bus,
31 const std::string& target,
32 const std::string& mode)
33{
34 return std::make_unique<SystemdUpdateMechanism>(std::move(bus), target,
35 mode);
36}
37
38bool SystemdUpdateMechanism::triggerUpdate()
39{
40 /* TODO: Add a util method for triggering a service with optional additional
41 * parameter. */
42 static constexpr auto systemdService = "org.freedesktop.systemd1";
43 static constexpr auto systemdRoot = "/org/freedesktop/systemd1";
44 static constexpr auto systemdInterface = "org.freedesktop.systemd1.Manager";
45
46 auto method = bus.new_method_call(systemdService, systemdRoot,
47 systemdInterface, "StartUnit");
48 method.append(target);
49
50 if (!mode.empty())
51 {
52 method.append(mode);
53 }
54
55 try
56 {
57 bus.call_noreply(method);
58 return true;
59 }
60 catch (const sdbusplus::exception::SdBusError& ex)
61 {
62 return false;
63 }
64}
65
66void SystemdUpdateMechanism::abortUpdate()
67{
68 return;
69}
70
71UpdateStatus SystemdUpdateMechanism::status()
72{
73 /* For now, don't check if the target failed. */
74 return UpdateStatus::running;
75}
76
77} // namespace ipmi_flash