public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] passt: Truncate PID file on open()
@ 2022-07-22 17:42 Stefano Brivio
  2022-07-23  2:27 ` David Gibson
  0 siblings, 1 reply; 2+ messages in thread
From: Stefano Brivio @ 2022-07-22 17:42 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 631 bytes --]

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

Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
 passt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/passt.c b/passt.c
index a8d94b4..01eed1b 100644
--- a/passt.c
+++ b/passt.c
@@ -390,7 +390,7 @@ int main(int argc, char **argv)
 
 	if (*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) {
 			perror("PID file open");
 			exit(EXIT_FAILURE);
-- 
@@ -390,7 +390,7 @@ int main(int argc, char **argv)
 
 	if (*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) {
 			perror("PID file open");
 			exit(EXIT_FAILURE);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-23  2:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-22 17:42 [PATCH] passt: Truncate PID file on open() Stefano Brivio
2022-07-23  2:27 ` David Gibson

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).