From: Davin McCall Date: Mon, 23 Nov 2015 09:43:59 +0000 (+0000) Subject: Add a "query version" command to the control protocol. X-Git-Tag: v0.01~102 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=18ef505588801f78127f277e6b465378335709fa;p=oweals%2Fdinit.git Add a "query version" command to the control protocol. --- 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; }