Code Review
/
src
/
app-framework-main.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Treat correctly running/not running status
[src/app-framework-main.git]
/
src
/
afm-binding.c
diff --git
a/src/afm-binding.c
b/src/afm-binding.c
index
dd59be9
..
037c108
100644
(file)
--- a/
src/afm-binding.c
+++ b/
src/afm-binding.c
@@
-21,6
+21,7
@@
#include <string.h>
#include <assert.h>
#include <signal.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
+#include <errno.h>
#include <json-c/json.h>
#include <json-c/json.h>
@@
-48,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 _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";
@@
-186,6
+188,12
@@
static void not_found(afb_req_t req)
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)
{
@@
-282,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);
/* 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;
}
return 0;
}
@@
-295,21
+306,21
@@
static int onrunid(afb_req_t req, const char *method, int *runid)
* Sends the reply 'resp' to the request 'req' if 'resp' is not NULLzero.
* Otherwise, when 'resp' is NULL replies the error string 'errstr'.
*/
* Sends the reply 'resp' to the request 'req' if 'resp' is not NULLzero.
* Otherwise, when 'resp' is NULL replies the error string 'errstr'.
*/
-static void reply(afb_req_t req, struct json_object *resp
, const char *errstr
)
+static void reply(afb_req_t req, struct json_object *resp)
{
{
- if (
!
resp)
- afb_req_
fail(req, errstr
, NULL);
+ if (resp)
+ afb_req_
reply(req, resp, NULL
, NULL);
else
else
- afb_req_
success(req, resp, NULL
);
+ afb_req_
reply(req, NULL, "failed", strerror(errno)
);
}
/*
* Sends the reply "true" to the request 'req' if 'status' is zero.
* Otherwise, when 'status' is not zero replies the error string 'errstr'.
*/
}
/*
* Sends the reply "true" to the request 'req' if 'status' is zero.
* Otherwise, when 'status' is not zero replies the error string 'errstr'.
*/
-static void reply_status(afb_req_t req, int status
, const char *errstr
)
+static void reply_status(afb_req_t req, int status)
{
{
- reply(req, status ? NULL : json_object_get(json_true)
, errstr
);
+ reply(req, status ? NULL : json_object_get(json_true));
}
/*
}
/*
@@
-429,7
+440,7
@@
static void pause(afb_req_t req)
int runid, status;
if (onrunid(req, "pause", &runid)) {
status = afm_urun_pause(runid, afb_req_get_uid(req));
int runid, status;
if (onrunid(req, "pause", &runid)) {
status = afm_urun_pause(runid, afb_req_get_uid(req));
- reply_status(req, status
, _not_found_
);
+ reply_status(req, status);
}
}
}
}
@@
-441,7
+452,7
@@
static void resume(afb_req_t req)
int runid, status;
if (onrunid(req, "resume", &runid)) {
status = afm_urun_resume(runid, afb_req_get_uid(req));
int runid, status;
if (onrunid(req, "resume", &runid)) {
status = afm_urun_resume(runid, afb_req_get_uid(req));
- reply_status(req, status
, _not_found_
);
+ reply_status(req, status);
}
}
}
}
@@
-453,7
+464,7
@@
static void terminate(afb_req_t req)
int runid, status;
if (onrunid(req, "terminate", &runid)) {
status = afm_urun_terminate(runid, afb_req_get_uid(req));
int runid, status;
if (onrunid(req, "terminate", &runid)) {
status = afm_urun_terminate(runid, afb_req_get_uid(req));
- reply_status(req, status
, _not_found_
);
+ reply_status(req, status);
}
}
}
}
@@
-476,7
+487,7
@@
static void state(afb_req_t req)
struct json_object *resp;
if (onrunid(req, "state", &runid)) {
resp = afm_urun_state(afudb, runid, afb_req_get_uid(req));
struct json_object *resp;
if (onrunid(req, "state", &runid)) {
resp = afm_urun_state(afudb, runid, afb_req_get_uid(req));
- reply(req, resp
, _not_found_
);
+ reply(req, resp);
}
}
}
}