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>
static const char _install_[] = "install";
static const char _lang_[] = "lang";
static const char _not_found_[] = "not-found";
static const char _install_[] = "install";
static const char _lang_[] = "lang";
static const char _not_found_[] = "not-found";
+static const char _not_running_[] = "not-running";
static const char _once_[] = "once";
static const char _pause_[] = "pause";
static const char _resume_[] = "resume";
static const char _once_[] = "once";
static const char _pause_[] = "pause";
static const char _resume_[] = "resume";
afb_req_fail(req, _not_found_, NULL);
}
afb_req_fail(req, _not_found_, NULL);
}
+/* common not running reply */
+static void not_running(afb_req_t req)
+{
+ afb_req_fail(req, _not_running_, NULL);
+}
+
/* common can't start reply */
static void cant_start(afb_req_t req)
{
/* common can't start reply */
static void cant_start(afb_req_t req)
{
/* nothing appropriate */
INFO("method %s can't get runid for %s: %m", method,
appid);
/* nothing appropriate */
INFO("method %s can't get runid for %s: %m", method,
appid);
+ if (errno == ESRCH)
+ not_running(req);
+ else
+ not_found(req);
}
rc = systemd_unit_pid_of_dpath(isuser, udpath);
}
rc = systemd_unit_pid_of_dpath(isuser, udpath);
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);
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);
&& j_read_string_at(appli, "id", &id)) {
pid = systemd_unit_pid_of_dpath(isuser, udpath);
state = systemd_unit_state_of_dpath(isuser, dpath);
&& 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;
}
result = mkstate(id, runid, pid, state);
goto end;
}
pid = -1;
} else {
pid = systemd_unit_pid_of_dpath(isuser, udpath);
pid = -1;
} else {
pid = systemd_unit_pid_of_dpath(isuser, udpath);
+ if (pid == 0) {
+ errno = ESRCH;
+ pid = -1;
+ }