commit - c83e450a02fd06d73c5cbc444a1ccd6fc0bf0fa6
commit + b478a4bd62bf67f8603a0ec7e4fd533ba51d1008
blob - 9e64528d62a13660ef647ef40120c6a03dc0efa6
blob + 1e7aec349daec38f225163db76367135fe2cb4d9
--- web/web.c
+++ web/web.c
}
static void
+unexpected_imsg(struct imsg *imsg, const char *expected)
+{
+ const char *msg;
+ size_t datalen;
+
+ if (imsg->hdr.type != IMSG_CTL_ERR) {
+ log_warnx("got event %d while expecting %s",
+ imsg->hdr.type, expected);
+ return;
+ }
+
+ datalen = IMSG_DATA_SIZE(*imsg);
+ msg = imsg->data;
+ if (datalen == 0 || msg[datalen - 1] != '\0')
+ fatalx("malformed error message");
+ log_warnx("failure: %s", msg);
+}
+
+static void
route_notfound(struct reswriter *res, struct request *req)
{
if (http_reply(res, 404, "Not Found", "text/plain") == -1 ||
break;
if (imsg.hdr.type != IMSG_CTL_SHOW) {
- log_warnx("got event %d while expecting SHOW",
- imsg.hdr.type);
+ unexpected_imsg(&imsg, "IMSG_CTL_SHOW");
imsg_free(&imsg);
continue;
}
return;
if (imsg.hdr.type != IMSG_CTL_STATUS) {
- log_warnx("got event %d while expecting CTL_STATUS",
- imsg.hdr.type);
+ unexpected_imsg(&imsg, "IMSG_CTL_STATUS");
goto done;
}
if (IMSG_DATA_SIZE(imsg) != sizeof(ps))
break;
if (imsg.hdr.type != IMSG_CTL_STATUS) {
- log_warnx("got event %d while expecting"
- " IMSG_CTL_STATUS", imsg.hdr.type);
+ unexpected_imsg(&imsg, "IMSG_CTL_STATUS");
imsg_free(&imsg);
continue;
}
break;
if (imsg.hdr.type != IMSG_CTL_STATUS) {
- log_warnx("got event %d while expecting"
- " IMSG_CTL_STATUS", imsg.hdr.type);
+ unexpected_imsg(&imsg, "IMSG_CTL_STATUS");
imsg_free(&imsg);
continue;
}