From ca5944f3bddff420d88772e44851a665c6de1cac Mon Sep 17 00:00:00 2001 From: Jon Ludlam Date: Tue, 23 Jun 2015 11:24:28 +0100 Subject: [PATCH] Make sure we truncate the pidfile when opening This avoids writing incorrect pids Signed-off-by: Jon Ludlam --- idl/pidfile.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idl/pidfile.ml b/idl/pidfile.ml index a917ec3..c5e6712 100644 --- a/idl/pidfile.ml +++ b/idl/pidfile.ml @@ -3,7 +3,7 @@ let write_pid pidfile = let txt = string_of_int (Unix.getpid ()) in try - let fd = Unix.openfile pidfile [ Unix.O_WRONLY; Unix.O_CREAT ] 0o0644 in + let fd = Unix.openfile pidfile [ Unix.O_WRONLY; Unix.O_CREAT; Unix.O_TRUNC ] 0o0644 in Unix.lockf fd Unix.F_TLOCK (String.length txt); let (_: int) = Unix.write fd txt 0 (String.length txt) in ()