wenquan2015 opened a new pull request, #3789:
URL: https://github.com/apache/nuttx-apps/pull/3789
## Summary
Replace the `sigqueue` + shared-memory IPC mechanism in
`ptpd_status()` with a file-based approach that works across **all**
NuttX build modes (Flat, Protected, Kernel).
The old implementation passed a pointer to caller-owned memory via
`sigqueue(SIGUSR1, sival_ptr)`, which only works in `CONFIG_BUILD_FLAT`
and returned `-ENOTSUP` for Protected/Kernel builds. The new approach:
- **Daemon side**: on `SIGUSR1`, writes the `ptpd_status_s` struct to
a temp file and atomically renames it to the status path. The
`dump` flag is a simple `bool` checked in the main loop.
- **Client side** (`ptpd_status()`): deletes any stale status file,
sends `kill(pid, SIGUSR1)`, polls for the file to appear (up to 3s),
reads the struct back.
The atomic temp + rename pattern ensures readers never see a partial
write. The status file path is configurable via a new Kconfig option
`NETUTILS_PTPD_STATUSFILE` (default `/tmp/ptpd.status`).
- Rewrite `ptpd_status()` — remove `#ifdef CONFIG_BUILD_FLAT` guard
- Add `NETUTILS_PTPD_STATUSFILE` string config to Kconfig
- Add `#include <sys/stat.h>` for `O_CREAT` mode bits
## Impact
- `ptpd_status()` now works in Protected and Kernel builds (previously
returned `-ENOTSUP`).
- The status file (`/tmp/ptpd.status`) is created on demand when
`SIGUSR1` is received; it does not exist unless status is queried.
- No API signature changes — callers of `ptpd_status(int pid,
struct ptpd_status_s *)` are unaffected.
- New Kconfig: `NETUTILS_PTPD_STATUSFILE` (string, default
`/tmp/ptpd.status`).
## Testing
Build: `sim:tcpblaster` with `CONFIG_NET_IGMP=y`,
`CONFIG_NETUTILS_PTPD=y`, `CONFIG_PTP_CLOCK=y`,
`CONFIG_CLOCK_ADJTIME=y` added.
Host: Linux x86_64, GCC.
Runtime verification on NuttX sim — status query via file IPC:
nsh> ifup eth0
ifup eth0...OK
nsh> ptpd -S -i eth0 &
ptpd [10:100]
nsh> ptpd -t 10
PTPD (PID 10) status:
- clock_source_valid: 0
- last_clock_update: 1970-01-01T00:00:00.000000000
- last_delta_ns: 0
- last_adjtime_ns: 0
- drift_ppb: 0
- path_delay_ns: 0
- last_received_multicast: 11 s ago
- last_received_announce: 94 s ago
- last_received_sync: 94 s ago
- last_transmitted_sync: 0 s ago
- last_transmitted_announce: 94 s ago
- last_transmitted_delayresp: 94 s ago
- last_transmitted_delayreq: 94 s ago
nsh> ptpd -d 10
Stopped ptpd
`ptpd -t 10` successfully retrieves daemon status through the new
SIGUSR1 → status-file → read-back path. The daemon writes
`/tmp/ptpd.status` atomically; the client detects it within one poll
cycle (~100ms).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]