tools/ocaml: Dup2 /dev/null to stdin in daemonize()
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.
--- tools/ocaml/xenstored/stdext.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/ocaml/xenstored/stdext.ml +2 -2
@@ -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
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 4 lines · Christian Lindig
Don't close stdin in
daemonize()but dup2/dev/nullinstead. This avoids fd 0 being reused and potentially written to.Signed-off-by Christian Lindig <[email protected]>
Possibly worth noting that this fixes a bug whereby /dev/xen/evtchn reliably gets opened on fd 0.
I can fix the wording up on commit if there are no other concerns.
Juergen for 4.12
Quoted 10 lines
--- tools/ocaml/xenstored/stdext.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/ocaml/xenstored/stdext.ml +0
-0@@ -100,9 +100,9 @@ let daemonize () =
tools/ocaml/xenstored/stdext.ml let daemonize () = · line 108
Quoted 10 lines
tools/ocaml/xenstored/stdext.ml +2
-2begin 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
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Andrew Cooper
Quoted 4 lines · Christian Lindig
Don't close stdin in
daemonize()but dup2/dev/nullinstead. This avoids fd 0 being reused and potentially written to.Signed-off-by Christian Lindig <[email protected]>
Quoted 7 lines
Possibly worth noting that this fixes a bug whereby
/dev/xen/evtchnreliably gets opened on fd 0.I can fix the wording up on commit if there are no other concerns.
Reviewed-by Andrew Cooper <[email protected]>, and CC'ingJuergen for 4.12
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 4 lines · Christian Lindig
Don't close stdin in
daemonize()but dup2/dev/nullinstead. This avoids fd 0 being reused and potentially written to.Signed-off-by Christian Lindig <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel