From a4f173e6e8ed11ad2d5f54b8fcd30df5443cd053 Mon Sep 17 00:00:00 2001 From: Agata Olender Date: Tue, 4 Feb 2020 14:09:40 +0100 Subject: Add handling of exit code property. Property returns exit code value from nbd-client process for proxy mode and from nbdkit process for legacy mode. The initial value for this property is -1 and will be returned before starting the process and in the process execution time. Tested manually for proxy and legacy mode: - initial value before process first run - initial value in process execution time - 0 value for successful exit - specific value for forced process termination Change-Id: I4cefa423bade522fc2fac0cab620cbba0b66cce2 Signed-off-by: Agata Olender --- virtual-media/src/state_machine.hpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/virtual-media/src/state_machine.hpp b/virtual-media/src/state_machine.hpp index a788043..6711401 100644 --- a/virtual-media/src/state_machine.hpp +++ b/virtual-media/src/state_machine.hpp @@ -120,6 +120,9 @@ struct MountPointStateMachine virtual void onEnter() { + // Reset previous exit code + machine.exitCode = -1; + machine.emitActivationStartedEvent(); } }; @@ -337,11 +340,10 @@ struct MountPointStateMachine } }); processIface->register_property( - "ExitCode", uint8_t(0), - [](const uint8_t& req, uint8_t& property) { return 0; }, - [& machine = state.machine](const uint8_t& property) { - // TODO: indicate real value instead of success - return uint8_t(255); + "ExitCode", int32_t(0), + [](const int32_t& req, int32_t& property) { return 0; }, + [& machine = state.machine](const int32_t& property) { + return machine.exitCode; }); processIface->initialize(); } @@ -649,6 +651,7 @@ struct MountPointStateMachine Configuration::MountPoint::toArgs(state.machine.config), [& machine = state.machine](int exitCode, bool isReady) { LogMsg(Logger::Info, machine.name, " process ended."); + machine.exitCode = exitCode; machine.emitSubprocessStoppedEvent(); })) { @@ -799,6 +802,7 @@ struct MountPointStateMachine args, [& machine = machine, secret = std::move(secret)]( int exitCode, bool isReady) { LogMsg(Logger::Info, machine.name, " process ended."); + machine.exitCode = exitCode; machine.emitSubprocessStoppedEvent(); })) { @@ -1002,7 +1006,7 @@ struct MountPointStateMachine DeviceMonitor& devMonitor, const std::string& name, const Configuration::MountPoint& config) : ioc{ioc}, - name{name}, config{config}, state{InitialState(*this)} + name{name}, config{config}, state{InitialState(*this)}, exitCode{-1} { devMonitor.addDevice(config.nbdDevice); } @@ -1085,4 +1089,5 @@ struct MountPointStateMachine std::optional target; State state; + int exitCode; }; -- cgit v1.2.3