+/*
+ * 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>
// 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;
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;
+/*
+ * 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);
/*
- * 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
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;
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);
"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;
}
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;
}
}
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);