You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/11/15 00:53:33 UTC

svn commit: r1409573 - in /incubator/mesos/trunk/third_party/libprocess: Makefile.am include/stout/exit.hpp

Author: benh
Date: Wed Nov 14 23:53:33 2012
New Revision: 1409573

URL: http://svn.apache.org/viewvc?rev=1409573&view=rev
Log:
Added an EXIT function to stout.

From: Ben Mahler <be...@gmail.com>
Review: https://reviews.apache.org/r/7781

Added:
    incubator/mesos/trunk/third_party/libprocess/include/stout/exit.hpp
Modified:
    incubator/mesos/trunk/third_party/libprocess/Makefile.am

Modified: incubator/mesos/trunk/third_party/libprocess/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/Makefile.am?rev=1409573&r1=1409572&r2=1409573&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/Makefile.am (original)
+++ incubator/mesos/trunk/third_party/libprocess/Makefile.am Wed Nov 14 23:53:33 2012
@@ -67,6 +67,7 @@ libprocess_la_SOURCES += $(top_srcdir)/i
 	$(top_srcdir)/include/process/timer.hpp				\
 	$(top_srcdir)/include/stout/cache.hpp				\
 	$(top_srcdir)/include/stout/duration.hpp			\
+	$(top_srcdir)/include/stout/exit.hpp				\
 	$(top_srcdir)/include/stout/fatal.hpp				\
 	$(top_srcdir)/include/stout/foreach.hpp				\
 	$(top_srcdir)/include/stout/format.hpp				\

Added: incubator/mesos/trunk/third_party/libprocess/include/stout/exit.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/stout/exit.hpp?rev=1409573&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/stout/exit.hpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/include/stout/exit.hpp Wed Nov 14 23:53:33 2012
@@ -0,0 +1,35 @@
+#ifndef __STOUT_EXIT_HPP__
+#define __STOUT_EXIT_HPP__
+
+#include <stdlib.h>
+
+#include <ostream>
+#include <sstream>
+#include <string>
+
+// Exit takes an exit code and provides a stream for output prior to exiting.
+// This is like LOG(FATAL) or CHECK, except that it does _not_ print a stack
+// trace because we don't want to freak out the user.
+//
+// Ex: EXIT(1) << "Cgroups are not present in this system.";
+#define EXIT __Exit().stream
+
+struct __Exit
+{
+  ~__Exit()
+  {
+    std::cerr << out.str() << std::endl;
+    exit(exitCode);
+  }
+
+  std::ostream& stream(int exitCode)
+  {
+    this->exitCode = exitCode;
+    return out;
+  }
+
+  std::ostringstream out;
+  int exitCode;
+};
+
+#endif // __STOUT_EXIT_HPP__