Browse Source

Define constants for supported control protocol versions.

(Rather than hard-coding the values at point-of-use.)
Davin McCall 5 years ago
parent
commit
b74e67c450
3 changed files with 13 additions and 2 deletions
  1. 6 0
      src/control.cc
  2. 3 1
      src/dinitctl.cc
  3. 4 1
      src/shutdown.cc

+ 6 - 0
src/control.cc

@@ -7,6 +7,10 @@
 namespace {
     constexpr auto OUT_EVENTS = dasynq::OUT_EVENTS;
     constexpr auto IN_EVENTS = dasynq::IN_EVENTS;
+
+    // Control protocol minimum compatible version and current version:
+    constexpr uint16_t min_compat_version = 1;
+    constexpr uint16_t cp_version = 1;
 }
 
 bool control_conn_t::process_packet()
@@ -22,6 +26,8 @@ bool control_conn_t::process_packet()
         // Responds with:
         // DINIT_RP_CVERSION, (2 byte) minimum compatible version, (2 byte) actual version
         char replyBuf[] = { DINIT_RP_CPVERSION, 0, 0, 0, 0 };
+        memcpy(replyBuf + 1, &min_compat_version, 2);
+        memcpy(replyBuf + 3, &cp_version, 2);
         if (! queue_packet(replyBuf, sizeof(replyBuf))) return false;
         rbuf.consume(1);
         return true;

+ 3 - 1
src/dinitctl.cc

@@ -22,6 +22,8 @@
 
 // This utility communicates with the dinit daemon via a unix stream socket (/dev/initctl, or $HOME/.dinitctl).
 
+static constexpr uint16_t min_cp_version = 1;
+static constexpr uint16_t max_cp_version = 1;
 
 enum class command_t;
 
@@ -226,7 +228,7 @@ int main(int argc, char **argv)
     try {
         // Start by querying protocol version:
         cpbuffer_t rbuffer;
-        check_protocol_version(0, 0, rbuffer, socknum);
+        check_protocol_version(min_cp_version, max_cp_version, rbuffer, socknum);
 
         if (command == command_t::UNPIN_SERVICE) {
             return unpin_service(socknum, rbuffer, service_name, verbose);

+ 4 - 1
src/shutdown.cc

@@ -24,6 +24,9 @@
 // shutdown:  shut down the system
 // This utility communicates with the dinit daemon via a unix socket (/dev/initctl).
 
+static constexpr uint16_t min_cp_version = 1;
+static constexpr uint16_t max_cp_version = 1;
+
 using loop_t = dasynq::event_loop_n;
 using rearm = dasynq::rearm;
 using clock_type = dasynq::clock_type;
@@ -344,7 +347,7 @@ int main(int argc, char **argv)
     try {
         cpbuffer_t rbuffer;
     
-        check_protocol_version(0, 0, rbuffer, socknum);
+        check_protocol_version(min_cp_version, max_cp_version, rbuffer, socknum);
 
         // Build buffer;
         constexpr int bufsize = 2;