From bfe507fe8c80540cbf8b9a97a0b92db20f123e59 Mon Sep 17 00:00:00 2001
From: Mike Brady <4265913+mikebrady@users.noreply.github.com>
Date: Mon, 22 Mar 2021 16:24:34 +0000
Subject: [PATCH] Tidy some stuff up.
---
debug.c | 21 +++++++++++++++++++--
debug.h | 21 +++++++++++++++++++++
nqptp-shm-structures.h | 2 +-
nqptp.c | 26 +++++++++++++++-----------
4 files changed, 56 insertions(+), 14 deletions(-)
diff --git a/debug.c b/debug.c
index 2650670..6b4a7c3 100644
--- 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 .
+ *
+ * Commercial licensing is also available.
+ */
+
#include
#include
#include
@@ -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 a14de2c..7415c97 100644
--- 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 .
+ *
+ * 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);
diff --git a/nqptp-shm-structures.h b/nqptp-shm-structures.h
index 17db129..8afa6f0 100644
--- a/nqptp-shm-structures.h
+++ b/nqptp-shm-structures.h
@@ -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 e16076e..e254c46 100644
--- 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);
--
2.47.2