if (pktType == DINIT_CP_ENABLESERVICE) {
return add_service_dep(true);
}
+ if (pktType == DINIT_CP_QUERYSERVICENAME) {
+ return process_query_name();
+ }
// Unrecognized: give error response
char outbuf[] = { DINIT_RP_BADREQ };
return true;
}
+bool control_conn_t::process_query_name()
+{
+ // 1 byte packet type
+ // 1 byte reserved
+ // handle: service
+ constexpr int pkt_size = 2 + sizeof(handle_t);
+
+ if (rbuf.get_length() < pkt_size) {
+ chklen = pkt_size;
+ return true;
+ }
+
+ // Reply:
+ // 1 byte packet type = DINIT_RP_SERVICENAME
+ // 1 byte reserved
+ // uint16_t length
+ // N bytes name
+
+ handle_t handle;
+ rbuf.extract(&handle, 2, sizeof(handle));
+ rbuf.consume(pkt_size);
+ chklen = 0;
+
+ service_record *service = find_service_for_key(handle);
+ if (service == nullptr || service->get_name().length() > std::numeric_limits<uint16_t>::max()) {
+ char ack_rep[] = { DINIT_RP_ACK };
+ if (! queue_packet(ack_rep, 1)) return false;
+ }
+
+ std::vector<char> reply;
+ const std::string &name = service->get_name();
+ uint16_t name_length = name.length();
+ reply.resize(2 + sizeof(uint16_t) + name_length);
+ reply[0] = DINIT_RP_SERVICENAME;
+ memcpy(reply.data() + 2, &name_length, sizeof(name_length));
+ memcpy(reply.data() + 2 + sizeof(uint16_t), name.c_str(), name_length);
+
+ return queue_packet(std::move(reply));
+}
+
bool control_conn_t::query_load_mech()
{
rbuf.consume(1);
if (try_path_size == 0) {
// overflow.
char ack_rep[] = { DINIT_RP_NAK };
- if (! queue_packet(ack_rep, 1)) return false;
- return true;
+ return queue_packet(ack_rep, 1);
}
}
else {
// If we don't know how to deal with the service set type, send a NAK reply:
char ack_rep[] = { DINIT_RP_NAK };
- if (! queue_packet(ack_rep, 1)) return false;
- return true;
+ return queue_packet(ack_rep, 1);
}
}
// Add a waits for dependency from one service to another, and start the dependency:
constexpr static int DINIT_CP_ENABLESERVICE = 14;
+// Find the name of a service (from a handle)
+constexpr static int DINIT_CP_QUERYSERVICENAME = 15;
+
// Replies:
// Reply: ACK/NAK to request
// Dependent services prevent stopping/restarting. Includes size_t count, handle_t * N handles.
constexpr static int DINIT_RP_DEPENDENTS = 65;
+// Service name:
+constexpr static int DINIT_RP_SERVICENAME = 66;
+
// Information:
// Service event occurred (4-byte service handle, 1 byte event code)