diff options
author | José Bollo <jose.bollo@iot.bzh> | 2018-11-05 18:14:15 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2018-11-05 18:14:15 +0100 |
commit | 44c70fd80a3ff8931aa97555ceaf5ed578e4f8be (patch) | |
tree | df315bba53965b9ad13f6f2972b370909b651943 /src/afm-urun.c | |
parent | bceaf2cc403176fd808d4e00be893671be3f4bb0 (diff) |
Treat correctly running/not running status
Systemd returns 0 for services that don't run.
It wasn't checked well causing weird effect:
trying to terminate an application not running
killed afm-system-daemon because kill(0) kills
all processes of the group of the caller.
Bug-AGL: SPEC-1836
Change-Id: I1bd64faf871ecd42aaaa5449312e8b8cb26ee9dd
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afm-urun.c')
-rw-r--r-- | src/afm-urun.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/afm-urun.c b/src/afm-urun.c index 8c21b2a..882d44c 100644 --- a/src/afm-urun.c +++ b/src/afm-urun.c @@ -268,7 +268,7 @@ int afm_urun_once(struct json_object *appli, int uid) } rc = systemd_unit_pid_of_dpath(isuser, udpath); - if (rc < 0) { + if (rc <= 0) { j_read_string_at(appli, "unit-scope", &uscope); j_read_string_at(appli, "unit-name", &uname); ERROR("can't getpid of %s unit %s for uid %d: %m", uscope, uname, uid); @@ -403,7 +403,7 @@ struct json_object *afm_urun_state(struct afm_udb *db, int runid, int uid) && j_read_string_at(appli, "id", &id)) { pid = systemd_unit_pid_of_dpath(isuser, udpath); state = systemd_unit_state_of_dpath(isuser, dpath); - if (state == SysD_State_Active) + if (pid > 0 && state == SysD_State_Active) result = mkstate(id, runid, pid, state); goto end; } @@ -437,6 +437,10 @@ int afm_urun_search_runid(struct afm_udb *db, const char *id, int uid) pid = -1; } else { pid = systemd_unit_pid_of_dpath(isuser, udpath); + if (pid == 0) { + errno = ESRCH; + pid = -1; + } } return pid; } |