From f8f2338aba84394e132fff55b6ebdef7d884292b Mon Sep 17 00:00:00 2001 From: José Bollo Date: Tue, 19 May 2020 11:22:26 +0200 Subject: Improve use of systemd's states MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A better handling of systemd state is need to treat correctly transient states. That change includes: - Management of states with numeric identifiers instead of names - Handling of the state "inactive" as a stable state. Most of previous seen problems were coming from that miss. - Returning no error but also no info on the process if it falled to "inactive" meaning that it stopped quickly. Bug-AGL: SPEC-3323 Change-Id: Ibf35eb6257c5583596d675cad0bec2869f5fd5f7 Signed-off-by: José Bollo --- src/utils-systemd.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/utils-systemd.h') diff --git a/src/utils-systemd.h b/src/utils-systemd.h index cf95097..3bddfd6 100644 --- a/src/utils-systemd.h +++ b/src/utils-systemd.h @@ -18,12 +18,15 @@ #pragma once -extern const char SysD_State_Inactive[]; -extern const char SysD_State_Activating[]; -extern const char SysD_State_Active[]; -extern const char SysD_State_Deactivating[]; -extern const char SysD_State_Reloading[]; -extern const char SysD_State_Failed[]; +enum SysD_State { + SysD_State_INVALID, + SysD_State_Inactive, + SysD_State_Activating, + SysD_State_Active, + SysD_State_Deactivating, + SysD_State_Reloading, + SysD_State_Failed +}; struct sd_bus; extern int systemd_get_bus(int isuser, struct sd_bus **ret); @@ -48,8 +51,10 @@ extern int systemd_unit_stop_name(int isuser, const char *name); extern int systemd_unit_stop_pid(int isuser, unsigned pid); extern int systemd_unit_pid_of_dpath(int isuser, const char *dpath); -extern const char *systemd_unit_state_of_dpath(int isuser, const char *dpath); +extern enum SysD_State systemd_unit_state_of_dpath(int isuser, const char *dpath); extern int systemd_unit_list(int isuser, int (*callback)(void *closure, const char *name, const char *path, int isuser), void *closure); extern int systemd_unit_list_all(int (*callback)(void *closure, const char *name, const char *path, int isuser), void *closure); +extern const char *systemd_state_name(enum SysD_State state); + -- cgit 1.2.3-korg