You are viewing a plain text version of this content. The canonical link for it is here.
Posted to builds@kvrocks.apache.org by GitBox <gi...@apache.org> on 2026/09/03 05:53:38 UTC
[GH] (kvrocks/unstable): Workflow run "SonarCloud Analysis" is working again!
The GitHub Actions job "SonarCloud Analysis" on kvrocks.git/unstable has succeeded.
Run started by GitHub user git-hulk (triggered by git-hulk).
Head commit for run:
7cf8e642274ad47a606859f4e3d940ffa1532c76 / weimeng <we...@163.com>
fix(server): add O_TRUNC when creating PID file to avoid stale content (#3598)
What problem does this change solve?
CreatePidFile opens the PID file with O_RDWR | O_CREAT but without
O_TRUNC. If a stale PID file already exists from a previous run and the
old PID string is longer than the new one, open() + write() will only
overwrite the first N bytes of the file, leaving the trailing bytes from
the old content intact. This results in a corrupted PID file.
Example:
Step File content Note
Previous run (PID=12345) 12345 correct
New run (PID=678), without O_TRUNC 67845 corrupted — trailing 45 is
stale
New run (PID=678), with O_TRUNC 678 correct
A corrupted PID file can cause process management tools (e.g., kill
$(cat pidfile), systemd, init scripts) to target the wrong process or
fail to stop/restart the service.
How does this change fix the problem?
Add O_TRUNC to the open() flags in CreatePidFile so the file is
truncated to zero length before writing the new PID, ensuring no stale
bytes remain.
Changes
- src/cli/pid_util.h: Add O_TRUNC flag to the open() call in
CreatePidFile.
- tests/cppunit/pid_util_test.cc: Add unit tests covering:
- - Truncation on existing file: Write a longer fake PID first, then
call CreatePidFile and verify the content matches exactly the current
PID with no leftover bytes.
- - Creation from scratch: Verify CreatePidFile works correctly when no
file exists.
- - RemovePidFile: Verify the PID file is properly removed.
---------
Co-authored-by: weimeng <we...@didiglobal.com>
Co-authored-by: Twice <tw...@gmail.com>
Co-authored-by: hulk <hu...@gmail.com>
Report URL: https://github.com/apache/kvrocks/actions/runs/33720558703
With regards,
GitHub Actions via GitBox