X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=util.cc;h=0aa5efbb8eb521e14f935bc286de8c081067a62c;hb=fc223ec17dc5e6691291a7b31f6daa8679b484cd;hp=22aab3b61dc02923f33eb9748cae6034cff181f7;hpb=0dfc70e01ddb7d2bce0db03d5364c0bd3a2bb308;p=cumulus.git diff --git a/util.cc b/util.cc index 22aab3b..0aa5efb 100644 --- a/util.cc +++ b/util.cc @@ -22,6 +22,9 @@ * later, for parsing them back, perhaps). */ #include +#include +#include +#include #include #include @@ -114,3 +117,21 @@ long long parse_int(const string &s) { return strtoll(s.c_str(), NULL, 0); } + +/* Mark a file descriptor as close-on-exec. */ +void cloexec(int fd) +{ + long flags = fcntl(fd, F_GETFD); + + if (flags < 0) + return; + + fcntl(fd, F_SETFD, flags | FD_CLOEXEC); +} + +/* Report a fatal error and exit. */ +void fatal(string msg) +{ + fprintf(stderr, "FATAL: %s\n", msg.c_str()); + exit(1); +}