summaryrefslogtreecommitdiff
path: root/src/monitor/main.cpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-02-04 23:18:54 -0800
committerBen Longbons <b.r.longbons@gmail.com>2014-02-06 11:18:37 -0800
commit9215c35975be745628e8188473154c7e476add55 (patch)
tree14d4f5d51381f8a59803233c24dfafc846ddf583 /src/monitor/main.cpp
parent9544985ccbb20d7f8377c63a4e59d1ff97b844ac (diff)
downloadtmwa-9215c35975be745628e8188473154c7e476add55.tar.gz
tmwa-9215c35975be745628e8188473154c7e476add55.tar.bz2
tmwa-9215c35975be745628e8188473154c7e476add55.tar.xz
tmwa-9215c35975be745628e8188473154c7e476add55.zip
Wrap remaining FDs in a class
Diffstat (limited to 'src/monitor/main.cpp')
-rw-r--r--src/monitor/main.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/monitor/main.cpp b/src/monitor/main.cpp
index 1bc9880..352b375 100644
--- a/src/monitor/main.cpp
+++ b/src/monitor/main.cpp
@@ -20,6 +20,7 @@
#include "../strings/xstring.hpp"
#include "../io/cxxstdio.hpp"
+#include "../io/fd.hpp"
#include "../io/read.hpp"
#include "../common/config_parse.hpp"
@@ -183,19 +184,21 @@ int main(int argc, char *argv[])
{
//make sure all possible file descriptors are free for use by the servers
//if there are file descriptors higher than the max open from before the limit dropped, that's not our problem
- int fd = sysconf(_SC_OPEN_MAX);
- while (--fd > 2)
- if (close(fd) == 0)
- FPRINTF(stderr, "close fd %d\n", fd);
- fd = open("/dev/null", O_RDWR);
- if (fd < 0)
+ io::FD fd = io::FD::sysconf_SC_OPEN_MAX();
+ while ((fd = fd.prev()) > io::FD::stderr())
+ {
+ if (fd.close() == 0)
+ FPRINTF(stderr, "close fd %d\n", fd.uncast_dammit());
+ }
+ fd = io::FD::open("/dev/null", O_RDWR);
+ if (fd == io::FD())
{
perror("open /dev/null");
exit(1);
}
- dup2(fd, 0);
- dup2(fd, 1);
- close(fd);
+ fd.dup2(io::FD::stdin());
+ fd.dup2(io::FD::stdout());
+ fd.close();
}
while (1)
{