Software /
code /
prosody
Comparison
util-src/pposix.c @ 9028:d4c2a3060e7e
util.pposix: Use freopen(3) when replacing standard IO streams (thanks ratchetfreak)
Man page says this is what freopen(3) is for.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 12 Jul 2018 20:42:22 +0200 |
parent | 8012:e898c8fda986 |
child | 9150:c1d5f52274cf |
comparison
equal
deleted
inserted
replaced
9027:4028eb4a9f7f | 9028:d4c2a3060e7e |
---|---|
102 lua_pushboolean(L, 0); | 102 lua_pushboolean(L, 0); |
103 lua_pushstring(L, "setsid-failed"); | 103 lua_pushstring(L, "setsid-failed"); |
104 return 2; | 104 return 2; |
105 } | 105 } |
106 | 106 |
107 /* Close stdin, stdout, stderr */ | |
108 close(0); | |
109 close(1); | |
110 close(2); | |
111 /* Make sure accidental use of FDs 0, 1, 2 don't cause weirdness */ | 107 /* Make sure accidental use of FDs 0, 1, 2 don't cause weirdness */ |
112 open("/dev/null", O_RDONLY); | 108 stdin = freopen("/dev/null", "r", stdin); |
113 open("/dev/null", O_WRONLY); | 109 stdout = freopen("/dev/null", "w", stdout); |
114 open("/dev/null", O_WRONLY); | 110 stderr = freopen("/dev/null", "w", stderr); |
115 | 111 |
116 /* Final fork, use it wisely */ | 112 /* Final fork, use it wisely */ |
117 if(fork()) { | 113 if(fork()) { |
118 exit(0); | 114 exit(0); |
119 } | 115 } |