passt: Truncate PID file on open()

Otherwise, if the current PID has fewer digits than a previously
written one, the content will be wrong.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2022-07-22 19:30:10 +02:00
parent e07670c15b
commit 3ec02c0975

View file

@ -390,7 +390,7 @@ int main(int argc, char **argv)
if (*c.pid_file) { if (*c.pid_file) {
if ((pidfile_fd = open(c.pid_file, if ((pidfile_fd = open(c.pid_file,
O_CREAT | O_WRONLY | O_CLOEXEC, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
S_IRUSR | S_IWUSR)) < 0) { S_IRUSR | S_IWUSR)) < 0) {
perror("PID file open"); perror("PID file open");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);