X-Git-Url: http://git.vrable.net/?p=cumulus.git;a=blobdiff_plain;f=util.cc;h=a7479fcf3a754428edf39f56f7eebd34838aa0b7;hp=22aab3b61dc02923f33eb9748cae6034cff181f7;hb=f546e4df51cde51dd984e4ad26e70dd7533f9791;hpb=0dfc70e01ddb7d2bce0db03d5364c0bd3a2bb308 diff --git a/util.cc b/util.cc index 22aab3b..a7479fc 100644 --- a/util.cc +++ b/util.cc @@ -1,7 +1,6 @@ -/* Cumulus: Smart Filesystem Backup to Dumb Servers - * - * Copyright (C) 2007 The Regents of the University of California - * Written by Michael Vrable +/* Cumulus: Efficient Filesystem Backup to the Cloud + * Copyright (C) 2007-2008 The Cumulus Developers + * See the AUTHORS file for a list of contributors. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,6 +21,9 @@ * later, for parsing them back, perhaps). */ #include +#include +#include +#include #include #include @@ -114,3 +116,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); +}