aboutsummaryrefslogtreecommitdiffstats
path: root/util-src/pposix.c
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-07-12 20:42:22 +0200
committerKim Alvefur <zash@zash.se>2018-07-12 20:42:22 +0200
commit922039c0d6cbdf9ea1f5be4878c857f99cb65a2f (patch)
tree54f82cc1091887bf5d6aa3fc4a5163c2fb44edd5 /util-src/pposix.c
parent8c2964e6a982eef1d18c61b73f83c463014b2ef8 (diff)
downloadprosody-922039c0d6cbdf9ea1f5be4878c857f99cb65a2f.tar.gz
prosody-922039c0d6cbdf9ea1f5be4878c857f99cb65a2f.zip
util.pposix: Use freopen(3) when replacing standard IO streams (thanks ratchetfreak)
Man page says this is what freopen(3) is for.
Diffstat (limited to 'util-src/pposix.c')
-rw-r--r--util-src/pposix.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/util-src/pposix.c b/util-src/pposix.c
index e70a9d7f..215c45c3 100644
--- a/util-src/pposix.c
+++ b/util-src/pposix.c
@@ -104,14 +104,10 @@ static int lc_daemonize(lua_State *L) {
return 2;
}
- /* Close stdin, stdout, stderr */
- close(0);
- close(1);
- close(2);
/* Make sure accidental use of FDs 0, 1, 2 don't cause weirdness */
- open("/dev/null", O_RDONLY);
- open("/dev/null", O_WRONLY);
- open("/dev/null", O_WRONLY);
+ stdin = freopen("/dev/null", "r", stdin);
+ stdout = freopen("/dev/null", "w", stdout);
+ stderr = freopen("/dev/null", "w", stderr);
/* Final fork, use it wisely */
if(fork()) {