aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/afm-binding.c12
-rw-r--r--src/afm-urun.c8
2 files changed, 17 insertions, 3 deletions
diff --git a/src/afm-binding.c b/src/afm-binding.c
index 5fb1f73..037c108 100644
--- a/src/afm-binding.c
+++ b/src/afm-binding.c
@@ -49,6 +49,7 @@ static const char _id_[] = "id";
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";
@@ -187,6 +188,12 @@ static void not_found(afb_req_t req)
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)
{
@@ -283,7 +290,10 @@ static int onrunid(afb_req_t req, const char *method, int *runid)
/* nothing appropriate */
INFO("method %s can't get runid for %s: %m", method,
appid);
- not_found(req);
+ if (errno == ESRCH)
+ not_running(req);
+ else
+ not_found(req);
return 0;
}
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;
}