From 2cc313f34ece38518225f546370fe1e3c779a021 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Sun, 23 Apr 2023 19:13:28 -1000 Subject: bsd/ntp: Add ntpq command --- bsd/freebsd/contrib/ntp/include/ntp_lineedit.h | 2 +- bsd/freebsd/contrib/ntp/libntp/atolfp.c | 2 + bsd/freebsd/contrib/ntp/libntp/atouint.c | 2 + bsd/freebsd/contrib/ntp/libntp/authusekey.c | 2 + bsd/freebsd/contrib/ntp/libntp/caltontp.c | 2 + bsd/freebsd/contrib/ntp/libntp/hextoint.c | 2 + bsd/freebsd/contrib/ntp/libntp/hextolfp.c | 2 + bsd/freebsd/contrib/ntp/libntp/mstolfp.c | 2 + bsd/freebsd/contrib/ntp/libntp/octtoint.c | 2 + bsd/freebsd/contrib/ntp/libntp/socktohost.c | 2 + bsd/freebsd/contrib/ntp/ntpq/libntpq.c | 2 + bsd/freebsd/contrib/ntp/ntpq/libntpq.h | 2 + bsd/freebsd/contrib/ntp/ntpq/libntpq_subs.c | 2 + bsd/freebsd/contrib/ntp/ntpq/ntpq-opts.c | 2 + bsd/freebsd/contrib/ntp/ntpq/ntpq-opts.h | 2 + bsd/freebsd/contrib/ntp/ntpq/ntpq-subs.c | 30 ++ bsd/freebsd/contrib/ntp/ntpq/ntpq.c | 49 ++- bsd/freebsd/contrib/ntp/ntpq/ntpq.h | 4 + bsd/freebsd/contrib/ntp/sntp/libopts/ag-char-map.h | 3 - bsd/rtemsbsd/include/rtems/ntpq.h | 71 ++++ .../include/rtems/shellconfig-net-services.h | 54 +++ bsd/rtemsbsd/rtems/rtems-ntpq.c | 468 +++++++++++++++++++++ net/legacy/ntp/config.h | 2 - net/libbsd/ntp/config.h | 2 - net/lwip/ntp/config.h | 2 - netservices.py | 6 +- ntp-file-import.json | 14 +- testsuites/ntp01/test_main.c | 69 ++- 28 files changed, 782 insertions(+), 22 deletions(-) create mode 100644 bsd/rtemsbsd/include/rtems/ntpq.h create mode 100644 bsd/rtemsbsd/include/rtems/shellconfig-net-services.h create mode 100644 bsd/rtemsbsd/rtems/rtems-ntpq.c diff --git a/bsd/freebsd/contrib/ntp/include/ntp_lineedit.h b/bsd/freebsd/contrib/ntp/include/ntp_lineedit.h index 623c6f4..35a5c93 100755 --- a/bsd/freebsd/contrib/ntp/include/ntp_lineedit.h +++ b/bsd/freebsd/contrib/ntp/include/ntp_lineedit.h @@ -1,3 +1,4 @@ +#include /* * ntp_lineedit.h - generic interface to various line editing libs @@ -10,4 +11,3 @@ void ntp_readline_uninit(void); * strings returned by ntp_readline go home to free() */ char * ntp_readline(int *pcount); - diff --git a/bsd/freebsd/contrib/ntp/libntp/atolfp.c b/bsd/freebsd/contrib/ntp/libntp/atolfp.c index 439194e..0c8cc2b 100644 --- a/bsd/freebsd/contrib/ntp/libntp/atolfp.c +++ b/bsd/freebsd/contrib/ntp/libntp/atolfp.c @@ -1,3 +1,5 @@ +#include + /* * atolfp - convert an ascii string to an l_fp number */ diff --git a/bsd/freebsd/contrib/ntp/libntp/atouint.c b/bsd/freebsd/contrib/ntp/libntp/atouint.c index 0a61639..a4fdfa4 100755 --- a/bsd/freebsd/contrib/ntp/libntp/atouint.c +++ b/bsd/freebsd/contrib/ntp/libntp/atouint.c @@ -1,3 +1,5 @@ +#include + #include #include #include diff --git a/bsd/freebsd/contrib/ntp/libntp/authusekey.c b/bsd/freebsd/contrib/ntp/libntp/authusekey.c index ff449d3..dfa870c 100644 --- a/bsd/freebsd/contrib/ntp/libntp/authusekey.c +++ b/bsd/freebsd/contrib/ntp/libntp/authusekey.c @@ -1,3 +1,5 @@ +#include + /* * authusekey - decode a key from ascii and use it */ diff --git a/bsd/freebsd/contrib/ntp/libntp/caltontp.c b/bsd/freebsd/contrib/ntp/libntp/caltontp.c index 808c94c..0fcf32a 100644 --- a/bsd/freebsd/contrib/ntp/libntp/caltontp.c +++ b/bsd/freebsd/contrib/ntp/libntp/caltontp.c @@ -1,3 +1,5 @@ +#include + /* * caltontp - convert a date to an NTP time */ diff --git a/bsd/freebsd/contrib/ntp/libntp/hextoint.c b/bsd/freebsd/contrib/ntp/libntp/hextoint.c index 980a43f..f490018 100755 --- a/bsd/freebsd/contrib/ntp/libntp/hextoint.c +++ b/bsd/freebsd/contrib/ntp/libntp/hextoint.c @@ -1,3 +1,5 @@ +#include + /* * hextoint - convert an ascii string in hex to an unsigned * long, with error checking diff --git a/bsd/freebsd/contrib/ntp/libntp/hextolfp.c b/bsd/freebsd/contrib/ntp/libntp/hextolfp.c index 19a93cd..c62177d 100755 --- a/bsd/freebsd/contrib/ntp/libntp/hextolfp.c +++ b/bsd/freebsd/contrib/ntp/libntp/hextolfp.c @@ -1,3 +1,5 @@ +#include + /* * hextolfp - convert an ascii hex string to an l_fp number */ diff --git a/bsd/freebsd/contrib/ntp/libntp/mstolfp.c b/bsd/freebsd/contrib/ntp/libntp/mstolfp.c index 3dfc4ef..4521359 100644 --- a/bsd/freebsd/contrib/ntp/libntp/mstolfp.c +++ b/bsd/freebsd/contrib/ntp/libntp/mstolfp.c @@ -1,3 +1,5 @@ +#include + /* * mstolfp - convert an ascii string in milliseconds to an l_fp number */ diff --git a/bsd/freebsd/contrib/ntp/libntp/octtoint.c b/bsd/freebsd/contrib/ntp/libntp/octtoint.c index e519601..8090114 100644 --- a/bsd/freebsd/contrib/ntp/libntp/octtoint.c +++ b/bsd/freebsd/contrib/ntp/libntp/octtoint.c @@ -1,3 +1,5 @@ +#include + /* * octtoint - convert an ascii string in octal to an unsigned * long, with error checking diff --git a/bsd/freebsd/contrib/ntp/libntp/socktohost.c b/bsd/freebsd/contrib/ntp/libntp/socktohost.c index fdf9adb..4f0ff4a 100644 --- a/bsd/freebsd/contrib/ntp/libntp/socktohost.c +++ b/bsd/freebsd/contrib/ntp/libntp/socktohost.c @@ -1,3 +1,5 @@ +#include + /* * socktoa - return a numeric host name from a sockaddr_storage structure */ diff --git a/bsd/freebsd/contrib/ntp/ntpq/libntpq.c b/bsd/freebsd/contrib/ntp/ntpq/libntpq.c index e7f0266..24b68f9 100644 --- a/bsd/freebsd/contrib/ntp/ntpq/libntpq.c +++ b/bsd/freebsd/contrib/ntp/ntpq/libntpq.c @@ -1,3 +1,5 @@ +#include + /***************************************************************************** * * libntpq.c diff --git a/bsd/freebsd/contrib/ntp/ntpq/libntpq.h b/bsd/freebsd/contrib/ntp/ntpq/libntpq.h index 74caf27..78420ff 100644 --- a/bsd/freebsd/contrib/ntp/ntpq/libntpq.h +++ b/bsd/freebsd/contrib/ntp/ntpq/libntpq.h @@ -1,3 +1,5 @@ +#include + /***************************************************************************** * * libntpq.h diff --git a/bsd/freebsd/contrib/ntp/ntpq/libntpq_subs.c b/bsd/freebsd/contrib/ntp/ntpq/libntpq_subs.c index b232065..6f80f45 100644 --- a/bsd/freebsd/contrib/ntp/ntpq/libntpq_subs.c +++ b/bsd/freebsd/contrib/ntp/ntpq/libntpq_subs.c @@ -1,3 +1,5 @@ +#include + /***************************************************************************** * * libntpq_subs.c diff --git a/bsd/freebsd/contrib/ntp/ntpq/ntpq-opts.c b/bsd/freebsd/contrib/ntp/ntpq/ntpq-opts.c index ca08c3f..20b3985 100644 --- a/bsd/freebsd/contrib/ntp/ntpq/ntpq-opts.c +++ b/bsd/freebsd/contrib/ntp/ntpq/ntpq-opts.c @@ -1,3 +1,5 @@ +#include + /* * EDIT THIS FILE WITH CAUTION (ntpq-opts.c) * diff --git a/bsd/freebsd/contrib/ntp/ntpq/ntpq-opts.h b/bsd/freebsd/contrib/ntp/ntpq/ntpq-opts.h index 9bc23b8..f053d9f 100644 --- a/bsd/freebsd/contrib/ntp/ntpq/ntpq-opts.h +++ b/bsd/freebsd/contrib/ntp/ntpq/ntpq-opts.h @@ -1,3 +1,5 @@ +#include + /* * EDIT THIS FILE WITH CAUTION (ntpq-opts.h) * diff --git a/bsd/freebsd/contrib/ntp/ntpq/ntpq-subs.c b/bsd/freebsd/contrib/ntp/ntpq/ntpq-subs.c index 3020cc5..b5bb9fd 100644 --- a/bsd/freebsd/contrib/ntp/ntpq/ntpq-subs.c +++ b/bsd/freebsd/contrib/ntp/ntpq/ntpq-subs.c @@ -1,3 +1,5 @@ +#include + /* * ntpq-subs.c - subroutines which are called to perform ntpq commands. */ @@ -10,6 +12,10 @@ #include "ntpq.h" #include "ntpq-opts.h" +#ifdef __rtems__ +#undef fflush +#define fflush(fp) +#endif /* __rtems__ */ extern char currenthost[]; extern int currenthostisnum; size_t maxhostlen; @@ -270,7 +276,13 @@ typedef int (*qsort_cmp)(const void *, const void *); #define OLD_CTL_PST_SEL_SYNCCAND 2 #define OLD_CTL_PST_SEL_SYSPEER 3 +#ifdef _rtems__ +static const +#endif /* __rtems__ */ char flash2[] = " .+* "; /* flash decode for version 2 */ +#ifdef _rtems__ +static const +#endif /* __rtems__ */ char flash3[] = " x.-+#*o"; /* flash decode for peer status version 3 */ struct varlist { @@ -400,7 +412,11 @@ xprintf( int rc; va_start(va, fmt); +#ifndef __rtems__ rc = vfprintf((ofp ? ofp : stderr), fmt, va); +#else /* __rtems__ */ + rc = vfprintf(ofp, fmt, va); +#endif /* __rtems__ */ va_end(va); return rc; } @@ -411,7 +427,11 @@ xputs( FILE * ofp ) { +#ifndef __rtems__ return fputs(str, (ofp ? ofp : stderr)); +#else /* __rtems__ */ + return fputs(str, ofp); +#endif /* __rtems__ */ } static int @@ -420,7 +440,11 @@ xputc( FILE * ofp ) { +#ifndef __rtems__ return fputc(ch, (ofp ? ofp : stderr)); +#else /* __rtems__ */ + return fputc(ch, ofp); +#endif /* __rtems__ */ } /* @@ -737,9 +761,11 @@ dolist( * if we're asking for specific variables don't include the * status header line in the output. */ +#ifndef __rtems__ if (old_rv) quiet = 0; else +#endif /* __rtems__ */ quiet = (vlist->name != NULL); res = doquerylist(vlist, op, associd, 0, &rstatus, &dsize, &datap); @@ -3174,7 +3200,9 @@ mrulist( size_t i; mrulist_interrupted = FALSE; +#ifndef __rtems__ push_ctrl_c_handler(&mrulist_ctrl_c_hook); +#endif /* __rtems__ */ xprintf(stderr, "Ctrl-C will stop MRU retrieval and display partial results.\n"); fflush(stderr); @@ -3326,7 +3354,9 @@ cleanup_return: hash_table = NULL; INIT_DLIST(mru_list, mlink); +#ifndef __rtems__ pop_ctrl_c_handler(&mrulist_ctrl_c_hook); +#endif /* __rtems__ */ } diff --git a/bsd/freebsd/contrib/ntp/ntpq/ntpq.c b/bsd/freebsd/contrib/ntp/ntpq/ntpq.c index 0382c0f..1cea922 100644 --- a/bsd/freebsd/contrib/ntp/ntpq/ntpq.c +++ b/bsd/freebsd/contrib/ntp/ntpq/ntpq.c @@ -1,3 +1,5 @@ +#include + /* * ntpq - query an NTP server using mode 6 commands */ @@ -47,7 +49,9 @@ # define CMAC "AES128CMAC" # endif #endif +#ifndef __rtems__ #include +#endif /* __rtems__ */ #include "ntp_libopts.h" #include "safecast.h" @@ -57,6 +61,10 @@ # define SERVER_PORT_NUM 123 #endif +#ifdef __rtems__ +#undef fflush +#define fflush(fp) +#endif /* __rtems__ */ /* we use COMMAND as an autogen keyword */ #ifdef COMMAND # undef COMMAND @@ -87,16 +95,28 @@ te_Refid drefid = -1; /* * for get_systime() */ +#ifndef __rtems__ s_char sys_precision; /* local clock precision (log2 s) */ +#else /* __rtems__ */ +extern s_char sys_precision; +#endif /* __rtems__ */ /* * Keyid used for authenticated requests. Obtained on the fly. */ +#ifndef __rtems__ u_long info_auth_keyid = 0; +#else /* __rtems__ */ +extern keyid_t info_auth_keyid; +#endif /* __rtems__ */ static int info_auth_keytype = NID_md5; /* MD5 */ static size_t info_auth_hashlen = 16; /* MD5 */ +#ifndef __rtems__ u_long current_time; /* needed by authkeys; not used */ +#else /* __rtems__ */ +extern u_long current_time; +#endif /* __rtems__ */ /* * Flag which indicates we should always send authenticated requests @@ -113,7 +133,6 @@ int rawmode = 0; */ u_char pktversion = NTP_OLDVERSION + 1; - /* * Format values */ @@ -177,8 +196,12 @@ static const char *tstflagnames[] = { "peer_unreach" /* TEST13 */ }; - +#ifdef __rtems__ +#define BUILD_AS_LIB 1 +#define progname "ntpq" +#else /* __rtems__ */ int ntpqmain (int, char **); +#endif /* __rtems__ */ /* * Built in command handler declarations */ @@ -322,7 +345,6 @@ struct xcmd builtins[] = { { "", "", "", "" }, "" } }; - /* * Default values we use. */ @@ -396,9 +418,11 @@ u_int numassoc; /* number of cached associations */ /* * For commands typed on the command line (with the -c option) */ +#ifndef __rtems__ size_t numcmds = 0; const char *ccmds[MAXCMDS]; #define ADDCMD(cp) if (numcmds < MAXCMDS) ccmds[numcmds++] = (cp) +#endif /* __rtems__ */ /* * When multiple hosts are specified. @@ -445,8 +469,10 @@ chost chosts[MAXHOSTS]; # define SETJMP(x) setjmp((x)) # define LONGJMP(x, v) longjmp((x),(v)) #endif +#ifndef __rtems__ static JMP_BUF interrupt_buf; static volatile int jump = 0; +#endif /* __rtems__*/ /* * Points at file being currently printed into @@ -458,6 +484,7 @@ FILE *current_output = NULL; */ extern struct xcmd opcmds[]; +#ifndef __rtems__ char const *progname; #ifdef NO_MAIN_ALLOWED @@ -492,7 +519,6 @@ main( } #endif - #ifndef BUILD_AS_LIB int ntpqmain( @@ -646,6 +672,7 @@ ntpqmain( return 0; } #endif /* !BUILD_AS_LIB */ +#endif /* __rtems__ */ /* * openhost - open a socket to a host @@ -913,7 +940,13 @@ getresponse( size_t ff; int seenlastfrag; int shouldbesize; +#if __rtems__ + extern fd_set* rtems_ntpq_fd_set; + extern size_t rtems_ntpq_fd_set_size; + #define fds (*rtems_ntpq_fd_set) +#else /* __rtems__ */ fd_set fds; +#endif /* __rtems__ */ int n; int errcode; /* absolute timeout checks. Not 'time_t' by intention! */ @@ -941,7 +974,11 @@ getresponse( tobase = (uint32_t)time(NULL); +#if __rtems__ + memset(&fds, 0, rtems_ntpq_fd_set_size); +#else /* __rtems__ */ FD_ZERO(&fds); +#endif /* __rtems__ */ /* * Loop until we have an error or a complete response. Nearly all @@ -1355,6 +1392,7 @@ sendrequest( * Get the keyid and the password if we don't have one. */ if (info_auth_keyid == 0) { +#ifndef __rtems__ key_id = getkeyid("Keyid: "); if (key_id == 0 || key_id > NTP_MAXKEY) { fprintf(stderr, @@ -1362,6 +1400,7 @@ sendrequest( return 1; } info_auth_keyid = key_id; +#endif /* __rtems__ */ } if (!authistrusted(info_auth_keyid)) { pass = getpass_keytype(info_auth_keytype); @@ -3825,6 +3864,7 @@ grow_assoc_cache(void) } +#ifndef __rtems__ /* * ntpq_custom_opt_handler - autoopts handler for -c and -p * @@ -4172,3 +4212,4 @@ my_easprintf( return prc; } #endif /* !defined(BUILD_AS_LIB) */ +#endif /* __rtems__ */ diff --git a/bsd/freebsd/contrib/ntp/ntpq/ntpq.h b/bsd/freebsd/contrib/ntp/ntpq/ntpq.h index 53f7638..7bf82cb 100644 --- a/bsd/freebsd/contrib/ntp/ntpq/ntpq.h +++ b/bsd/freebsd/contrib/ntp/ntpq/ntpq.h @@ -1,3 +1,5 @@ +#include + /* * ntpq.h - definitions of interest to ntpq */ @@ -157,6 +159,8 @@ extern void makeascii (size_t, const char *, FILE *); extern const char * trunc_left (const char *, size_t); extern const char * trunc_right(const char *, size_t); +#ifndef __rtems__ typedef int/*BOOL*/ (*Ctrl_C_Handler)(void); extern int/*BOOL*/ push_ctrl_c_handler(Ctrl_C_Handler); extern int/*BOOL*/ pop_ctrl_c_handler(Ctrl_C_Handler); +#endif /* __rtems__ */ diff --git a/bsd/freebsd/contrib/ntp/sntp/libopts/ag-char-map.h b/bsd/freebsd/contrib/ntp/sntp/libopts/ag-char-map.h index 325ef41..e905118 100644 --- a/bsd/freebsd/contrib/ntp/sntp/libopts/ag-char-map.h +++ b/bsd/freebsd/contrib/ntp/sntp/libopts/ag-char-map.h @@ -29,9 +29,6 @@ #ifndef AG_CHAR_MAP_H_GUARD #define AG_CHAR_MAP_H_GUARD 1 -#ifdef __rtems__ -#include -#endif #ifdef HAVE_CONFIG_H # if defined(HAVE_INTTYPES_H) # include diff --git a/bsd/rtemsbsd/include/rtems/ntpq.h b/bsd/rtemsbsd/include/rtems/ntpq.h new file mode 100644 index 0000000..28009bb --- /dev/null +++ b/bsd/rtemsbsd/include/rtems/ntpq.h @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup rtems_bsd + * + * @brief This header file defines the NTP Queue daemon interfaces. + */ + +/* + * Copyright (C) 2023 Chris Johns + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTEMS_NTPQ_H +#define _RTEMS_NTPQ_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Runs the NTP query command (nptq). + * + * @param argc is the argument count. + * + * @param argv is the vector of arguments. + * + * @return This function returns the result. + */ +int rtems_shell_ntpq_command(int argc, char **argv); + +int rtems_ntpq_create(size_t output_buf_size); +void rtems_ntpq_destroy(void); + +int rtems_ntpq_error_code(void); +const char* rtems_ntpq_error_text(void); +int rtems_ntpq_create_check(void); +const char* rtems_ntpq_output(void); +FILE* rtems_ntpq_stdout(void); +FILE* rtems_ntpq_stderr(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTEMS_NTPQ_H */ diff --git a/bsd/rtemsbsd/include/rtems/shellconfig-net-services.h b/bsd/rtemsbsd/include/rtems/shellconfig-net-services.h new file mode 100644 index 0000000..28e1d1b --- /dev/null +++ b/bsd/rtemsbsd/include/rtems/shellconfig-net-services.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup rtems_bsd + * + * @brief This header file defines the Net Services Shell commands + */ + +/* + * Copyright (C) 2023 Chris Johns + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTEMS_SHELLCONFIG_NET_SERVICES_H +#define _RTEMS_SHELLCONFIG_NET_SERVICES_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Externs for all command definition structures + */ +extern rtems_shell_cmd_t rtems_shell_NTPQ_Command; + +#ifdef __cplusplus +} +#endif + +#endif /* _RTEMS_SHELLCONFIG_NET_SERVICES_H */ diff --git a/bsd/rtemsbsd/rtems/rtems-ntpq.c b/bsd/rtemsbsd/rtems/rtems-ntpq.c new file mode 100644 index 0000000..367b743 --- /dev/null +++ b/bsd/rtemsbsd/rtems/rtems-ntpq.c @@ -0,0 +1,468 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief NTPQ command + */ + +/* + * Copyright (c) 2023 Chris Johns . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (C) 1992-2020 The University of Delaware and Network Time Foundation, + * All rights reserved. + * http://ntp.org/license + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose with or without fee is hereby granted, + * provided that the above copyright notice appears in all copies and that + * both the copyright notice and this permission notice appear in supporting + * documentation, and that the name The University of Delaware not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. The University of Delaware and Network + * Time Foundation makes no representations about the suitability this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * Large pieces of this code have been taken from tnpq and reworked to + * be something usable on RTEMS. + */ + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#define LIBNTPQ_C 1 +#include + +#include +#include + +/* + * NTPQ is sequential + */ +static rtems_recursive_mutex ntpq_lock = RTEMS_RECURSIVE_MUTEX_INITIALIZER("ntpq"); + +/* + * NTPQ is full of globals and so we protect usage with single mutex + * from the user interface. There is no easy way to make ntpq thread + * safe without a lot of changes and the BSD command support is not + * fully ported to net seervices. + */ +int rtems_ntpq_error_value; +char rtems_ntpq_error_str[128]; +fd_set* rtems_ntpq_fd_set; +size_t rtems_ntpq_fd_set_size; +FILE* rtems_ntpq_outputfp; +char* rtems_ntpq_output_buf; +size_t rtems_ntpq_output_buf_size; + +/** + * SSL support stubs + */ +const char *keytype_name(int nid) { + (void) nid; + return "MD5"; +} + +int keytype_from_text(const char *text, size_t *pdigest_len) { + (void) text; + (void) pdigest_len; + return NID_md5; +} + +char *getpass_keytype(int keytype) { + (void) keytype; + return "\0"; +} + +void rtems_ntpq_verror(int error_code, const char* format, va_list ap) { + rtems_ntpq_error_value = error_code; + strcpy(rtems_ntpq_error_str, "ntpq: "); + vsnprintf( + rtems_ntpq_error_str + 6, sizeof(rtems_ntpq_error_str) - 7, format, ap); +} + +void rtems_ntpq_error(int error_code, const char* format, ...) { + va_list ap; + va_start(ap, format); + rtems_ntpq_verror(error_code, format, ap); + va_end(ap); +} + +void rtems_ntpq_error_msg(const char* format, ...) { + va_list ap; + va_start(ap, format); + rtems_ntpq_error(-1, format, ap); + va_end(ap); +} + +/* + * Default values we use. + */ +#define DEFHOST "localhost" /* default host name */ +#define DEFTIMEOUT 5 /* wait 5 seconds for 1st pkt */ +#define DEFSTIMEOUT 3 /* and 3 more for each additional */ +/* + * Requests are automatically retried once, so total timeout with no + * response is a bit over 2 * DEFTIMEOUT, or 10 seconds. At the other + * extreme, a request eliciting 32 packets of responses each for some + * reason nearly DEFSTIMEOUT seconds after the prior in that series, + * with a single packet dropped, would take around 32 * DEFSTIMEOUT, or + * 93 seconds to fail each of two times, or 186 seconds. + * Some commands involve a series of requests, such as "peers" and + * "mrulist", so the cumulative timeouts are even longer for those. + */ +#define DEFDELAY 0x51EB852 /* 20 milliseconds, l_fp fraction */ +#define LENHOSTNAME 256 /* host name is 256 characters long */ + +extern int always_auth; +extern int ai_fam_templ; +extern int ai_fam_default; +extern int wideremote; +extern int rawmode; +extern struct servent *server_entry; +extern struct association *assoc_cache; +extern u_char pktversion; +extern SOCKET sockfd; +extern int havehost; +extern int s_port; +extern struct servent *server_entry; +extern int sequence; +extern struct sock_timeval tvout; +extern struct sock_timeval tvsout; +extern l_fp delay_time; +extern char currenthost[LENHOSTNAME]; +extern int currenthostisnum; +extern struct sockaddr_in hostaddr; +extern int showhostnames; +extern int wideremote; + +static void rtems_ntpq_init(void) { + const struct sock_timeval tvout_ = { DEFTIMEOUT, 0 }; + const struct sock_timeval tvsout_ = { DEFSTIMEOUT, 0 }; + if (sockfd > 0) { + close(sockfd); + havehost = 0; + } + sockfd = -1; + havehost = 0; + s_port = 0; + server_entry = NULL; + sequence = 0; + + old_rv = 1; + drefid = -1; + always_auth = 0; + rawmode = 0; + pktversion = NTP_OLDVERSION + 1; + tvout = tvout_; + tvsout = tvsout_; + memset(&delay_time, 0, sizeof(delay_time)); + memset(currenthost, 0, LENHOSTNAME); + currenthostisnum = 0; + memset(&hostaddr, 0, sizeof(hostaddr)); + showhostnames = 1; + wideremote = 0; + ai_fam_templ = 0; + ai_fam_default = 0; + + if (assoc_cache != NULL) { + free(assoc_cache); + } + assoc_cache = NULL; + assoc_cache_slots = 0; + numassoc = 0; + + numhosts = 0; +} + +int rtems_ntpq_create(size_t output_buf_size) { + size_t alloc_size; + size_t fd_set_break; + rtems_recursive_mutex_lock(&ntpq_lock); + if (rtems_ntpq_output_buf != NULL) { + rtems_ntpq_error(EEXIST, "already open"); + rtems_recursive_mutex_unlock(&ntpq_lock); + return -1; + } + rtems_ntpq_output_buf_size = output_buf_size; + alloc_size = output_buf_size; + if ((alloc_size & 16) != 0) { + alloc_size = ((alloc_size / 16) + 1) * 16; + } + fd_set_break = alloc_size; + alloc_size += + sizeof(fd_set) * (howmany(rtems_libio_number_iops, sizeof(fd_set) * 8)); + rtems_ntpq_output_buf = calloc(1, alloc_size); + if (rtems_ntpq_output_buf == NULL) { + rtems_ntpq_error(ENOMEM, "no memory"); + rtems_recursive_mutex_unlock(&ntpq_lock); + return -1; + } + rtems_ntpq_fd_set = (fd_set*) (rtems_ntpq_output_buf + fd_set_break); + rtems_ntpq_outputfp = fopen("/dev/null", "wb"); + if (rtems_ntpq_outputfp == NULL) { + rtems_ntpq_error(errno, "buffered file pointer"); + free(rtems_ntpq_output_buf); + rtems_ntpq_output_buf_size = 0; + rtems_ntpq_output_buf = NULL; + rtems_ntpq_fd_set = NULL; + rtems_recursive_mutex_unlock(&ntpq_lock); + return -1; + } + setbuffer( + rtems_ntpq_outputfp, &rtems_ntpq_output_buf[0], + rtems_ntpq_output_buf_size); + rtems_ntpq_init(); + rtems_recursive_mutex_unlock(&ntpq_lock); + return 0; +} + +void rtems_ntpq_destroy(void) { + rtems_recursive_mutex_lock(&ntpq_lock); + if (rtems_ntpq_output_buf != NULL) { + if (rtems_ntpq_outputfp != NULL) { + fclose(rtems_ntpq_outputfp); + } + free(rtems_ntpq_output_buf); + rtems_ntpq_output_buf_size = 0; + rtems_ntpq_output_buf = NULL; + rtems_ntpq_fd_set = NULL; + } + rtems_ntpq_init(); + rtems_recursive_mutex_unlock(&ntpq_lock); +} + +int rtems_ntpq_error_code(void) { + int v; + rtems_recursive_mutex_lock(&ntpq_lock); + v = rtems_ntpq_error_value; + rtems_recursive_mutex_unlock(&ntpq_lock); + return v; +} + +const char* rtems_ntpq_error_text(void) { + return rtems_ntpq_error_str; +} + +int rtems_ntpq_create_check(void) { + int r = 1; + rtems_recursive_mutex_lock(&ntpq_lock); + if (rtems_ntpq_outputfp == NULL) { + rtems_ntpq_error_msg("not open"); + r = 0; + } + rtems_recursive_mutex_unlock(&ntpq_lock); + return r; +} + +const char* rtems_ntpq_output(void) { + const char* o; + rtems_recursive_mutex_lock(&ntpq_lock); + o = rtems_ntpq_output_buf; + rtems_recursive_mutex_unlock(&ntpq_lock); + return o; +} + +FILE* rtems_ntpq_stdout(void) { + FILE* fp; + rtems_recursive_mutex_lock(&ntpq_lock); + fp = rtems_ntpq_outputfp; + rtems_recursive_mutex_unlock(&ntpq_lock); + return fp; +} + +static int rtems_getarg(const char *str, int code, arg_v *argp) { + extern struct association *assoc_cache; + unsigned long ul; + + switch (code & ~OPT) { + case NTP_STR: + argp->string = str; + break; + + case NTP_ADD: + if (!getnetnum(str, &argp->netnum, NULL, 0)) + return 0; + break; + + case NTP_UINT: + if ('&' == str[0]) { + if (!atouint(&str[1], &ul)) { + rtems_ntpq_error_msg( + "association index `%s' invalid/undecodable", str); + return 0; + } + if (0 == numassoc) { + dogetassoc(rtems_ntpq_outputfp); + if (0 == numassoc) { + rtems_ntpq_error_msg("no associations found, `%s' unknown", str); + return 0; + } + } + ul = min(ul, numassoc); + argp->uval = assoc_cache[ul - 1].assid; + break; + } + if (!atouint(str, &argp->uval)) { + rtems_ntpq_error_msg("illegal unsigned value %s", str); + return 0; + } + break; + + case NTP_INT: + if (!atoint(str, &argp->ival)) { + rtems_ntpq_error_msg("illegal integer value %s", str); + return 0; + } + break; + + case IP_VERSION: + if (!strcmp("-6", str)) { + argp->ival = 6; + } else if (!strcmp("-4", str)) { + argp->ival = 4; + } else { + rtems_ntpq_error_msg("version must be either 4 or 6\n"); + return 0; + } + break; + } + + return 1; +} + +int rtems_ntpq_query(const int argc, const char** argv) { + extern struct xcmd builtins[]; + extern struct xcmd opcmds[]; + struct parse pcmd; + struct xcmd* cmd; + const char* keyword; + size_t keyword_len; + int args = argc; + int arg; + rtems_recursive_mutex_lock(&ntpq_lock); + if (!rtems_ntpq_create_check()) { + rtems_recursive_mutex_unlock(&ntpq_lock); + return -1; + } + if (argc < 1) { + rtems_ntpq_error_msg("no arguments provided"); + rtems_recursive_mutex_unlock(&ntpq_lock); + return -1; + } + fflush(rtems_ntpq_outputfp); + memset(rtems_ntpq_output_buf, 0, rtems_ntpq_output_buf_size); + keyword = argv[0]; + args--; + argv++; + keyword_len = strlen(keyword); + for (cmd = builtins; cmd->keyword != NULL; ++cmd) { + if (strncmp(keyword, cmd->keyword, keyword_len) == 0) { + break; + } + } + if (cmd->keyword == NULL) { + for (cmd = opcmds; cmd->keyword != NULL; ++cmd) { + if (strncmp(keyword, cmd->keyword, keyword_len) == 0) { + break; + } + } + if (cmd->keyword == NULL) { + rtems_ntpq_error_msg("command not found: %s", keyword); + rtems_recursive_mutex_unlock(&ntpq_lock); + return -1; + } + } + pcmd.keyword = keyword; + pcmd.nargs = 0; + for (arg = 0; arg < MAXARGS && cmd->arg[arg] != NO; ++arg) { + if (arg == args) { + break; + } + if (arg > args) { + rtems_ntpq_error_msg("not enough options: %s", keyword); + rtems_recursive_mutex_unlock(&ntpq_lock); + return -1; + } + if (!rtems_getarg(argv[arg], cmd->arg[arg], &pcmd.argval[arg])) { + rtems_recursive_mutex_unlock(&ntpq_lock); + return -1; + } + ++pcmd.nargs; + } + cmd->handler(&pcmd, rtems_ntpq_outputfp); + rtems_recursive_mutex_unlock(&ntpq_lock); + return 0; +} + +int rtems_shell_ntpq_command(int argc, char **argv) { + int r; + argc--; + argv++; + if (argc < 1) { + printf("error: no host and commands\n"); + return 1; + } + if (strcmp(argv[0], "open") == 0) { + r = rtems_ntpq_create(4096); + if (r == 0) { + printf("ntpq: open"); + } + } else if (strcmp(argv[0], "close") == 0) { + rtems_ntpq_destroy(); + printf("ntpq: closed"); + r = 0; + } else { + r = rtems_ntpq_query(argc, (const char**) argv); + } + if (r == 0) { + printf(rtems_ntpq_output()); + } else { + printf(rtems_ntpq_error_text()); + } + printf("\n"); + return r; +} + +rtems_shell_cmd_t rtems_shell_NTPQ_Command = +{ + "ntpq", + "[help]", + "misc", + rtems_shell_ntpq_command, + NULL, + NULL +}; diff --git a/net/legacy/ntp/config.h b/net/legacy/ntp/config.h index 2756aea..0beba47 100644 --- a/net/legacy/ntp/config.h +++ b/net/legacy/ntp/config.h @@ -11,8 +11,6 @@ #define RTEMS_BSD_PROGRAM_NO_ASPRINTF_WRAP #define RTEMS_BSD_PROGRAM_NO_FREE_WRAP -#include - #include "namespace.h" /* Define if building universal (internal helper macro) */ diff --git a/net/libbsd/ntp/config.h b/net/libbsd/ntp/config.h index f48309f..b2ebaf9 100644 --- a/net/libbsd/ntp/config.h +++ b/net/libbsd/ntp/config.h @@ -11,8 +11,6 @@ #define RTEMS_BSD_PROGRAM_NO_ASPRINTF_WRAP #define RTEMS_BSD_PROGRAM_NO_FREE_WRAP -#include - #include "namespace.h" /* Define if building universal (internal helper macro) */ diff --git a/net/lwip/ntp/config.h b/net/lwip/ntp/config.h index 4e06452..cd510de 100644 --- a/net/lwip/ntp/config.h +++ b/net/lwip/ntp/config.h @@ -11,8 +11,6 @@ #define RTEMS_BSD_PROGRAM_NO_ASPRINTF_WRAP #define RTEMS_BSD_PROGRAM_NO_FREE_WRAP -#include - #include "namespace.h" /* Define if building universal (internal helper macro) */ diff --git a/netservices.py b/netservices.py index e9eeb0c..c9e3a4c 100644 --- a/netservices.py +++ b/netservices.py @@ -219,12 +219,14 @@ def build(bld): bld.add_group() + ntpq_defines = ['NO_MAIN_ALLOWED=1'] + bld.stlib(features='c', target='ntp', source=ntp_source_files, includes=ntp_incl + [os.path.join(net_root, 'ntp')], cflags=cflags, - defines=[net_def, 'HAVE_CONFIG_H=1'] + bld.env.NTP_DEFINES, + defines=[net_def, 'HAVE_CONFIG_H=1'] + ntpq_defines + bld.env.NTP_DEFINES, use=[net_use]) bld.install_files("${PREFIX}/" + arch_lib_path, ["libntp.a"]) @@ -266,7 +268,7 @@ def build(bld): cflags=cflags, includes=ntp_test_incl, defines=[net_def], - lib=libs, + lib=['telnetd'] + libs, use=['ntp', net_use]) ttcp_test_incl = ttcp_incl + ['testsuites'] diff --git a/ntp-file-import.json b/ntp-file-import.json index 3387837..26f805d 100644 --- a/ntp-file-import.json +++ b/ntp-file-import.json @@ -5,6 +5,7 @@ "freebsd/contrib/ntp/lib/isc/pthreads/include", "freebsd/contrib/ntp/lib/isc/unix/include", "freebsd/contrib/ntp/sntp/libopts", + "freebsd/contrib/ntp/ntpq", "rtemsbsd/include" ], "source-files-to-import" : [ @@ -30,16 +31,23 @@ "freebsd/contrib/ntp/lib/isc/unix/time.c", "freebsd/contrib/ntp/libntp/a_md5encrypt.c", "freebsd/contrib/ntp/libntp/atoint.c", + "freebsd/contrib/ntp/libntp/atouint.c", + "freebsd/contrib/ntp/libntp/atolfp.c", "freebsd/contrib/ntp/libntp/authkeys.c", "freebsd/contrib/ntp/libntp/authreadkeys.c", + "freebsd/contrib/ntp/libntp/authusekey.c", + "freebsd/contrib/ntp/libntp/caltontp.c", "freebsd/contrib/ntp/libntp/decodenetnum.c", "freebsd/contrib/ntp/libntp/dolfptoa.c", "freebsd/contrib/ntp/libntp/emalloc.c", "freebsd/contrib/ntp/libntp/findconfig.c", + "freebsd/contrib/ntp/libntp/hextoint.c", + "freebsd/contrib/ntp/libntp/hextolfp.c", "freebsd/contrib/ntp/libntp/humandate.c", "freebsd/contrib/ntp/libntp/is_ip_address.c", "freebsd/contrib/ntp/libntp/lib_strbuf.c", "freebsd/contrib/ntp/libntp/modetoa.c", + "freebsd/contrib/ntp/libntp/mstolfp.c", "freebsd/contrib/ntp/libntp/msyslog.c", "freebsd/contrib/ntp/libntp/netof.c", "freebsd/contrib/ntp/libntp/ntp_calendar.c", @@ -49,11 +57,13 @@ "freebsd/contrib/ntp/libntp/ntp_rfc2553.c", "freebsd/contrib/ntp/libntp/ntp_worker.c", "freebsd/contrib/ntp/libntp/numtoa.c", + "freebsd/contrib/ntp/libntp/octtoint.c", "freebsd/contrib/ntp/libntp/recvbuff.c", "freebsd/contrib/ntp/libntp/refidsmear.c", "freebsd/contrib/ntp/libntp/refnumtoa.c", "freebsd/contrib/ntp/libntp/socket.c", "freebsd/contrib/ntp/libntp/socktoa.c", + "freebsd/contrib/ntp/libntp/socktohost.c", "freebsd/contrib/ntp/libntp/statestr.c", "freebsd/contrib/ntp/libntp/systime.c", "freebsd/contrib/ntp/libntp/vint64ops.c", @@ -61,7 +71,6 @@ "freebsd/contrib/ntp/libntp/work_thread.c", "freebsd/contrib/ntp/libntp/xsbprintf.c", "freebsd/contrib/ntp/ntpd/cmd_args.c", - "freebsd/contrib/ntp/ntpdc/ntpdc_ops.c", "freebsd/contrib/ntp/ntpd/ntp_config.c", "freebsd/contrib/ntp/ntpd/ntp_control.c", "freebsd/contrib/ntp/ntpd/ntp_crypto.c", @@ -85,12 +94,15 @@ "freebsd/contrib/ntp/ntpd/ntp_util.c", "freebsd/contrib/ntp/ntpd/rc_cmdlength.c", "freebsd/contrib/ntp/ntpd/version.c", + "freebsd/contrib/ntp/ntpq/ntpq.c", + "freebsd/contrib/ntp/ntpq/ntpq-subs.c", "freebsd/contrib/ntp/sntp/libopts/libopts.c", "freebsd/contrib/ntp/libntp/clocktypes.c", "freebsd/contrib/ntp/lib/isc/tsmemcmp.c", "freebsd/contrib/ntp/libntp/machines.c", "freebsd/contrib/ntp/libntp/prettydate.c", "rtemsbsd/rtems/rtems-program.c", + "rtemsbsd/rtems/rtems-ntpq.c", "rtemsbsd/rtems/rtems-program-socket.c" ] } diff --git a/testsuites/ntp01/test_main.c b/testsuites/ntp01/test_main.c index 8e76b96..1d8ffb0 100644 --- a/testsuites/ntp01/test_main.c +++ b/testsuites/ntp01/test_main.c @@ -38,15 +38,36 @@ #include #include +#include + #include #include #include +#include + #include const char rtems_test_name[] = "NTP 1"; -#define NTP_DEBUG 2 +rtems_shell_env_t env; + +static void telnet_shell( char *name, void *arg ) +{ + rtems_shell_dup_current_env( &env ); + + env.devname = name; + env.taskname = "NTPD"; + + rtems_shell_main_loop( &env ); +} + +rtems_telnetd_config_table rtems_telnetd_config = { + .command = telnet_shell, + .stack_size = 8 * RTEMS_MINIMUM_STACK_SIZE, +}; + +#define NTP_DEBUG 0 #define ntp_xstr(s) ntp_str(s) #define ntp_str(s) #s #define NTP_DEBUG_STR ntp_xstr(NTP_DEBUG) @@ -335,6 +356,9 @@ static const char etc_services[] = "ntp 123/tcp # Network Time Protocol [Dave_Mills] [RFC5905]\n" "ntp 123/udp # Network Time Protocol [Dave_Mills] [RFC5905]\n"; +static bool ntp_finished; +static rtems_id ntpd_id; + static void setup_etc(void) { int rv; @@ -359,9 +383,10 @@ static void setup_etc(void) } -static void run_test(void) +static rtems_task ntpd_runner( + rtems_task_argument argument +) { - rtems_status_code sc; char *argv[] = { "ntpd", "-g", @@ -370,15 +395,49 @@ static void run_test(void) #endif NULL }; - #define argc ((sizeof(argv) / sizeof(argv[0])) - 1) + const int argc = ((sizeof(argv) / sizeof(argv[0])) - 1); + + (void)rtems_ntpd_run(argc, argv); + ntp_finished = true; +} + +static void run_test(void) +{ + rtems_status_code sc; + char *argv[] = { + "ntpq", + "127.0.0.1", + NULL + }; + const int argc = ((sizeof(argv) / sizeof(argv[0])) - 1); setup_etc(); + rtems_shell_add_cmd_struct(&rtems_shell_NTPQ_Command); + + sc = rtems_telnetd_start( &rtems_telnetd_config ); + rtems_test_assert( sc == RTEMS_SUCCESSFUL ); + sc = rtems_shell_init("SHLL", 16 * 1024, 1, CONSOLE_DEVICE_NAME, false, false, NULL); + directive_failed( sc, "rtems_shell_init" ); assert(sc == RTEMS_SUCCESSFUL); - (void)rtems_ntpd_run(argc, argv); + sc = rtems_task_create( + rtems_build_name( 'n', 't', 'p', 'd' ), + 10, + 8 * 1024, + RTEMS_TIMESLICE, + RTEMS_FLOATING_POINT, + &ntpd_id + ); + directive_failed( sc, "rtems_task_create" ); + sc = rtems_task_start( ntpd_id, ntpd_runner, 0 ); + directive_failed( sc, "rtems_task_start of TA1" ); + + while (!ntp_finished) { + sleep(2); + } } static rtems_task Init( rtems_task_argument argument ) -- cgit v1.2.3