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

[Xen-devel] [PATCH 1/1] tools/ocaml: Dup2 /dev/null to stdin in daemonize()



Don't close stdin in daemonize() but dup2 /dev/null instead. This avoids
fd 0 being reused and potentially written to.

Signed-off-by: Christian Lindig <christian.lindig@xxxxxxxxxx>
---
 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 879565c515..ffb516a0d4 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
-- 
2.20.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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