Skip to content

Commit be2b74c

Browse files
committed
Merge pull request #120 from johnelse/daemonize-fix-race
CA-208547: Avoid races in pointing stdin/stdout/stderr at /dev/null
2 parents e977fa9 + 9f10c2d commit be2b74c

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ install: wget https://raw.githubusercontent.com/ocaml/ocaml-travisci-skeleton/ma
33
script: bash -ex .travis-opam.sh
44
sudo: true
55
env:
6-
- OCAML_VERSION=4.02 PACKAGE=xapi-idl FORK_USER=xapi-project EXTRA_REMOTES=git://github.com/xapi-project/opam-repo-dev
6+
- OCAML_VERSION=4.02 PACKAGE=xapi-idl EXTRA_REMOTES=git://github.com/xapi-project/opam-repo-dev

lib/xcp_service.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,13 +554,11 @@ let daemonize ?start_fn () =
554554
Unix.chdir "/";
555555
mkdir_rec (Filename.dirname !pidfile) 0o755;
556556
pidfile_write !pidfile;
557-
Unix.close Unix.stdin;
558-
Unix.close Unix.stdout;
559-
Unix.close Unix.stderr;
560557
let nullfd = Unix.openfile "/dev/null" [ Unix.O_RDWR ] 0 in
561-
assert (nullfd = Unix.stdin);
562-
let (_:Unix.file_descr) = Unix.dup nullfd in ();
563-
let (_:Unix.file_descr) = Unix.dup nullfd in ();
558+
Unix.dup2 nullfd Unix.stdin;
559+
Unix.dup2 nullfd Unix.stdout;
560+
Unix.dup2 nullfd Unix.stderr;
561+
Unix.close nullfd
564562
| _ -> exit 0)
565563
| _ -> exit 0
566564

opam

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
opam-version: "1"
1+
opam-version: "1.2"
2+
authors: "Dave Scott"
3+
homepage: "https://github.com/xapi-project/xcp-idl"
4+
bug-reports: "https://github.com/xapi-project/xcp-idl/issues"
5+
dev-repo: "git://github.com/xapi-project/xcp-idl"
26
maintainer: "dave.scott@eu.citrix.com"
37
build: [
48
[make "all"]
5-
[make "install"]
69
]
710
build-test: [
811
[make "test"]
912
]
13+
install: [
14+
[make "install"]
15+
]
1016
remove: [
1117
["ocamlfind" "remove" "xcp"]
1218
]

0 commit comments

Comments
 (0)