Re-do cumulus side of upload script interface.
[cumulus.git] / util.cc
diff --git a/util.cc b/util.cc
index b595eea..0aa5efb 100644 (file)
--- a/util.cc
+++ b/util.cc
@@ -23,6 +23,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
 #include <uuid/uuid.h>
 
 #include <iostream>
@@ -115,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);
+}