From 28302ae7d74db81f65995389e7acbac754b2a438 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Mon, 24 Mar 2025 16:10:35 +0800 Subject: [PATCH] system/ptpd: using main task to replace new task new starting command: ptpd start interface & we should run it in background ways Signed-off-by: dongjiuzhu1 --- netutils/ptpd/ptpd.c | 73 +++++++++++------------------------------ system/ptpd/ptpd_main.c | 17 ++++------ 2 files changed, 26 insertions(+), 64 deletions(-) diff --git a/netutils/ptpd/ptpd.c b/netutils/ptpd/ptpd.c index bdfae08a0..411c9f4eb 100644 --- a/netutils/ptpd/ptpd.c +++ b/netutils/ptpd/ptpd.c @@ -1376,11 +1376,27 @@ static void ptp_process_statusreq(FAR struct ptp_state_s *state) state->status_req.dest = NULL; } -/* Main PTPD task */ +/**************************************************************************** + * Public Functions + ****************************************************************************/ -static int ptp_daemon(int argc, FAR char** argv) +/**************************************************************************** + * Name: ptpd_start + * + * Description: + * Start the PTP daemon and bind it to specified interface. + * + * Input Parameters: + * interface - Name of the network interface to bind to, e.g. "eth0" + * + * Returned Value: + * On success, the non-negative task ID of the PTP daemon is returned; + * On failure, a negated errno value is returned. + * + ****************************************************************************/ + +int ptpd_start(FAR const char *interface) { - FAR const char *interface = "eth0"; FAR struct ptp_state_s *state; struct pollfd pollfds[2]; struct msghdr rxhdr; @@ -1392,11 +1408,6 @@ static int ptp_daemon(int argc, FAR char** argv) state = calloc(1, sizeof(struct ptp_state_s)); - if (argc > 1) - { - interface = argv[1]; - } - if (ptp_initialize_state(state, interface) != OK) { ptperr("Failed to initialize PTP state, exiting\n"); @@ -1477,52 +1488,6 @@ static int ptp_daemon(int argc, FAR char** argv) return 0; } -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: ptpd_start - * - * Description: - * Start the PTP daemon and bind it to specified interface. - * - * Input Parameters: - * interface - Name of the network interface to bind to, e.g. "eth0" - * - * Returned Value: - * On success, the non-negative task ID of the PTP daemon is returned; - * On failure, a negated errno value is returned. - * - ****************************************************************************/ - -int ptpd_start(FAR const char *interface) -{ - int pid; - FAR char *task_argv[] = - { - (FAR char *)interface, - NULL - }; - - pid = task_create("PTPD", CONFIG_NETUTILS_PTPD_SERVERPRIO, - CONFIG_NETUTILS_PTPD_STACKSIZE, ptp_daemon, task_argv); - - /* Use kill with signal 0 to check if the process is still alive - * after initialization. - */ - - usleep(USEC_PER_TICK); - if (kill(pid, 0) != OK) - { - return ERROR; - } - else - { - return pid; - } -} - /**************************************************************************** * Name: ptpd_status * diff --git a/system/ptpd/ptpd_main.c b/system/ptpd/ptpd_main.c index 503300bce..36b8b67c6 100644 --- a/system/ptpd/ptpd_main.c +++ b/system/ptpd/ptpd_main.c @@ -37,17 +37,14 @@ static int do_ptpd_start(FAR const char *interface) { - int pid; + int ret; - pid = ptpd_start(interface); - if (pid < 0) - { - fprintf(stderr, "ERROR: ptpd_start() failed\n"); - return EXIT_FAILURE; - } + ret = ptpd_start(interface); - printf("Started the PTP daemon as PID=%d\n", pid); - return EXIT_SUCCESS; + /* Should never happen */ + + fprintf(stderr, "ERROR: ptpd_start() failed:%d\n", ret); + return EXIT_FAILURE; } static int do_ptpd_status(int pid) @@ -168,7 +165,7 @@ int main(int argc, FAR char *argv[]) else { fprintf(stderr, "Usage: \n" - "ptpd start \n" + "ptpd start &\n" "ptpd status \n" "ptpd stop \n"); return EXIT_FAILURE;