Patrick Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 1 | /* |
| 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 Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 20 | |
| 21 | #include <memory> |
| 22 | #include <sdbusplus/bus.hpp> |
| 23 | #include <string> |
| 24 | |
| 25 | namespace ipmi_flash |
| 26 | { |
| 27 | |
Patrick Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 28 | std::unique_ptr<TriggerableActionInterface> |
Patrick Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 29 | 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 Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 37 | bool SystemdUpdateMechanism::trigger() |
Patrick Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 38 | { |
| 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 Venture | 1d66fe6 | 2019-06-03 14:57:27 -0700 | [diff] [blame] | 65 | void SystemdUpdateMechanism::abort() |
Patrick Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 66 | { |
| 67 | return; |
| 68 | } |
| 69 | |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 70 | ActionStatus SystemdUpdateMechanism::status() |
Patrick Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 71 | { |
| 72 | /* For now, don't check if the target failed. */ |
Patrick Venture | da66fd8 | 2019-06-03 11:11:24 -0700 | [diff] [blame] | 73 | return ActionStatus::running; |
Patrick Venture | 6f81b16 | 2019-05-20 14:02:59 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | } // namespace ipmi_flash |