This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 7c81889dc6f9d5de9716419121605694a77de69a
Author: guanyushuai1 <[email protected]>
AuthorDate: Tue Jun 9 20:39:51 2026 +0800

    system/ntpc: support explicit server list in ntpcstart
    
    The ntpcstart command previously ignored its arguments and always
    started the daemon with the build-time or DHCP default servers. Accept
    an optional ';'-separated NTP server list argument and route it through
    ntpc_start_with_list(), so a specific server can be selected from the
    shell.
    
    Signed-off-by: guanyushuai1 <[email protected]>
    Assisted-by: Kiro:claude-opus-4
---
 system/ntpc/ntpcstart_main.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)

diff --git a/system/ntpc/ntpcstart_main.c b/system/ntpc/ntpcstart_main.c
index 475ce5f89..5590f5bc9 100644
--- a/system/ntpc/ntpcstart_main.c
+++ b/system/ntpc/ntpcstart_main.c
@@ -31,6 +31,27 @@
 
 #include "netutils/ntpclient.h"
 
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: ntpc_usage
+ ****************************************************************************/
+
+static void ntpc_usage(FAR const char *progname)
+{
+  fprintf(stderr, "Usage: %s [<server>[;<server>...]]\n", progname);
+  fprintf(stderr,
+          "  Start the NTP daemon.\n"
+          "  Without arguments, servers are taken from DHCP or the\n"
+          "  build-time configuration.\n"
+          "  With an argument, a ';'-separated list of NTP server\n"
+          "  hostnames or IP addresses can be specified, e.g.:\n"
+          "    %s \"pool.ntp.org;time.google.com\"\n",
+          progname);
+}
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -43,10 +64,29 @@ int main(int argc, FAR char *argv[])
 {
   int pid;
 
+  if (argc > 2)
+    {
+      ntpc_usage(argv[0]);
+      return EXIT_FAILURE;
+    }
+
   printf("Starting NTP client...\n");
-  printf("Using NTP servers: %s\n", CONFIG_NETUTILS_NTPCLIENT_SERVER);
 
-  pid = ntpc_start();
+  if (argc == 2)
+    {
+      /* A specific NTP server (list) was provided on the command line. */
+
+      printf("Using NTP servers: %s\n", argv[1]);
+      pid = ntpc_start_with_list(argv[1]);
+    }
+  else
+    {
+      /* Use the default servers from DHCP or the build-time config. */
+
+      printf("Using NTP servers: %s\n", CONFIG_NETUTILS_NTPCLIENT_SERVER);
+      pid = ntpc_start();
+    }
+
   if (pid < 0)
     {
       fprintf(stderr, "ERROR: ntpc_start() failed\n");

Reply via email to