From aa09d40fdcaf9abfe750929c5fe3b19ac1cef0cb Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 21 Aug 2009 19:27:54 +0200 Subject: move most of CCrashWatcher's init/deinit into daemon's main() Signed-off-by: Denys Vlasenko --- lib/Utils/xfuncs.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'lib/Utils') diff --git a/lib/Utils/xfuncs.cpp b/lib/Utils/xfuncs.cpp index c8aee376..cc147204 100644 --- a/lib/Utils/xfuncs.cpp +++ b/lib/Utils/xfuncs.cpp @@ -252,3 +252,41 @@ std::string get_home_dir(int uid) struct passwd* pw = getpwuid(uid); return pw ? pw->pw_dir : ""; } + +// Die if we can't open a file and return a fd +int xopen3(const char *pathname, int flags, int mode) +{ + int ret; + + ret = open(pathname, flags, mode); + if (ret < 0) { + perror_msg_and_die("can't open '%s'", pathname); + } + return ret; +} + +// Die if we can't open an existing file and return a fd +int xopen(const char *pathname, int flags) +{ + return xopen3(pathname, flags, 0666); +} + +#if 0 //UNUSED +// Warn if we can't open a file and return a fd. +int open3_or_warn(const char *pathname, int flags, int mode) +{ + int ret; + + ret = open(pathname, flags, mode); + if (ret < 0) { + perror_msg("can't open '%s'", pathname); + } + return ret; +} + +// Warn if we can't open a file and return a fd. +int open_or_warn(const char *pathname, int flags) +{ + return open3_or_warn(pathname, flags, 0666); +} +#endif -- cgit