diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-01-04 12:36:05 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-01-04 12:54:29 +0200 |
commit | 2782ae034e51d5e9c74a9b1f2c6e6c452bd83243 (patch) | |
tree | a79664c1090d35c899eb867e1b749630cc455b00 | |
parent | 5c7f75146266ece25a47dc8df898ac1e1629f51d (diff) | |
download | pies-2782ae034e51d5e9c74a9b1f2c6e6c452bd83243.tar.gz pies-2782ae034e51d5e9c74a9b1f2c6e6c452bd83243.tar.bz2 |
Minor fixes
* src/ctl.c: Start textual descriptions with capital letters.
* src/piesctl-cl.opt: Fix typos.
* src/piesctl.c (shttp_process): Fix error handling.
(shttp_fatal): Select exit code depending on the HTTP response code.
-rw-r--r-- | src/ctl.c | 8 | ||||
-rw-r--r-- | src/piesctl-cl.opt | 4 | ||||
-rw-r--r-- | src/piesctl.c | 56 |
3 files changed, 56 insertions, 12 deletions
@@ -1715,7 +1715,7 @@ static void component_stop (struct ctlio *io, struct prog *prog) { if (prog->v.p.comp->flags & CF_DISABLED) - ctlio_reply (io, 409, "already stopped"); + ctlio_reply (io, 409, "Already stopped"); else { progman_stop_component (prog); @@ -1727,15 +1727,15 @@ component_stop (struct ctlio *io, struct prog *prog) static void component_start (struct ctlio *io, struct prog *prog) { - if (!(prog->v.p.comp->flags & CF_DISABLED)) - ctlio_reply (io, 409, "already running"); - else + if (prog->v.p.comp->flags & CF_DISABLED) { prog->v.p.comp->flags &= ~CF_DISABLED; prog->v.p.status = status_enabled; kill (getpid (), SIGALRM); ctlio_reply (io, 200, "Component started"); } + else + ctlio_reply (io, 409, "Already running"); } static void diff --git a/src/piesctl-cl.opt b/src/piesctl-cl.opt index d026269..b8e4fc1 100644 --- a/src/piesctl-cl.opt +++ b/src/piesctl-cl.opt @@ -41,7 +41,7 @@ BEGIN END OPTION(,E,, - [<preprocess config and exit>]) + [<preprocess configuration files and exit>]) BEGIN preprocess_only = 1; END @@ -53,7 +53,7 @@ BEGIN END OPTION(dump,d,, - [<dump obtained responsed verbatim>]) + [<dump obtained responses verbatim>]) BEGIN ++dump; END diff --git a/src/piesctl.c b/src/piesctl.c index 3ae4af2..4319946 100644 --- a/src/piesctl.c +++ b/src/piesctl.c @@ -816,7 +816,8 @@ static void shttp_fatal (struct shttp_connection *conn) { struct json_value *jv; - + int status; + if (conn->result && (jv = json_value_lookup (conn->result, "error_message"))) { if (jv->type == json_string) @@ -827,7 +828,36 @@ shttp_fatal (struct shttp_connection *conn) else grecs_error (NULL, 0, "%s", conn->status_line[2]); - exit (1); + switch (conn->resp.code) + { + case 400: + case 405: + case 501: + case 505: + grecs_error (NULL, 0, _("please report")); + status = EX_SOFTWARE; + break; + + case 401: + status = EX_NOUSER; + break; + + case 403: + status = EX_NOPERM; + break; + + case 404: + status = EX_NOINPUT; + break; + + default: + if (conn->resp.code >= 400 && conn->resp.code < 500) + status = EX_TEMPFAIL; + else + status = EX_UNAVAILABLE; + } + + exit (status); } static void @@ -930,12 +960,26 @@ shttp_process (struct shttp_connection *conn, int method, char const *uri) shttp_get_reply (conn); if (dump && conn->result) shttp_format_result (conn, stdout); + if (conn->resp.code / 100 == 2) return; - if (conn->resp.code == 401 && isatty (fileno (stdin))) - shttp_get_credentials (conn); - else - shttp_fatal (conn); + + switch (conn->resp.code) + { + case 401: + if (isatty (fileno (stdin))) + shttp_get_credentials (conn); + else + shttp_fatal (conn); + break; + + case 404: /* Not found */ + case 409: /* Conflict */ + return; + + default: + shttp_fatal (conn); + } } } |