From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Mon, 28 Feb 2022 06:42:25 +0000 (+1100) Subject: Always create a new SHM interface for every new shm address provided. Remove redundan... X-Git-Tag: 1.2~46^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d111219ce38d3a8589e1f0006758698bc57f158;p=thirdparty%2Fnqptp.git Always create a new SHM interface for every new shm address provided. Remove redundant coded. Add a few debug messages. Enhance the service record to define the service provided. --- diff --git a/nqptp-clock-sources.c b/nqptp-clock-sources.c index ef41700..b35ba25 100644 --- a/nqptp-clock-sources.c +++ b/nqptp-clock-sources.c @@ -46,21 +46,6 @@ clock_source_private_data clocks_private[MAX_CLOCKS]; client_record clients[MAX_CLIENTS]; -int find_client_id(char *client_shared_memory_interface_name) { - int response = -1; // signify not found - if (client_shared_memory_interface_name != NULL) { - int i = 0; - // first, see if yu can find it anywhere - while ((response == -1) && (i < MAX_CLIENTS)) { - if (strcmp(clients[i].shm_interface_name, client_shared_memory_interface_name) == 0) - response = i; - else - i++; - } - } - return response; -} - const char *get_client_name(int client_id) { if ((client_id >= 0) && (client_id < MAX_CLIENTS)) { return clients[client_id].shm_interface_name; @@ -80,7 +65,7 @@ int get_client_id(char *client_shared_memory_interface_name) { else i++; } - + if (response == -1) { // no match, so create one i = 0; while ((response == -1) && (i < MAX_CLIENTS)) { @@ -94,9 +79,10 @@ int get_client_id(char *client_shared_memory_interface_name) { int err; strncpy(clients[i].shm_interface_name, client_shared_memory_interface_name, sizeof(clients[i].shm_interface_name)); - // creat the named smi interface + // create the named smi interface // open a shared memory interface. + debug(2, "Create a shm interface named \"%s\"", clients[i].shm_interface_name); clients[i].shm_fd = -1; mode_t oldumask = umask(0); @@ -163,6 +149,7 @@ int get_client_id(char *client_shared_memory_interface_name) { } else { debug(1, "no client_shared_memory_interface_name"); } + debug(2, "get_client_id \"%s\" response %d", client_shared_memory_interface_name, response); return response; } diff --git a/nqptp-clock-sources.h b/nqptp-clock-sources.h index 9e9bada..760a051 100644 --- a/nqptp-clock-sources.h +++ b/nqptp-clock-sources.h @@ -84,7 +84,6 @@ void update_clock_self_identifications(clock_source_private_data *clocks_private void manage_clock_sources(uint64_t reception_time, clock_source_private_data *clocks_private_info); -int find_client_id(char *client_shared_memory_interface_name); int get_client_id(char *client_shared_memory_interface_name); const char *get_client_name(int client_id); int delete_client(int client_id); diff --git a/nqptp-message-handlers.c b/nqptp-message-handlers.c index a0f12b1..c37f5b4 100644 --- a/nqptp-message-handlers.c +++ b/nqptp-message-handlers.c @@ -29,7 +29,7 @@ void handle_control_port_messages(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info) { if (recv_len != -1) { buf[recv_len - 1] = 0; // make sure there's a null in it! - debug(1, "New control port message: \"%s\".", buf); + debug(2, "New control port message: \"%s\".", buf); // we need to get the client shared memory interface name from the front char *ip_list = buf; char *smi_name = strsep(&ip_list, " "); @@ -40,7 +40,7 @@ void handle_control_port_messages(char *buf, ssize_t recv_len, command = strsep(&ip_list, " "); if ((command == NULL) || ((strcmp(command, "T") == 0) && (ip_list == NULL))) { // clear all the flags, but only if the client exists - client_id = find_client_id(smi_name); // don't create a record + client_id = get_client_id(smi_name); // create the record if it doesn't exist if (client_id != -1) { // turn off all is_timing_peer flags int i; @@ -70,6 +70,7 @@ void handle_control_port_messages(char *buf, ssize_t recv_len, } } } else { + debug(2,"get or create new record for \"%s\".",smi_name); client_id = get_client_id(smi_name); // create the record if it doesn't exist if (client_id != -1) { if (strcmp(command, "T") == 0) { diff --git a/nqptp.service.in b/nqptp.service.in index a0f619a..d166aff 100644 --- a/nqptp.service.in +++ b/nqptp.service.in @@ -1,4 +1,5 @@ [Unit] +Provides=nqptp.service Description=NQPTP -- Not Quite PTP Wants=network-online.target After=network.target network-online.target