From 18ef505588801f78127f277e6b465378335709fa Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Mon, 23 Nov 2015 09:43:59 +0000 Subject: [PATCH] Add a "query version" command to the control protocol. --- control-cmds.h | 6 ++++++ control.cc | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/control-cmds.h b/control-cmds.h index f0d2e76..4888f08 100644 --- a/control-cmds.h +++ b/control-cmds.h @@ -9,6 +9,9 @@ constexpr static int DINIT_CP_STOPSERVICE = 1; // Roll-back all services: constexpr static int DINIT_CP_ROLLBACKALL = 2; +// Query protocol version: +constexpr static int DINIT_CP_QUERYVERSION = 3; + // Replies: @@ -28,3 +31,6 @@ constexpr static int DINIT_ROLLBACK_COMPLETED = 60; // Start service replies: constexpr static int DINIT_RP_SERVICELOADERR = 61; constexpr static int DINIT_RP_SERVICEOOM = 62; // couldn't start due to out-of-memory + +// Query version response: +constexpr static int DINIT_RP_CPVERSION = 63; diff --git a/control.cc b/control.cc index fd1c366..bc7182a 100644 --- a/control.cc +++ b/control.cc @@ -10,6 +10,15 @@ void ControlConn::processPacket() // shouldn't touch instance members after that point. int pktType = iobuf[0]; + if (pktType == DINIT_CP_QUERYVERSION) { + // Responds with: + // DINIT_RP_CVERSION, (2 byte) minimum compatible version, (2 byte) maximum compatible version + char replyBuf[] = { DINIT_RP_CPVERSION, 0, 0, 0, 0 }; + if (! queuePacket(replyBuf, 1)) return; + memmove(iobuf, iobuf + 1, 1024 - 1); + bufidx -= 1; + return; + } if (pktType == DINIT_CP_STARTSERVICE || pktType == DINIT_CP_STOPSERVICE) { if (bufidx < 4) { chklen = 4; @@ -42,6 +51,7 @@ void ControlConn::processPacket() if (! queuePacket(ack_buf, 1)) return; } catch (ServiceLoadExc &slexc) { + log(LogLevel::ERROR, "Could not start service ", slexc.serviceName, ": ", slexc.excDescription); char outbuf[] = { DINIT_RP_SERVICELOADERR }; if (! queuePacket(outbuf, 1)) return; } @@ -81,7 +91,11 @@ void ControlConn::processPacket() return; } else { - // TODO error response + // Unrecognized: give error response + char outbuf[] = { DINIT_RP_BADREQ }; + if (! queuePacket(outbuf, 1)) return; + bad_conn_close = true; + ev_io_set(&iob, iob.fd, EV_WRITE); } return; } -- 2.25.1