]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Tidy some stuff up.
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Mon, 22 Mar 2021 16:24:34 +0000 (16:24 +0000)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Mon, 22 Mar 2021 16:24:34 +0000 (16:24 +0000)
debug.c
debug.h
nqptp-shm-structures.h
nqptp.c

diff --git a/debug.c b/debug.c
index 2650670484c713155f4c480da288520af62ff12c..6b4a7c359856c7675b94a832bc19543f23b30ac4 100644 (file)
--- a/debug.c
+++ b/debug.c
@@ -1,3 +1,22 @@
+/*
+ * This file is part of the nqptp distribution (https://github.com/mikebrady/nqptp).
+ * Copyright (c) 2021 Mike Brady.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Commercial licensing is also available.
+ */
+
 #include <stddef.h>
 #include <stdio.h>
 #include <string.h>
@@ -19,7 +38,6 @@ uint64_t ns_time_at_last_debug_message;
 // always lock use this when accessing the ns_time_at_last_debug_message
 static pthread_mutex_t debug_timing_lock = PTHREAD_MUTEX_INITIALIZER;
 
-
 uint64_t get_absolute_time_in_ns() {
   uint64_t time_now_ns;
   struct timespec tn;
@@ -41,7 +59,6 @@ void debug_init(int level, int show_elapsed_time, int show_relative_time, int sh
        debugger_show_file_and_line = show_file_and_line;
 }
 
-
 char *generate_preliminary_string(char *buffer, size_t buffer_length, double tss, double tsl,
                                   const char *filename, const int linenumber, const char *prefix) {
   size_t space_remaining = buffer_length;
diff --git a/debug.h b/debug.h
index a14de2c5e3b7d6493799c26cd823870cba78d145..7415c97f2687ed0ae65a6466aa3adbae2e1719d3 100644 (file)
--- a/debug.h
+++ b/debug.h
@@ -1,3 +1,24 @@
+/*
+ * This file is part of the nqptp distribution (https://github.com/mikebrady/nqptp).
+ * Copyright (c) 2021 Mike Brady.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Commercial licensing is also available.
+ */
+
+// four level debug message utility giving file and line, total elapsed time, interval time
+// warn / inform / debug / die calls.
 
 // level 0 is no messages, level 3 is most messages
 void debug_init(int level, int show_elapsed_time, int show_relative_time, int show_file_and_line);
index 17db129e750aac2389e473ef65fab45aca226da4..8afa6f004c6dfd85fce523f3452bba47d6dfb3a3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the nqPTP distribution (https://github.com/mikebrady/nqPTP).
+ * This file is part of the nqptp distribution (https://github.com/mikebrady/nqptp).
  * Copyright (c) 2021 Mike Brady.
  *
  * This program is free software: you can redistribute it and/or modify
diff --git a/nqptp.c b/nqptp.c
index e16076e7b7cdce183e635fc70df4f0850ef7d0cd..e254c4641f2245ac6c3bdd2066e74bf49eeb9a26 100644 (file)
--- a/nqptp.c
+++ b/nqptp.c
@@ -1,5 +1,5 @@
 /*
- * This file is part of the nqPTP distribution (https://github.com/mikebrady/nqPTP).
+ * This file is part of the nqptp distribution (https://github.com/mikebrady/nqptp).
  * Copyright (c) 2021 Mike Brady.
  *
  * This program is free software: you can redistribute it and/or modify
@@ -210,7 +210,10 @@ struct ptpSource *findOrCreateSource(struct ptpSource **list, char *ip, uint64_t
       response->vacant_samples = MAX_TIMING_SAMPLES; // no valid samples yet
       response->shared_clock_number = -1;            // none allocated yet. Hacky
       *insertion_point = response;
-      debug(3, "Clock record created for \"%s\".", ip);
+      debug(1,
+            "Clock record created for Clock ID: '%" PRIu64 "', aka '%" PRIu64 "', aka '%" PRIx64
+            "' at %s.",
+            clock_id, clock_id, clock_id, ip);
     }
   }
   return response;
@@ -299,22 +302,22 @@ void goodbye(void) {
     if (shm_unlink(STORAGE_ID) == -1)
       debug(1, "error unlinking shared memory \"%s\"", STORAGE_ID);
   }
-  debug(1,"goodbye");
+  debug(1, "goodbye");
 }
 
-void intHandler(__attribute__ ((unused)) int k) {
-       debug(1,"exit on SIGINT");
+void intHandler(__attribute__((unused)) int k) {
+  debug(1, "exit on SIGINT");
   exit(EXIT_SUCCESS);
 }
 
-void termHandler(__attribute__ ((unused)) int k) {
-       debug(1,"exit on SIGTERM");
+void termHandler(__attribute__((unused)) int k) {
+  debug(1, "exit on SIGTERM");
   exit(EXIT_SUCCESS);
 }
 
 int main(void) {
   // level 0 is no messages, level 3 is most messages -- see debug.h
-  debug_init(0, 0, 1, 1);
+  debug_init(1, 0, 1, 1);
   debug(1, "startup");
   atexit(goodbye);
 
@@ -476,7 +479,8 @@ int main(void) {
             "separate PTP daemon running?",
             p->ai_family == AF_INET6 ? "IPv6" : "IPv4", 320, strerror(errno));
       } else {
-        debug(3, "listen on %s port %d.", p->ai_family == AF_INET6 ? "IPv6" : "IPv4", 319);
+
+        debug(1, "listening on %s port %d.", p->ai_family == AF_INET6 ? "IPv6" : "IPv4", 319);
         sockets[sockets_open].number = fd;
         sockets[sockets_open++].port = 319;
       }
@@ -549,7 +553,7 @@ int main(void) {
             p->ai_family == AF_INET6 ? "IPv6" : "IPv4", 320, strerror(errno));
         exit(1);
       } else {
-        debug(3, "listen on %s port %d.", p->ai_family == AF_INET6 ? "IPv6" : "IPv4", 320);
+        debug(1, "listening on %s port %d.", p->ai_family == AF_INET6 ? "IPv6" : "IPv4", 320);
         sockets[sockets_open].number = fd;
         sockets[sockets_open++].port = 320;
       }
@@ -568,7 +572,7 @@ int main(void) {
   }
   shm_fd = shm_open(STORAGE_ID, O_RDWR | O_CREAT, 0660);
   if (shm_fd == -1) {
-    die("cannot open shared memory \"%s\".",STORAGE_ID);
+    die("cannot open shared memory \"%s\".", STORAGE_ID);
   }
   (void)umask(oldumask);