summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2023-05-25 13:46:03 +1000
committerKinseyMoore <48726349+KinseyMoore@users.noreply.github.com>2023-05-25 07:40:24 -0500
commitd0e1e800a1bbf075743286a99cd10ef20ae9b584 (patch)
tree991278aecfa02e37f9f751ba07077be6671d3a61
parentbsd/ntp: Only clean up in the finish safe handler (diff)
downloadrtems-net-services-d0e1e800a1bbf075743286a99cd10ef20ae9b584.tar.bz2
bsd/ntp: Set the ntpq fd set size
- Fix the trailing line feed printing
-rw-r--r--bsd/rtemsbsd/rtems/rtems-ntpq.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/bsd/rtemsbsd/rtems/rtems-ntpq.c b/bsd/rtemsbsd/rtems/rtems-ntpq.c
index 367b743..a32556c 100644
--- a/bsd/rtemsbsd/rtems/rtems-ntpq.c
+++ b/bsd/rtemsbsd/rtems/rtems-ntpq.c
@@ -223,10 +223,12 @@ int rtems_ntpq_create(size_t output_buf_size) {
alloc_size = ((alloc_size / 16) + 1) * 16;
}
fd_set_break = alloc_size;
- alloc_size +=
+ rtems_ntpq_fd_set_size =
sizeof(fd_set) * (howmany(rtems_libio_number_iops, sizeof(fd_set) * 8));
+ alloc_size += rtems_ntpq_fd_set_size;
rtems_ntpq_output_buf = calloc(1, alloc_size);
if (rtems_ntpq_output_buf == NULL) {
+ rtems_ntpq_fd_set_size = 0;
rtems_ntpq_error(ENOMEM, "no memory");
rtems_recursive_mutex_unlock(&ntpq_lock);
return -1;
@@ -236,6 +238,7 @@ int rtems_ntpq_create(size_t output_buf_size) {
if (rtems_ntpq_outputfp == NULL) {
rtems_ntpq_error(errno, "buffered file pointer");
free(rtems_ntpq_output_buf);
+ rtems_ntpq_fd_set_size = 0;
rtems_ntpq_output_buf_size = 0;
rtems_ntpq_output_buf = NULL;
rtems_ntpq_fd_set = NULL;
@@ -257,6 +260,7 @@ void rtems_ntpq_destroy(void) {
fclose(rtems_ntpq_outputfp);
}
free(rtems_ntpq_output_buf);
+ rtems_ntpq_fd_set_size = 0;
rtems_ntpq_output_buf_size = 0;
rtems_ntpq_output_buf = NULL;
rtems_ntpq_fd_set = NULL;
@@ -449,11 +453,15 @@ int rtems_shell_ntpq_command(int argc, char **argv) {
r = rtems_ntpq_query(argc, (const char**) argv);
}
if (r == 0) {
+ const char* output = rtems_ntpq_output();
+ const size_t len = strlen(output);
printf(rtems_ntpq_output());
+ if (len > 0 && output[len - 1] != '\n') {
+ printf("\n");
+ }
} else {
- printf(rtems_ntpq_error_text());
+ printf("%s\n", rtems_ntpq_error_text());
}
- printf("\n");
return r;
}