@@ -397,8 +397,8 @@ defaulting to ``ustate``. In addition, it captures the ``update_state_t`` enum v
The function ``suricatta.pstate.save(state)`` requires one of ``suricatta.pstate``'s
"enum" values as parameter and returns ``true``, or, in case of error, ``nil``.
-The function ``suricatta.pstate.get()`` returns ``true``, or, in case of error, ``nil``,
-plus one of ``suricatta.pstate``'s "enum" values in the former case.
+The function ``suricatta.pstate.get()`` returns one of ``suricatta.pstate``'s
+"enum" values or, in case of error, ``STATE_ERROR``.
`suricatta.server`
@@ -171,8 +171,7 @@ gs = {
function has_pending_action(action_id)
action_id = action_id
gs.polldelay.current = gs.polldelay.default
- local _, pstate = suricatta.pstate.get()
- if pstate == suricatta.pstate.INSTALLED then
+ if suricatta.pstate.get() == suricatta.pstate.INSTALLED then
suricatta.notify.warn("An installed update is pending testing, not querying server.")
return action_id, suricatta.status.NO_UPDATE_AVAILABLE
end
@@ -1458,20 +1458,13 @@ static int lua_bootloader_env_apply(lua_State *L)
/**
* @brief Get update state from persistent storage (bootloader).
*
- * @return [Lua] True, or, in case of error, nil.
- * [Lua] One of pstate's enum values.
+ * @return [Lua] One of pstate's enum values.
*/
static int lua_pstate_get(lua_State *L)
{
update_state_t state = get_state();
- if (is_valid_state(state)) {
- lua_pushboolean(L, true);
- lua_pushinteger(L, (int)state);
- } else {
- lua_pushnil(L);
- lua_pushnil(L);
- }
- return 2;
+ lua_pushinteger(L, is_valid_state(state) ? (int)state : STATE_ERROR);
+ return 1;
}
@@ -130,8 +130,7 @@ suricatta.pstate = {
--- Get the current stored persistent state.
--
---- @return boolean # Whether operation was successful or not
---- @return suricatta.pstate # Persistent state ID number
+--- @return number # Persistent state ID number, suricatta.pstate.ERROR if unsuccessful
suricatta.pstate.get = function() end
--- Save persistent state information.
As nil is not of type number and STATE_ERROR is semantically equivalent, return STATE_ERROR upon error in suricatta.pstate.get(). This change also makes it unnecessary to return a success indicator boolean as first return value. Signed-off-by: Christian Storm <christian.storm@siemens.com> --- doc/source/suricatta.rst | 4 ++-- examples/suricatta/swupdate_suricatta.lua | 3 +-- suricatta/server_lua.c | 13 +++---------- suricatta/suricatta.lua | 3 +-- 4 files changed, 7 insertions(+), 16 deletions(-)