tools/ocaml: Dup2 /dev/null to stdin in daemonize()

Don't close stdin in daemonize() but dup2 /dev/null instead.  Otherwise, fd 0
gets reused later:

  [root@idol ~]# ls -lav /proc/`pgrep xenstored`/fd
  total 0
  dr-x------ 2 root root  0 Feb 28 11:02 .
  dr-xr-xr-x 9 root root  0 Feb 27 15:59 ..
  lrwx------ 1 root root 64 Feb 28 11:02 0 -> /dev/xen/evtchn
  l-wx------ 1 root root 64 Feb 28 11:02 1 -> /dev/null
  l-wx------ 1 root root 64 Feb 28 11:02 2 -> /dev/null
  lrwx------ 1 root root 64 Feb 28 11:02 3 -> /dev/xen/privcmd
  ...

Signed-off-by: Christian Lindig <christian.lindig@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
(cherry picked from commit 677e64dbe3)
(cherry picked from commit 4b72470175)
(cherry picked from commit 5cfbc0ffd5)
(cherry picked from commit 3db28b0bab)
(cherry picked from commit d929136ca8)
This commit is contained in:
Christian Lindig authored and Ian Jackson committed 2019-05-16 17:01:20 +01:00
1 parent 50bdecaf01
commit 206d3f65f7
1 file changed
+2 -2
+2 -2
View File
@@ -100,9 +100,9 @@ let daemonize () =
begin match Unix.fork () with
| 0 ->
let nullfd = Unix.openfile "/dev/null" [ Unix.O_WRONLY ] 0 in
let nullfd = Unix.openfile "/dev/null" [ Unix.O_RDWR ] 0 in
begin try
Unix.close Unix.stdin;
Unix.dup2 nullfd Unix.stdin;
Unix.dup2 nullfd Unix.stdout;
Unix.dup2 nullfd Unix.stderr;
with exn -> Unix.close nullfd; raise exn
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.