[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen staging-4.10] tools/ocaml: Dup2 /dev/null to stdin in daemonize()



commit 5cfbc0ffd563a2ee3abfcce74eb3c20d82a7a035
Author:     Christian Lindig <christian.lindig@xxxxxxxxxx>
AuthorDate: Wed Feb 27 10:33:42 2019 +0000
Commit:     Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
CommitDate: Thu May 16 17:00:15 2019 +0100

    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@xxxxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
    Release-acked-by: Juergen Gross <jgross@xxxxxxxx>
    (cherry picked from commit 677e64dbe315343620c3b266e9eb16623b118038)
    (cherry picked from commit 4b72470175a592fb5c0a5d10ed505de73778e10f)
---
 tools/ocaml/xenstored/stdext.ml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/ocaml/xenstored/stdext.ml b/tools/ocaml/xenstored/stdext.ml
index b8a8fd00e1..95ceff2f72 100644
--- a/tools/ocaml/xenstored/stdext.ml
+++ b/tools/ocaml/xenstored/stdext.ml
@@ -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
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.10

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.