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 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2025-03-24 16:10:35 +08:00 committed by Alan C. Assis
parent d1f59bef8e
commit 28302ae7d7
2 changed files with 26 additions and 64 deletions

View file

@ -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
*

View file

@ -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 <interface>\n"
"ptpd start <interface> &\n"
"ptpd status <pid>\n"
"ptpd stop <pid>\n");
return EXIT_FAILURE;