Skip to content

Commit 864b9a1

Browse files
author
Srinivasan Muralidharan
committed
[FAB-4899] don't use syscall for writing out peer pid
Its probably OK to not have to lock the peer PID file while writing the PID to it. Using `syscall.Flock` etc to do this causes failure on Windows platforms. patch 1 . removed the file removal in case it belongs to a running server (was in two minds about it... we will overwrite but why remove unnecessarily...) Change-Id: I6347ac744eeaa8114728d5357bfaa2292525db15 Signed-off-by: Srinivasan Muralidharan <[email protected]>
1 parent cefe788 commit 864b9a1

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

peer/node/start.go

+5-25
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ package node
88

99
import (
1010
"fmt"
11+
"io/ioutil"
1112
"net"
1213
"net/http"
1314
"os"
1415
"os/signal"
1516
"path/filepath"
17+
"strconv"
1618
"syscall"
1719
"time"
1820

@@ -370,33 +372,11 @@ func writePid(fileName string, pid int) error {
370372
return err
371373
}
372374

373-
fd, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0644)
374-
if err != nil {
375-
return err
376-
}
377-
defer fd.Close()
378-
if err := syscall.Flock(int(fd.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil {
379-
return fmt.Errorf("can't lock '%s', lock is held", fd.Name())
380-
}
381-
382-
if _, err := fd.Seek(0, 0); err != nil {
383-
return err
384-
}
385-
386-
if err := fd.Truncate(0); err != nil {
375+
buf := strconv.Itoa(pid)
376+
if err = ioutil.WriteFile(fileName, []byte(buf), 0644); err != nil {
377+
logger.Errorf("Cannot write pid to %s (err:%s)", fileName, err)
387378
return err
388379
}
389380

390-
if _, err := fmt.Fprintf(fd, "%d", pid); err != nil {
391-
return err
392-
}
393-
394-
if err := fd.Sync(); err != nil {
395-
return err
396-
}
397-
398-
if err := syscall.Flock(int(fd.Fd()), syscall.LOCK_UN); err != nil {
399-
return fmt.Errorf("can't release lock '%s', lock is held", fd.Name())
400-
}
401381
return nil
402382
}

0 commit comments

Comments
 (0)