| 30 | } |
| 31 | |
| 32 | bool control_conn_t::process_packet() |
| 33 | { |
| 34 | using std::string; |
| 35 | |
| 36 | // Note that where we call queue_packet, we must generally check the return value. If it |
| 37 | // returns false it has either deleted the connection or marked it for deletion; we |
| 38 | // shouldn't touch instance members after that point. |
| 39 | |
| 40 | cp_cmd pkt_type = (cp_cmd)rbuf[0]; |
| 41 | |
| 42 | switch (pkt_type) { |
| 43 | case cp_cmd::QUERYVERSION: |
| 44 | { |
| 45 | // Responds with: |
| 46 | // cp_rply::CPVERSION, (2 byte) minimum compatible version, (2 byte) actual version |
| 47 | char replyBuf[] = { (char)cp_rply::CPVERSION, 0, 0, 0, 0 }; |
| 48 | memcpy(replyBuf + 1, &min_compat_version, 2); |
| 49 | memcpy(replyBuf + 3, &cp_version, 2); |
| 50 | if (!queue_packet(replyBuf, sizeof(replyBuf))) return false; |
| 51 | rbuf.consume(1); |
| 52 | return true; |
| 53 | } |
| 54 | case cp_cmd::FINDSERVICE: |
| 55 | case cp_cmd::LOADSERVICE: |
| 56 | return process_find_load(pkt_type); |
| 57 | case cp_cmd::CLOSEHANDLE: |
| 58 | return process_close_handle(); |
| 59 | case cp_cmd::STARTSERVICE: |
| 60 | case cp_cmd::STOPSERVICE: |
| 61 | case cp_cmd::WAKESERVICE: |
| 62 | case cp_cmd::RELEASESERVICE: |
| 63 | return process_start_stop(pkt_type); |
| 64 | case cp_cmd::UNPINSERVICE: |
| 65 | return process_unpin_service(); |
| 66 | case cp_cmd::UNLOADSERVICE: |
| 67 | return process_unload_service(); |
| 68 | case cp_cmd::RELOADSERVICE: |
| 69 | return process_reload_service(); |
| 70 | case cp_cmd::SHUTDOWN: |
| 71 | // Shutdown/reboot |
| 72 | if (rbuf.get_length() < 2) { |
| 73 | chklen = 2; |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | if (contains({shutdown_type_t::REMAIN, shutdown_type_t::HALT, |
| 78 | shutdown_type_t::POWEROFF, shutdown_type_t::REBOOT, |
| 79 | shutdown_type_t::SOFTREBOOT, shutdown_type_t::KEXEC}, rbuf[1])) { |
| 80 | auto sd_type = static_cast<shutdown_type_t>(rbuf[1]); |
| 81 | |
| 82 | services->stop_all_services(sd_type); |
| 83 | char ackBuf[] = { (char)cp_rply::ACK }; |
| 84 | if (!queue_packet(ackBuf, 1)) return false; |
| 85 | |
| 86 | // Clear the packet from the buffer |
| 87 | rbuf.consume(2); |
| 88 | chklen = 0; |
| 89 | return true; |
nothing calls this directly
no test coverage detected