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/09/19 02:08:14 UTC

svn commit: r1387409 - in /incubator/mesos/trunk: src/linux/ src/log/ src/logging/ src/slave/ src/tests/ src/webui/ third_party/libprocess/include/stout/ third_party/libprocess/src/

Author: benh
Date: Wed Sep 19 00:08:13 2012
New Revision: 1387409

URL: http://svn.apache.org/viewvc?rev=1387409&view=rev
Log:
Refactored unnecessary 'Try<bool>' into 'Try<Nothing>' (contributed by
Ben Mahler, https://reviews.apache.org/r/7001).

Modified:
    incubator/mesos/trunk/src/linux/cgroups.cpp
    incubator/mesos/trunk/src/linux/cgroups.hpp
    incubator/mesos/trunk/src/linux/fs.cpp
    incubator/mesos/trunk/src/linux/fs.hpp
    incubator/mesos/trunk/src/log/replica.cpp
    incubator/mesos/trunk/src/logging/logging.cpp
    incubator/mesos/trunk/src/slave/cgroups_isolation_module.cpp
    incubator/mesos/trunk/src/slave/cgroups_isolation_module.hpp
    incubator/mesos/trunk/src/slave/gc.cpp
    incubator/mesos/trunk/src/slave/gc.hpp
    incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp
    incubator/mesos/trunk/src/slave/slave.cpp
    incubator/mesos/trunk/src/tests/cgroups_tests.cpp
    incubator/mesos/trunk/src/tests/configurator_tests.cpp
    incubator/mesos/trunk/src/tests/files_tests.cpp
    incubator/mesos/trunk/src/tests/stout_tests.cpp
    incubator/mesos/trunk/src/tests/zookeeper_server.hpp
    incubator/mesos/trunk/src/webui/webui.cpp
    incubator/mesos/trunk/third_party/libprocess/include/stout/os.hpp
    incubator/mesos/trunk/third_party/libprocess/include/stout/try.hpp
    incubator/mesos/trunk/third_party/libprocess/src/process.cpp

Modified: incubator/mesos/trunk/src/linux/cgroups.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/linux/cgroups.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/linux/cgroups.cpp (original)
+++ incubator/mesos/trunk/src/linux/cgroups.cpp Wed Sep 19 00:08:13 2012
@@ -56,6 +56,7 @@ namespace cgroups {
 namespace internal {
 
 
+// TODO(bmahler): Change all unnecessary Future<bool>'s to Future<Nothing>'s.
 // Snapshot a subsystem (modeled after a line in /proc/cgroups).
 struct SubsystemInfo
 {
@@ -150,21 +151,12 @@ static Try<std::map<std::string, Subsyst
 // are enabled in the current platform.
 // @param   hierarchy   Path to the hierarchy root.
 // @param   subsystems  Comma-separated subsystem names.
-// @return  True if the operation succeeds.
+// @return  Some if the operation succeeds.
 //          Error if the operation fails.
-static Try<bool> mount(const std::string& hierarchy,
-                       const std::string& subsystems)
+static Try<Nothing> mount(const std::string& hierarchy,
+                          const std::string& subsystems)
 {
-  Try<bool> result = fs::mount(subsystems,
-                               hierarchy,
-                               "cgroup",
-                               0,
-                               subsystems.c_str());
-  if (result.isError()) {
-    return Try<bool>::error(result.error());
-  }
-
-  return true;
+  return fs::mount(subsystems, hierarchy, "cgroup", 0, subsystems.c_str());
 }
 
 
@@ -173,16 +165,11 @@ static Try<bool> mount(const std::string
 // assumes the given hierarchy is currently mounted with a cgroups virtual file
 // system.
 // @param   hierarchy   Path to the hierarchy root.
-// @return  True if the operation succeeds.
+// @return  Some if the operation succeeds.
 //          Error if the operation fails.
-static Try<bool> unmount(const std::string& hierarchy)
+static Try<Nothing> unmount(const std::string& hierarchy)
 {
-  Try<bool> result = fs::unmount(hierarchy);
-  if (result.isError()) {
-    return Try<bool>::error(result.error());
-  }
-
-  return true;
+  return fs::unmount(hierarchy);
 }
 
 
@@ -195,18 +182,20 @@ static Try<bool> unmount(const std::stri
 // any of the parent cgroups does not exist.
 // @param   hierarchy   Path to the hierarchy root.
 // @param   cgroup      Path to the cgroup relative to the hierarchy root.
-// @return  True if the operation succeeds.
+// @return  Some if the operation succeeds.
 //          Error if the operation fails.
-static Try<bool> createCgroup(const std::string& hierarchy,
-                              const std::string& cgroup)
+static Try<Nothing> createCgroup(const std::string& hierarchy,
+                                 const std::string& cgroup)
 {
   std::string path = hierarchy + "/" + cgroup;
-  if (::mkdir(path.c_str(), 0755) < 0) {
-    return Try<bool>::error(
-        "Failed to create cgroup at " + path + ": " + strerror(errno));
+  Try<Nothing> mkdir = os::mkdir(path);
+
+  if (mkdir.isError()) {
+    return Try<Nothing>::error(
+        "Failed to create cgroup at " + path + ": " + mkdir.error());
   }
 
-  return true;
+  return mkdir;
 }
 
 
@@ -218,18 +207,20 @@ static Try<bool> createCgroup(const std:
 // either processes or sub-cgroups inside.
 // @param   hierarchy   Path to the hierarchy root.
 // @param   cgroup      Path to the cgroup relative to the hierarchy root.
-// @return  True if the operation succeeds.
+// @return  Some if the operation succeeds.
 //          Error if the operation fails.
-static Try<bool> removeCgroup(const std::string& hierarchy,
-                              const std::string& cgroup)
+static Try<Nothing> removeCgroup(const std::string& hierarchy,
+                                 const std::string& cgroup)
 {
   std::string path = hierarchy + "/" + cgroup;
-  if (::rmdir(path.c_str()) < 0) {
-    return Try<bool>::error(
-        "Failed to remove cgroup at " + path + ": " + strerror(errno));
+  Try<Nothing> rmdir = os::rmdir(path);
+
+  if (rmdir.isError()) {
+    return Try<Nothing>::error(
+        "Failed to remove cgroup at " + path + ": " + rmdir.error());
   }
 
-  return true;
+  return rmdir;
 }
 
 
@@ -275,18 +266,18 @@ static Try<std::string> readControl(cons
 // @param   cgroup      Path to the cgroup relative to the hierarchy root.
 // @param   control     Name of the control file.
 // @param   value       Value to be written.
-// @return  True if the operation succeeds.
+// @return  Some if the operation succeeds.
 //          Error if the operation fails.
-static Try<bool> writeControl(const std::string& hierarchy,
-                              const std::string& cgroup,
-                              const std::string& control,
-                              const std::string& value)
+static Try<Nothing> writeControl(const std::string& hierarchy,
+                                 const std::string& cgroup,
+                                 const std::string& control,
+                                 const std::string& value)
 {
   std::string path = hierarchy + "/" + cgroup + "/" + control;
   std::ofstream file(path.c_str());
 
   if (!file.is_open()) {
-    return Try<bool>::error("Failed to open file " + path);
+    return Try<Nothing>::error("Failed to open file " + path);
   }
 
   file << value << std::endl;
@@ -295,11 +286,11 @@ static Try<bool> writeControl(const std:
     // TODO(jieyu): Make sure that the way we get errno here is portable.
     std::string msg = strerror(errno);
     file.close();
-    return Try<bool>::error(msg);
+    return Try<Nothing>::error(msg);
   }
 
   file.close();
-  return true;
+  return Nothing();
 }
 
 } // namespace internal {
@@ -448,152 +439,156 @@ Try<std::set<std::string> > subsystems(c
 }
 
 
-Try<bool> createHierarchy(const std::string& hierarchy,
-                          const std::string& subsystems)
+Try<Nothing> createHierarchy(const std::string& hierarchy,
+                             const std::string& subsystems)
 {
   if (os::exists(hierarchy)) {
-    return Try<bool>::error(
+    return Try<Nothing>::error(
         hierarchy + " already exists in the file system");
   }
 
   // Make sure all subsystems are enabled.
   Try<bool> enabledResult = enabled(subsystems);
   if (enabledResult.isError()) {
-    return Try<bool>::error(enabledResult.error());
+    return Try<Nothing>::error(enabledResult.error());
   } else if (!enabledResult.get()) {
-    return Try<bool>::error("Some subsystems are not enabled");
+    return Try<Nothing>::error("Some subsystems are not enabled");
   }
 
   // Make sure none of the subsystems are busy.
   Try<bool> busyResult = busy(subsystems);
   if (busyResult.isError()) {
-    return Try<bool>::error(busyResult.error());
+    return Try<Nothing>::error(busyResult.error());
   } else if (busyResult.get()) {
-    return Try<bool>::error("Some subsystems are currently being attached");
+    return Try<Nothing>::error("Some subsystems are currently being attached");
   }
 
   // Create the directory for the hierarchy.
-  if (!os::mkdir(hierarchy)) {
-    return Try<bool>::error("Failed to create " + hierarchy);
+  Try<Nothing> mkdir = os::mkdir(hierarchy);
+  if (mkdir.isError()) {
+    return Try<Nothing>::error(
+        "Failed to create " + hierarchy + ": " + mkdir.error());
   }
 
   // Mount the virtual file system (attach subsystems).
-  Try<bool> mountResult = internal::mount(hierarchy, subsystems);
+  Try<Nothing> mountResult = internal::mount(hierarchy, subsystems);
   if (mountResult.isError()) {
+    // Ignore success or failure of rmdir.
     os::rmdir(hierarchy);
-    return Try<bool>::error(mountResult.error());
+    return mountResult;
   }
 
-  return true;
+  return Nothing();
 }
 
 
-Try<bool> removeHierarchy(const std::string& hierarchy)
+Try<Nothing> removeHierarchy(const std::string& hierarchy)
 {
-  Try<bool> check = checkHierarchy(hierarchy);
+  Try<Nothing> check = checkHierarchy(hierarchy);
   if (check.isError()) {
-    return Try<bool>::error(check.error());
+    return check;
   }
 
-  Try<bool> unmount = internal::unmount(hierarchy);
+  Try<Nothing> unmount = internal::unmount(hierarchy);
   if (unmount.isError()) {
-    return Try<bool>::error(unmount.error());
+    return unmount;
   }
 
-  if (!os::rmdir(hierarchy)) {
-    return Try<bool>::error("Failed to remove directory " + hierarchy);
+  Try<Nothing> rmdir = os::rmdir(hierarchy);
+  if (rmdir.isError()) {
+    return Try<Nothing>::error("Failed to rmdir " + hierarchy + rmdir.error());
   }
 
-  return true;
+  return Nothing();
 }
 
 
-Try<bool> checkHierarchy(const std::string& hierarchy)
+Try<Nothing> checkHierarchy(const std::string& hierarchy)
 {
   Try<std::set<std::string> > names = subsystems(hierarchy);
   if (names.isError()) {
-    return Try<bool>::error(names.error());
+    return Try<Nothing>::error(names.error());
   }
 
-  return true;
+  return Nothing();
 }
 
 
-Try<bool> checkHierarchy(const std::string& hierarchy,
-                         const std::string& subsystems)
+Try<Nothing> checkHierarchy(const std::string& hierarchy,
+                            const std::string& subsystems)
 {
   // Check if subsystems are enabled in the system.
   Try<bool> enabledResult = enabled(subsystems);
   if (enabledResult.isError()) {
-    return Try<bool>::error(enabledResult.error());
+    return Try<Nothing>::error(enabledResult.error());
   } else if (!enabledResult.get()) {
-    return Try<bool>::error("Some subsystems are not enabled");
+    return Try<Nothing>::error("Some subsystems are not enabled");
   }
 
   Try<std::set<std::string> > namesResult = cgroups::subsystems(hierarchy);
   if (namesResult.isError()) {
-    return Try<bool>::error(namesResult.error());
+    return Try<Nothing>::error(namesResult.error());
   }
 
   std::set<std::string> names = namesResult.get();
   foreach (const std::string& name, strings::tokenize(subsystems, ",")) {
     if (names.find(name) == names.end()) {
-      return Try<bool>::error(
+      return Try<Nothing>::error(
           "Subsystem " + name + " is not found or enabled");
     }
   }
 
-  return true;
+  return Nothing();
 }
 
 
-Try<bool> createCgroup(const std::string& hierarchy,
-                       const std::string& cgroup)
+Try<Nothing> createCgroup(const std::string& hierarchy,
+                          const std::string& cgroup)
 {
-  Try<bool> check = checkHierarchy(hierarchy);
+  Try<Nothing> check = checkHierarchy(hierarchy);
   if (check.isError()) {
-    return Try<bool>::error(check.error());
+    return check;
   }
 
   return internal::createCgroup(hierarchy, cgroup);
 }
 
 
-Try<bool> removeCgroup(const std::string& hierarchy,
-                       const std::string& cgroup)
+Try<Nothing> removeCgroup(const std::string& hierarchy,
+                          const std::string& cgroup)
 {
-  Try<bool> check = checkCgroup(hierarchy, cgroup);
+  Try<Nothing> check = checkCgroup(hierarchy, cgroup);
   if (check.isError()) {
-    return Try<bool>::error(check.error());
+    return check;
   }
 
   Try<std::vector<std::string> > cgroups = getCgroups(hierarchy, cgroup);
   if (cgroups.isError()) {
-    return Try<bool>::error(cgroups.error());
+    return Try<Nothing>::error(cgroups.error());
   }
 
   if (!cgroups.get().empty()) {
-    return Try<bool>::error("Sub-cgroups exist in " + cgroup);
+    return Try<Nothing>::error("Sub-cgroups exist in " + cgroup);
   }
 
   return internal::removeCgroup(hierarchy, cgroup);
 }
 
 
-Try<bool> checkCgroup(const std::string& hierarchy,
-                      const std::string& cgroup)
+Try<Nothing> checkCgroup(const std::string& hierarchy,
+                         const std::string& cgroup)
 {
-  Try<bool> check = checkHierarchy(hierarchy);
+  Try<Nothing> check = checkHierarchy(hierarchy);
   if (check.isError()) {
-    return Try<bool>::error(check.error());
+    return check;
   }
 
   std::string path = hierarchy + "/" + cgroup;
   if (!os::exists(path)) {
-    return Try<bool>::error("Cgroup " + cgroup + " is not valid");
+    return Try<Nothing>::error("Cgroup " + cgroup + " is not valid");
   }
 
-  return true;
+  return Nothing();
 }
 
 
@@ -601,7 +596,7 @@ Try<std::string> readControl(const std::
                              const std::string& cgroup,
                              const std::string& control)
 {
-  Try<bool> check = checkControl(hierarchy, cgroup, control);
+  Try<Nothing> check = checkControl(hierarchy, cgroup, control);
   if (check.isError()) {
     return Try<std::string>::error(check.error());
   }
@@ -610,42 +605,42 @@ Try<std::string> readControl(const std::
 }
 
 
-Try<bool> writeControl(const std::string& hierarchy,
-                       const std::string& cgroup,
-                       const std::string& control,
-                       const std::string& value)
+Try<Nothing> writeControl(const std::string& hierarchy,
+                          const std::string& cgroup,
+                          const std::string& control,
+                          const std::string& value)
 {
-  Try<bool> check = checkControl(hierarchy, cgroup, control);
+  Try<Nothing> check = checkControl(hierarchy, cgroup, control);
   if (check.isError()) {
-    return Try<bool>::error(check.error());
+    return check;
   }
 
   return internal::writeControl(hierarchy, cgroup, control, value);
 }
 
 
-Try<bool> checkControl(const std::string& hierarchy,
-                       const std::string& cgroup,
-                       const std::string& control)
+Try<Nothing> checkControl(const std::string& hierarchy,
+                          const std::string& cgroup,
+                          const std::string& control)
 {
-  Try<bool> check = checkCgroup(hierarchy, cgroup);
+  Try<Nothing> check = checkCgroup(hierarchy, cgroup);
   if (check.isError()) {
-    return Try<bool>::error(check.error());
+    return check;
   }
 
   std::string path = hierarchy + "/" + cgroup + "/" + control;
   if (!os::exists(path)) {
-    return Try<bool>::error("Control file " + path + " does not exist");
+    return Try<Nothing>::error("Control file " + path + " does not exist");
   }
 
-  return true;
+  return Nothing();
 }
 
 
 Try<std::vector<std::string> > getCgroups(const std::string& hierarchy,
                                           const std::string& cgroup)
 {
-  Try<bool> check = checkCgroup(hierarchy, cgroup);
+  Try<Nothing> check = checkCgroup(hierarchy, cgroup);
   if (check.isError()) {
     return Try<std::vector<std::string> >::error(check.error());
   }
@@ -701,7 +696,7 @@ Try<std::vector<std::string> > getCgroup
 Try<std::set<pid_t> > getTasks(const std::string& hierarchy,
                                const std::string& cgroup)
 {
-  Try<bool> check = checkCgroup(hierarchy, cgroup);
+  Try<Nothing> check = checkCgroup(hierarchy, cgroup);
   if (check.isError()) {
     return Try<std::set<pid_t> >::error(check.error());
   }
@@ -733,13 +728,13 @@ Try<std::set<pid_t> > getTasks(const std
 }
 
 
-Try<bool> assignTask(const std::string& hierarchy,
-                     const std::string& cgroup,
-                     pid_t pid)
+Try<Nothing> assignTask(const std::string& hierarchy,
+                        const std::string& cgroup,
+                        pid_t pid)
 {
-  Try<bool> check = checkCgroup(hierarchy, cgroup);
+  Try<Nothing> check = checkCgroup(hierarchy, cgroup);
   if (check.isError()) {
-    return Try<bool>::error(check.error());
+    return check;
   }
 
   return internal::writeControl(hierarchy,
@@ -773,16 +768,14 @@ static int eventfd(unsigned int initval,
 
   // Manually set CLOEXEC and NONBLOCK.
   if ((flags & EFD_CLOEXEC) != 0) {
-    Try<bool> cloexec = os::cloexec(fd);
-    if (cloexec.isError()) {
+    if (os::cloexec(fd).isError()) {
       os::close(fd);
       return -1;
     }
   }
 
   if ((flags & EFD_NONBLOCK) != 0) {
-    Try<bool> nonblock = os::nonblock(fd);
-    if (nonblock.isError()) {
+    if (os::nonblock(fd).isError()) {
       os::close(fd);
       return -1;
     }
@@ -836,10 +829,10 @@ static Try<int> openNotifier(const std::
   if (args.isSome()) {
     out << " " << args.get();
   }
-  Try<bool> write = internal::writeControl(hierarchy,
-                                           cgroup,
-                                           "cgroup.event_control",
-                                           out.str());
+  Try<Nothing> write = internal::writeControl(hierarchy,
+                                              cgroup,
+                                              "cgroup.event_control",
+                                              out.str());
   if (write.isError()) {
     os::close(efd);
     os::close(cfd.get());
@@ -854,9 +847,9 @@ static Try<int> openNotifier(const std::
 
 // Close a notifier. The parameter fd is the eventfd returned by openNotifier.
 // @param   fd      The eventfd returned by openNotifier.
-// @return  True if the operation succeeds.
+// @return  Some if the operation succeeds.
 //          Error if the operation fails.
-static Try<bool> closeNotifier(int fd)
+static Try<Nothing> closeNotifier(int fd)
 {
   return os::close(fd);
 }
@@ -915,7 +908,7 @@ protected:
 
     // Close the eventfd if needed.
     if (eventfd.isSome()) {
-      Try<bool> close = internal::closeNotifier(eventfd.get());
+      Try<Nothing> close = internal::closeNotifier(eventfd.get());
       if (close.isError()) {
         LOG(ERROR) << "Closing eventfd " << eventfd.get()
                    << " failed: " << close.error();
@@ -969,7 +962,7 @@ Future<uint64_t> listenEvent(const std::
                              const std::string& control,
                              const Option<std::string>& args)
 {
-  Try<bool> check = checkControl(hierarchy, cgroup, control);
+  Try<Nothing> check = checkControl(hierarchy, cgroup, control);
   if (check.isError()) {
     return Future<uint64_t>::failed(check.error());
   }
@@ -1030,10 +1023,10 @@ protected:
 private:
   void freeze()
   {
-    Try<bool> result = internal::writeControl(hierarchy,
-                                              cgroup,
-                                              "freezer.state",
-                                              "FROZEN");
+    Try<Nothing> result = internal::writeControl(hierarchy,
+                                                 cgroup,
+                                                 "freezer.state",
+                                                 "FROZEN");
     if (result.isError()) {
       promise.fail(result.error());
       terminate(self());
@@ -1044,10 +1037,10 @@ private:
 
   void thaw()
   {
-    Try<bool> result = internal::writeControl(hierarchy,
-                                              cgroup,
-                                              "freezer.state",
-                                              "THAWED");
+    Try<Nothing> result = internal::writeControl(hierarchy,
+                                                 cgroup,
+                                                 "freezer.state",
+                                                 "THAWED");
     if (result.isError()) {
       promise.fail(result.error());
       terminate(self());
@@ -1153,7 +1146,7 @@ Future<bool> freezeCgroup(const std::str
                           const std::string& cgroup,
                           const Duration& interval)
 {
-  Try<bool> check = checkControl(hierarchy, cgroup, "freezer.state");
+  Try<Nothing> check = checkControl(hierarchy, cgroup, "freezer.state");
   if (check.isError()) {
     return Future<bool>::failed(check.error());
   }
@@ -1181,7 +1174,7 @@ Future<bool> thawCgroup(const std::strin
                         const std::string& cgroup,
                         const Duration& interval)
 {
-  Try<bool> check = checkControl(hierarchy, cgroup, "freezer.state");
+  Try<Nothing> check = checkControl(hierarchy, cgroup, "freezer.state");
   if (check.isError()) {
     return Future<bool>::failed(check.error());
   }
@@ -1390,12 +1383,12 @@ Future<bool> killTasks(const std::string
                        const std::string& cgroup,
                        const Duration& interval)
 {
-  Try<bool> freezerCheck = checkHierarchy(hierarchy, "freezer");
+  Try<Nothing> freezerCheck = checkHierarchy(hierarchy, "freezer");
   if (freezerCheck.isError()) {
     return Future<bool>::failed(freezerCheck.error());
   }
 
-  Try<bool> cgroupCheck = checkCgroup(hierarchy, cgroup);
+  Try<Nothing> cgroupCheck = checkCgroup(hierarchy, cgroup);
   if (cgroupCheck.isError()) {
     return Future<bool>::failed(cgroupCheck.error());
   }
@@ -1474,7 +1467,7 @@ private:
   void remove()
   {
     foreach (const std::string& cgroup, cgroups) {
-      Try<bool> remove = internal::removeCgroup(hierarchy, cgroup);
+      Try<Nothing> remove = internal::removeCgroup(hierarchy, cgroup);
       if (remove.isError()) {
         promise.fail(remove.error());
         terminate(self());
@@ -1502,7 +1495,7 @@ Future<bool> destroyCgroup(const std::st
                            const std::string& cgroup,
                            const Duration& interval)
 {
-  Try<bool> cgroupCheck = checkCgroup(hierarchy, cgroup);
+  Try<Nothing> cgroupCheck = checkCgroup(hierarchy, cgroup);
   if (cgroupCheck.isError()) {
     return Future<bool>::failed(cgroupCheck.error());
   }

Modified: incubator/mesos/trunk/src/linux/cgroups.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/linux/cgroups.hpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/linux/cgroups.hpp (original)
+++ incubator/mesos/trunk/src/linux/cgroups.hpp Wed Sep 19 00:08:13 2012
@@ -94,36 +94,36 @@ Try<std::set<std::string> > subsystems(c
 // virtual file system will be mounted with proper subsystems attached.
 // @param   hierarchy   Path to the hierarchy root.
 // @param   subsystems  Comma-separated subsystem names.
-// @return  True if the operation succeeds.
+// @return  Some if the operation succeeds.
 //          Error if the operation fails.
-Try<bool> createHierarchy(const std::string& hierarchy,
-                          const std::string& subsystems);
+Try<Nothing> createHierarchy(const std::string& hierarchy,
+                             const std::string& subsystems);
 
 
 // Remove a hierarchy and the directory associated with it. This function will
 // return error if the given hierarchy is not valid. Also, it will return error
 // if the given hierarchy has cgroups inside.
 // @param   hierarchy   Path to the hierarchy root.
-// @return  True if the operation succeeds.
+// @return  Some if the operation succeeds.
 //          Error if the operation fails.
-Try<bool> removeHierarchy(const std::string& hierarchy);
+Try<Nothing> removeHierarchy(const std::string& hierarchy);
 
 
 // Check whether a given directory is a hierarchy root for cgroups.
 // @param   hierarchy   Path to the hierarchy root.
-// @return  True if the given directory is a hierarchy root.
+// @return  Some if the given directory is a hierarchy root.
 //          Error if the check fails.
-Try<bool> checkHierarchy(const std::string& hierarchy);
+Try<Nothing> checkHierarchy(const std::string& hierarchy);
 
 
 // Check whether a given directory is a hierarchy root for cgroups, and whether
 // it has proper subsystems attached.
 // @param   hierarchy   Path to the hierarchy root.
 // @param   subsystems  Comma-separated subsystem names.
-// @return  True if the check succeeds.
+// @return  Some if the check succeeds.
 //          Error if the check fails.
-Try<bool> checkHierarchy(const std::string& hierarchy,
-                         const std::string& subsystems);
+Try<Nothing> checkHierarchy(const std::string& hierarchy,
+                            const std::string& subsystems);
 
 
 // Create a cgroup under a given hierarchy. This function will return error if
@@ -132,10 +132,10 @@ Try<bool> checkHierarchy(const std::stri
 // return error.
 // @param   hierarchy   Path to the hierarchy root.
 // @param   cgroup      Path to the cgroup relative to the hierarchy root.
-// @return  True if the operation succeeds.
+// @return  Some if the operation succeeds.
 //          Error if the operation fails.
-Try<bool> createCgroup(const std::string& hierarchy,
-                       const std::string& cgroup);
+Try<Nothing> createCgroup(const std::string& hierarchy,
+                          const std::string& cgroup);
 
 
 // Remove a cgroup under a given hierarchy. This function will return error if
@@ -145,18 +145,18 @@ Try<bool> createCgroup(const std::string
 // given cgroup, the removal operation will also fail.
 // @param   hierarchy   Path to the hierarchy root.
 // @param   cgroup      Path to the cgroup relative to the hierarchy root.
-Try<bool> removeCgroup(const std::string& hierarchy,
-                       const std::string& cgroup);
+Try<Nothing> removeCgroup(const std::string& hierarchy,
+                          const std::string& cgroup);
 
 
 // Check whether a given cgroup under a given hierarchy is valid. This function
 // will verify both the given hierarchy and the given cgroup.
 // @param   hierarchy   Path to the hierarchy root.
 // @param   cgroup      Path to the cgroup relative to the hierarchy root.
-// @return  True if the check succeeds.
+// @return  Some if the check succeeds.
 //          Error if the check fails.
-Try<bool> checkCgroup(const std::string& hierarchy,
-                      const std::string& cgroup);
+Try<Nothing> checkCgroup(const std::string& hierarchy,
+                         const std::string& cgroup);
 
 
 // Read a control file. Control files are used to monitor and control cgroups.
@@ -178,12 +178,12 @@ Try<std::string> readControl(const std::
 // @param   cgroup      Path to the cgroup relative to the hierarchy root.
 // @param   control     Name of the control file.
 // @param   value       Value to be written.
-// @return  True if the operation succeeds.
+// @return  Some if the operation succeeds.
 //          Error if the operation fails.
-Try<bool> writeControl(const std::string& hierarchy,
-                       const std::string& cgroup,
-                       const std::string& control,
-                       const std::string& value);
+Try<Nothing> writeControl(const std::string& hierarchy,
+                          const std::string& cgroup,
+                          const std::string& control,
+                          const std::string& value);
 
 
 // Check whether a control file is valid under a given cgroup and a given
@@ -193,11 +193,11 @@ Try<bool> writeControl(const std::string
 // @param   hierarchy   Path to the hierarchy root.
 // @param   cgroup      Path to the cgroup relative to the hierarchy root.
 // @param   control     Name of the control file.
-// @return  True if the check succeeds.
+// @return  Some if the check succeeds.
 //          Error if the check fails.
-Try<bool> checkControl(const std::string& hierarchy,
-                       const std::string& cgroup,
-                       const std::string& control);
+Try<Nothing> checkControl(const std::string& hierarchy,
+                          const std::string& cgroup,
+                          const std::string& control);
 
 
 // Return all the cgroups under the given cgroup of a given hierarchy. By
@@ -225,11 +225,11 @@ Try<std::set<pid_t> > getTasks(const std
 // @param   hierarchy   Path to the hierarchy root.
 // @param   cgroup      Path to the cgroup relative to the hierarchy root.
 // @param   pid         The pid of the given process.
-// @return  True if the operation succeeds.
+// @return  Some if the operation succeeds.
 //          Error if the operation fails.
-Try<bool> assignTask(const std::string& hierarchy,
-                     const std::string& cgroup,
-                     pid_t pid);
+Try<Nothing> assignTask(const std::string& hierarchy,
+                        const std::string& cgroup,
+                        pid_t pid);
 
 
 // Listen on an event notifier and return a future which will become ready when

Modified: incubator/mesos/trunk/src/linux/fs.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/linux/fs.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/linux/fs.cpp (original)
+++ incubator/mesos/trunk/src/linux/fs.cpp Wed Sep 19 00:08:13 2012
@@ -145,35 +145,35 @@ Try<FileSystemTable> FileSystemTable::re
 }
 
 
-Try<bool> mount(const std::string& source,
-                const std::string& target,
-                const std::string& type,
-                unsigned long flags,
-                const void* data)
+Try<Nothing> mount(const std::string& source,
+                   const std::string& target,
+                   const std::string& type,
+                   unsigned long flags,
+                   const void* data)
 {
   // The prototype of function 'mount' on Linux is as follows:
   // int mount(const char *source, const char *target,
   //           const char *filesystemtype, unsigned long mountflags,
   //           const void *data);
   if (::mount(source.c_str(), target.c_str(), type.c_str(), flags, data) < 0) {
-    return Try<bool>::error(
+    return Try<Nothing>::error(
         "Failed to mount " + source + " at " + target + ": " + strerror(errno));
   }
 
-  return true;
+  return Nothing();
 }
 
 
-Try<bool> unmount(const std::string& target, int flags)
+Try<Nothing> unmount(const std::string& target, int flags)
 {
   // The prototype of function 'umount2' on Linux is as follows:
   // int umount2(const char *target, int flags);
   if (::umount2(target.c_str(), flags) < 0) {
-    return Try<bool>::error(
+    return Try<Nothing>::error(
         "Failed to unmount " + target + ": " + strerror(errno));
   }
 
-  return true;
+  return Nothing();
 }
 
 

Modified: incubator/mesos/trunk/src/linux/fs.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/linux/fs.hpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/linux/fs.hpp (original)
+++ incubator/mesos/trunk/src/linux/fs.hpp Wed Sep 19 00:08:13 2012
@@ -27,6 +27,7 @@
 #include <string>
 #include <vector>
 
+#include <stout/nothing.hpp>
 #include <stout/try.hpp>
 
 
@@ -125,19 +126,19 @@ struct FileSystemTable {
 // @param   type      File system type (listed in /proc/filesystems).
 // @param   flags     Mount flags.
 // @param   data      Extra data interpreted by different file systems.
-// @return  Whether the mount operation successes.
-Try<bool> mount(const std::string& source,
-                const std::string& target,
-                const std::string& type,
-                unsigned long flags,
-                const void* data);
+// @return  Whether the mount operation succeeds.
+Try<Nothing> mount(const std::string& source,
+                   const std::string& target,
+                   const std::string& type,
+                   unsigned long flags,
+                   const void* data);
 
 
 // Unmount a file system.
 // @param   target    The (topmost) directory where the file system attaches.
 // @param   flags     Unmount flags.
-// @return  Whether the unmount operation successes.
-Try<bool> unmount(const std::string& target, int flags = 0);
+// @return  Whether the unmount operation succeeds.
+Try<Nothing> unmount(const std::string& target, int flags = 0);
 
 
 } // namespace fs {

Modified: incubator/mesos/trunk/src/log/replica.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/log/replica.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/log/replica.cpp (original)
+++ incubator/mesos/trunk/src/log/replica.cpp Wed Sep 19 00:08:13 2012
@@ -28,6 +28,7 @@
 #include <process/protobuf.hpp>
 
 #include <stout/foreach.hpp>
+#include <stout/nothing.hpp>
 #include <stout/numify.hpp>
 #include <stout/stopwatch.hpp>
 #include <stout/utils.hpp>
@@ -74,8 +75,8 @@ class Storage
 public:
   virtual ~Storage() {}
   virtual Try<State> recover(const string& path) = 0;
-  virtual Try<void> persist(const Promise& promise) = 0;
-  virtual Try<void> persist(const Action& action) = 0;
+  virtual Try<Nothing> persist(const Promise& promise) = 0;
+  virtual Try<Nothing> persist(const Action& action) = 0;
   virtual Try<Action> read(uint64_t position) = 0;
 };
 
@@ -88,8 +89,8 @@ public:
   virtual ~LevelDBStorage();
 
   virtual Try<State> recover(const string& path);
-  virtual Try<void> persist(const Promise& promise);
-  virtual Try<void> persist(const Action& action);
+  virtual Try<Nothing> persist(const Promise& promise);
+  virtual Try<Nothing> persist(const Action& action);
   virtual Try<Action> read(uint64_t position);
 
 private:
@@ -321,7 +322,7 @@ Try<State> LevelDBStorage::recover(const
 }
 
 
-Try<void> LevelDBStorage::persist(const Promise& promise)
+Try<Nothing> LevelDBStorage::persist(const Promise& promise)
 {
   Stopwatch stopwatch;
   stopwatch.start();
@@ -336,23 +337,23 @@ Try<void> LevelDBStorage::persist(const 
   string value;
 
   if (!record.SerializeToString(&value)) {
-    return Try<void>::error("Failed to serialize record");
+    return Try<Nothing>::error("Failed to serialize record");
   }
 
   leveldb::Status status = db->Put(options, encode(0, false), value);
 
   if (!status.ok()) {
-    return Try<void>::error(status.ToString());
+    return Try<Nothing>::error(status.ToString());
   }
 
   LOG(INFO) << "Persisting promise (" << value.size()
             << " bytes) to leveldb took " << stopwatch.elapsed();
 
-  return Try<void>::some();
+  return Nothing();
 }
 
 
-Try<void> LevelDBStorage::persist(const Action& action)
+Try<Nothing> LevelDBStorage::persist(const Action& action)
 {
   Stopwatch stopwatch;
   stopwatch.start();
@@ -364,7 +365,7 @@ Try<void> LevelDBStorage::persist(const 
   string value;
 
   if (!record.SerializeToString(&value)) {
-    return Try<void>::error("Failed to serialize record");
+    return Try<Nothing>::error("Failed to serialize record");
   }
 
   leveldb::WriteOptions options;
@@ -373,7 +374,7 @@ Try<void> LevelDBStorage::persist(const 
   leveldb::Status status = db->Put(options, encode(action.position()), value);
 
   if (!status.ok()) {
-    return Try<void>::error(status.ToString());
+    return Try<Nothing>::error(status.ToString());
   }
 
   LOG(INFO) << "Persisting action (" << value.size()
@@ -430,7 +431,7 @@ Try<void> LevelDBStorage::persist(const 
     }
   }
 
-  return Try<void>::some();
+  return Nothing();
 }
 
 
@@ -937,7 +938,7 @@ void ReplicaProcess::learn(uint64_t posi
 
 bool ReplicaProcess::persist(const Promise& promise)
 {
-  Try<void> persisted = storage->persist(promise);
+  Try<Nothing> persisted = storage->persist(promise);
 
   if (persisted.isError()) {
     LOG(ERROR) << "Error writing to log: " << persisted.error();
@@ -952,7 +953,7 @@ bool ReplicaProcess::persist(const Promi
 
 bool ReplicaProcess::persist(const Action& action)
 {
-  Try<void> persisted = storage->persist(action);
+  Try<Nothing> persisted = storage->persist(action);
 
   if (persisted.isError()) {
     LOG(ERROR) << "Error writing to log: " << persisted.error();

Modified: incubator/mesos/trunk/src/logging/logging.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/logging/logging.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/logging/logging.cpp (original)
+++ incubator/mesos/trunk/src/logging/logging.cpp Wed Sep 19 00:08:13 2012
@@ -152,9 +152,10 @@ void initialize(const string& _argv0, co
 
   // Set glog's parameters through Google Flags variables.
   if (flags.log_dir.isSome()) {
-    if (!os::mkdir(flags.log_dir.get())) {
+    Try<Nothing> mkdir = os::mkdir(flags.log_dir.get());
+    if (mkdir.isError()) {
       std::cerr << "Could not initialize logging: Failed to create directory "
-                << flags.log_dir.get() << std::endl;
+                << flags.log_dir.get() << ": " << mkdir.error() << std::endl;
       exit(1);
     }
     FLAGS_log_dir = flags.log_dir.get();

Modified: incubator/mesos/trunk/src/slave/cgroups_isolation_module.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/cgroups_isolation_module.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/cgroups_isolation_module.cpp (original)
+++ incubator/mesos/trunk/src/slave/cgroups_isolation_module.cpp Wed Sep 19 00:08:13 2012
@@ -139,8 +139,7 @@ void CgroupsIsolationModule::initialize(
   }
 
   // Prepare the cgroups hierarchy root.
-  Try<bool> check = cgroups::checkHierarchy(hierarchy);
-  if (check.isError()) {
+  if (cgroups::checkHierarchy(hierarchy).isError()) {
     // The given hierarchy is not a cgroups hierarchy root. We will try to
     // create a cgroups hierarchy root there.
     if (os::exists(hierarchy)) {
@@ -176,8 +175,8 @@ void CgroupsIsolationModule::initialize(
     }
 
     // Create the cgroups hierarchy root.
-    Try<bool> create = cgroups::createHierarchy(hierarchy,
-                                                strings::trim(subsystems, ","));
+    Try<Nothing> create =
+        cgroups::createHierarchy(hierarchy, strings::trim(subsystems, ","));
     if (create.isError()) {
       LOG(FATAL) << "Failed to create cgroups hierarchy root at " << hierarchy
                  << ": " << create.error();
@@ -285,7 +284,7 @@ void CgroupsIsolationModule::launchExecu
   }
 
   // Create a new cgroup for the executor.
-  Try<bool> create =
+  Try<Nothing> create =
     cgroups::createCgroup(hierarchy, getCgroupName(frameworkId, executorId));
   if (create.isError()) {
     LOG(FATAL) << "Failed to create cgroup for executor " << executorId
@@ -316,7 +315,7 @@ void CgroupsIsolationModule::launchExecu
                << rootCpusetMems.error();
   }
 
-  Try<bool> setCpusetCpus =
+  Try<Nothing> setCpusetCpus =
     cgroups::writeControl(hierarchy,
                           getCgroupName(frameworkId, executorId),
                           "cpuset.cpus",
@@ -327,7 +326,7 @@ void CgroupsIsolationModule::launchExecu
                << ": " << setCpusetCpus.error();
   }
 
-  Try<bool> setCpusetMems =
+  Try<Nothing> setCpusetMems =
     cgroups::writeControl(hierarchy,
                           getCgroupName(frameworkId, executorId),
                           "cpuset.mems",
@@ -368,7 +367,7 @@ void CgroupsIsolationModule::launchExecu
   } else {
     // In child process.
     // Put self into the newly created cgroup.
-    Try<bool> assign =
+    Try<Nothing> assign =
       cgroups::assignTask(hierarchy,
                           getCgroupName(frameworkId, executorId),
                           ::getpid());
@@ -451,7 +450,7 @@ void CgroupsIsolationModule::resourcesCh
       // not depend on any subsystem, or the dependent subsystem is active.
       if (!resourceSubsystemMap.contains(name) ||
           activatedSubsystems.contains(resourceSubsystemMap[name])) {
-        Try<bool> result =
+        Try<Nothing> result =
           (this->*resourceChangedHandlers[name])(frameworkId,
                                                  executorId,
                                                  resources);
@@ -489,7 +488,7 @@ void CgroupsIsolationModule::processExit
 }
 
 
-Try<bool> CgroupsIsolationModule::cpusChanged(
+Try<Nothing> CgroupsIsolationModule::cpusChanged(
     const FrameworkID& frameworkId,
     const ExecutorID& executorId,
     const Resources& resources)
@@ -507,13 +506,13 @@ Try<bool> CgroupsIsolationModule::cpusCh
     size_t cpuShares =
       std::max((size_t)(CPU_SHARES_PER_CPU * cpus), MIN_CPU_SHARES);
 
-    Try<bool> set =
+    Try<Nothing> set =
       cgroups::writeControl(hierarchy,
                             getCgroupName(frameworkId, executorId),
                             "cpu.shares",
                             stringify(cpuShares));
     if (set.isError()) {
-      return Try<bool>::error(set.error());
+      return set;
     }
 
     LOG(INFO) << "Write cpu.shares = " << cpuShares
@@ -521,11 +520,11 @@ Try<bool> CgroupsIsolationModule::cpusCh
               << " of framework " << frameworkId;
   }
 
-  return true;
+  return Nothing();
 }
 
 
-Try<bool> CgroupsIsolationModule::memChanged(
+Try<Nothing> CgroupsIsolationModule::memChanged(
     const FrameworkID& frameworkId,
     const ExecutorID& executorId,
     const Resources& resources)
@@ -543,13 +542,13 @@ Try<bool> CgroupsIsolationModule::memCha
     size_t limitInBytes =
       std::max((size_t)mem, MIN_MEMORY_MB) * 1024LL * 1024LL;
 
-    Try<bool> set =
+    Try<Nothing> set =
       cgroups::writeControl(hierarchy,
                             getCgroupName(frameworkId, executorId),
                             "memory.limit_in_bytes",
                             stringify(limitInBytes));
     if (set.isError()) {
-      return Try<bool>::error(set.error());
+      return set;
     }
 
     LOG(INFO) << "Write memory.limit_in_bytes = " << limitInBytes
@@ -557,7 +556,7 @@ Try<bool> CgroupsIsolationModule::memCha
               << " of framework " << frameworkId;
   }
 
-  return true;
+  return Nothing();
 }
 
 

Modified: incubator/mesos/trunk/src/slave/cgroups_isolation_module.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/cgroups_isolation_module.hpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/cgroups_isolation_module.hpp (original)
+++ incubator/mesos/trunk/src/slave/cgroups_isolation_module.hpp Wed Sep 19 00:08:13 2012
@@ -97,18 +97,18 @@ private:
   // @param   executorId    The id of the given executor.
   // @param   resources     The handle for the resources.
   // @return  Whether the operation successes.
-  Try<bool> cpusChanged(const FrameworkID& frameworkId,
-                        const ExecutorID& executorId,
-                        const Resources& resources);
+  Try<Nothing> cpusChanged(const FrameworkID& frameworkId,
+                           const ExecutorID& executorId,
+                           const Resources& resources);
 
   // The callback which will be invoked when "mem" resource has changed.
   // @param   frameworkId   The id of the given framework.
   // @param   executorId    The id of the given executor.
   // @param   resources     The handle for the resources.
   // @return  Whether the operation successes.
-  Try<bool> memChanged(const FrameworkID& frameworkId,
-                       const ExecutorID& executorId,
-                       const Resources& resources);
+  Try<Nothing> memChanged(const FrameworkID& frameworkId,
+                          const ExecutorID& executorId,
+                          const Resources& resources);
 
   // Start listening on OOM events. This function will create an eventfd and
   // start polling on it.
@@ -200,7 +200,7 @@ private:
   // Mapping between resource name to the corresponding resource changed
   // handler function.
   hashmap<std::string,
-          Try<bool>(CgroupsIsolationModule::*)(
+          Try<Nothing>(CgroupsIsolationModule::*)(
               const FrameworkID&,
               const ExecutorID&,
               const Resources&)> resourceChangedHandlers;

Modified: incubator/mesos/trunk/src/slave/gc.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/gc.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/gc.cpp (original)
+++ incubator/mesos/trunk/src/slave/gc.cpp Wed Sep 19 00:08:13 2012
@@ -53,7 +53,7 @@ public:
   virtual ~GarbageCollectorProcess();
 
   // GarbageCollector implementation.
-  Future<bool> schedule(const Duration& d, const string& path);
+  Future<Nothing> schedule(const Duration& d, const string& path);
 
   void prune(const Duration& d);
 
@@ -62,11 +62,11 @@ private:
 
   struct PathInfo
   {
-    PathInfo(const string& _path, Promise<bool>* _promise)
+    PathInfo(const string& _path, Promise<Nothing>* _promise)
       : path(_path), promise(_promise) {}
 
     string path;
-    Promise<bool>* promise;
+    Promise<Nothing>* promise;
   };
 
   // Store all the paths that needed to be deleted after a given timeout.
@@ -90,13 +90,13 @@ GarbageCollectorProcess::~GarbageCollect
 }
 
 
-Future<bool> GarbageCollectorProcess::schedule(
+Future<Nothing> GarbageCollectorProcess::schedule(
     const Duration& d,
     const string& path)
 {
   LOG(INFO) << "Scheduling " << path << " for removal";
 
-  Promise<bool>* promise = new Promise<bool>();
+  Promise<Nothing>* promise = new Promise<Nothing>();
 
   Timeout removalTime(d);
 
@@ -135,17 +135,18 @@ void GarbageCollectorProcess::remove(con
   if (paths.count(removalTime) > 0) {
     foreach (const PathInfo& info, paths[removalTime]) {
       const string& path = info.path;
-      Promise<bool>* promise = info.promise;
+      Promise<Nothing>* promise = info.promise;
 
       LOG(INFO) << "Deleting " << path;
 
-      // TODO(benh): Check error conditions of 'rmdir', e.g., permission
-      // denied, file no longer exists, etc.
-      // TODO(vinod): Consider invoking rmdir via async.
-      bool result = os::rmdir(path);
-
-      VLOG(1) << "Deleted " << path;
-      promise->set(result);
+      Try<Nothing> result = os::rmdir(path);
+      if (result.isError()) {
+        LOG(WARNING) << "Failed to delete " << path << ": " << result.error();
+        promise->fail(result.error());
+      } else {
+        VLOG(1) << "Deleted " << path;
+        promise->set(result.get());
+      }
       delete promise;
     }
     paths.erase(removalTime);
@@ -187,7 +188,7 @@ GarbageCollector::~GarbageCollector()
 }
 
 
-Future<bool> GarbageCollector::schedule(
+Future<Nothing> GarbageCollector::schedule(
     const Duration& d,
     const string& path)
 {

Modified: incubator/mesos/trunk/src/slave/gc.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/gc.hpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/gc.hpp (original)
+++ incubator/mesos/trunk/src/slave/gc.hpp Wed Sep 19 00:08:13 2012
@@ -24,6 +24,8 @@
 #include <process/future.hpp>
 
 #include <stout/duration.hpp>
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
 
 namespace mesos {
 namespace internal {
@@ -49,7 +51,7 @@ public:
   // duration of time has elapsed and returns true if the file was
   // successfully removed and false if the file didn't exist (or an
   // error, e.g., permission denied).
-  process::Future<bool> schedule(const Duration& d, const std::string& path);
+  process::Future<Nothing> schedule(const Duration& d, const std::string& path);
 
   // Deletes all the directories, whose scheduled garbage collection time
   // is within the next 'd' duration of time.

Modified: incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp (original)
+++ incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp Wed Sep 19 00:08:13 2012
@@ -117,13 +117,13 @@ void ProcessBasedIsolationModule::launch
   }
 
   // Set the FD_CLOEXEC flags on these pipes
-  Try<bool> result = os::cloexec(pipes[0]);
-  CHECK(result.isSome()) << "Error setting FD_CLOEXEC on pipe[0] "
-                         << result.error();
-
-  result = os::cloexec(pipes[1]);
-  CHECK(result.isSome()) << "Error setting FD_CLOEXEC on pipe[1] "
-                         << result.error();
+  Try<Nothing> cloexec = os::cloexec(pipes[0]);
+  CHECK(cloexec.isSome()) << "Error setting FD_CLOEXEC on pipe[0] "
+                          << cloexec.error();
+
+  cloexec = os::cloexec(pipes[1]);
+  CHECK(cloexec.isSome()) << "Error setting FD_CLOEXEC on pipe[1] "
+                          << cloexec.error();
 
   pid_t pid;
   if ((pid = fork()) == -1) {

Modified: incubator/mesos/trunk/src/slave/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/slave.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave/slave.cpp Wed Sep 19 00:08:13 2012
@@ -1587,8 +1587,9 @@ string Slave::createUniqueWorkDirectory(
   }
   out << maxrun;
 
-  bool created = os::mkdir(out.str());
-  CHECK(created) << "Error creating work directory " << out.str();
+  Try<Nothing> mkdir = os::mkdir(out.str());
+  CHECK(mkdir.isSome()) << "Error creating work directory '"
+                        << out.str() << "': " << mkdir.error();
 
   return out.str();
 }

Modified: incubator/mesos/trunk/src/tests/cgroups_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/cgroups_tests.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/cgroups_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/cgroups_tests.cpp Wed Sep 19 00:08:13 2012
@@ -68,8 +68,7 @@ protected:
 
   void cleanup()
   {
-    Try<bool> check = cgroups::checkHierarchy(hierarchy);
-    if (check.isSome()) {
+    if (cgroups::checkHierarchy(hierarchy).isSome()) {
       // Remove all cgroups.
       Try<std::vector<std::string> > cgroups = cgroups::getCgroups(hierarchy);
       ASSERT_TRUE(cgroups.isSome());
@@ -217,103 +216,69 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_Subsyst
 
 TEST_F(CgroupsSimpleTest, ROOT_CGROUPS_CreateRemoveHierarchy)
 {
-  Try<bool> result = false;
+  EXPECT_TRUE(cgroups::createHierarchy("/tmp", "cpu").isError());
 
-  result = cgroups::createHierarchy("/tmp", "cpu");
-  EXPECT_TRUE(result.isError());
+  EXPECT_TRUE(cgroups::createHierarchy(hierarchy, "invalid").isError());
 
-  result = cgroups::createHierarchy(hierarchy, "invalid");
-  EXPECT_TRUE(result.isError());
+  ASSERT_TRUE(cgroups::createHierarchy(hierarchy, "cpu,memory").isSome());
 
-  result = cgroups::createHierarchy(hierarchy, "cpu,memory");
-  ASSERT_TRUE(result.isSome());
+  EXPECT_TRUE(cgroups::createHierarchy(hierarchy, "cpuset").isError());
 
-  result = cgroups::createHierarchy(hierarchy, "cpuset");
-  EXPECT_TRUE(result.isError());
+  EXPECT_TRUE(cgroups::removeHierarchy("/tmp").isError());
 
-  result = cgroups::removeHierarchy("/tmp");
-  EXPECT_TRUE(result.isError());
-
-  result = cgroups::removeHierarchy(hierarchy);
-  ASSERT_TRUE(result.isSome());
+  ASSERT_TRUE(cgroups::removeHierarchy(hierarchy).isSome());
 }
 
 
 TEST_F(CgroupsTest, ROOT_CGROUPS_CheckHierarchy)
 {
-  Try<bool> result = false;
+  EXPECT_TRUE(cgroups::checkHierarchy("/tmp-nonexist").isError());
 
-  result = cgroups::checkHierarchy("/tmp-nonexist");
-  EXPECT_TRUE(result.isError());
-
-  result = cgroups::checkHierarchy("/tmp");
-  EXPECT_TRUE(result.isError());
+  EXPECT_TRUE(cgroups::checkHierarchy("/tmp").isError());
 
-  result = cgroups::checkHierarchy(hierarchy);
-  EXPECT_TRUE(result.isSome());
+  EXPECT_TRUE(cgroups::checkHierarchy(hierarchy).isSome());
 
-  result = cgroups::checkHierarchy(hierarchy + "/");
-  EXPECT_TRUE(result.isSome());
+  EXPECT_TRUE(cgroups::checkHierarchy(hierarchy + "/").isSome());
 
-  result = cgroups::checkHierarchy(hierarchy + "/stu");
-  EXPECT_TRUE(result.isError());
+  EXPECT_TRUE(cgroups::checkHierarchy(hierarchy + "/stu").isError());
 }
 
 
 TEST_F(CgroupsTest, ROOT_CGROUPS_CheckHierarchySubsystems)
 {
-  Try<bool> result = false;
-
-  result = cgroups::checkHierarchy("/tmp-nonexist", "cpu");
-  EXPECT_TRUE(result.isError());
+  EXPECT_TRUE(cgroups::checkHierarchy("/tmp-nonexist", "cpu").isError());
 
-  result = cgroups::checkHierarchy("/tmp", "cpu,memory");
-  EXPECT_TRUE(result.isError());
+  EXPECT_TRUE(cgroups::checkHierarchy("/tmp", "cpu,memory").isError());
 
-  result = cgroups::checkHierarchy("/tmp", "cpu");
-  EXPECT_TRUE(result.isError());
+  EXPECT_TRUE(cgroups::checkHierarchy("/tmp", "cpu").isError());
 
-  result = cgroups::checkHierarchy("/tmp", "invalid");
-  EXPECT_TRUE(result.isError());
+  EXPECT_TRUE(cgroups::checkHierarchy("/tmp", "invalid").isError());
 
-  result = cgroups::checkHierarchy(hierarchy, "cpu,memory");
-  EXPECT_TRUE(result.isSome());
+  EXPECT_TRUE(cgroups::checkHierarchy(hierarchy, "cpu,memory").isSome());
 
-  result = cgroups::checkHierarchy(hierarchy, "memory");
-  EXPECT_TRUE(result.isSome());
+  EXPECT_TRUE(cgroups::checkHierarchy(hierarchy, "memory").isSome());
 
-  result = cgroups::checkHierarchy(hierarchy, "invalid");
-  EXPECT_TRUE(result.isError());
+  EXPECT_TRUE(cgroups::checkHierarchy(hierarchy, "invalid").isError());
 
-  result = cgroups::checkHierarchy(hierarchy + "/stu", "cpu");
-  EXPECT_TRUE(result.isError());
+  EXPECT_TRUE(cgroups::checkHierarchy(hierarchy + "/stu", "cpu").isError());
 }
 
 
 TEST_F(CgroupsSimpleTest, ROOT_CGROUPS_CreateRemoveCgroup)
 {
-  Try<bool> result = false;
+  EXPECT_TRUE(cgroups::createCgroup("/tmp", "test").isError());
 
-  result = cgroups::createCgroup("/tmp", "test");
-  EXPECT_TRUE(result.isError());
+  ASSERT_TRUE(cgroups::createHierarchy(hierarchy, "cpu,memory").isSome());
 
-  result = cgroups::createHierarchy(hierarchy, "cpu,memory");
-  ASSERT_TRUE(result.isSome());
+  EXPECT_TRUE(cgroups::createCgroup(hierarchy, "test/1").isError());
 
-  result = cgroups::createCgroup(hierarchy, "test/1");
-  EXPECT_TRUE(result.isError());
+  ASSERT_TRUE(cgroups::createCgroup(hierarchy, "test").isSome());
 
-  result = cgroups::createCgroup(hierarchy, "test");
-  ASSERT_TRUE(result.isSome());
+  EXPECT_TRUE(cgroups::removeCgroup(hierarchy, "invalid").isError());
 
-  result = cgroups::removeCgroup(hierarchy, "invalid");
-  EXPECT_TRUE(result.isError());
-
-  result = cgroups::removeCgroup(hierarchy, "test");
-  ASSERT_TRUE(result.isSome());
+  ASSERT_TRUE(cgroups::removeCgroup(hierarchy, "test").isSome());
 
-  result = cgroups::removeHierarchy(hierarchy);
-  ASSERT_TRUE(result.isSome());
+  ASSERT_TRUE(cgroups::removeHierarchy(hierarchy).isSome());
 }
 
 
@@ -333,14 +298,14 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_ReadCon
 
 TEST_F(CgroupsTest, ROOT_CGROUPS_WriteControl)
 {
-  Try<bool> result = false;
   std::string pid = stringify(::getpid());
 
-  result = cgroups::writeControl(hierarchy, "/prof", "invalid", "invalid");
-  EXPECT_TRUE(result.isError());
+  EXPECT_TRUE(cgroups::writeControl(hierarchy,
+                                    "/prof",
+                                    "invalid",
+                                    "invalid").isError());
 
-  result = cgroups::writeControl(hierarchy, "/prof", "tasks", pid);
-  ASSERT_TRUE(result.isSome());
+  ASSERT_TRUE(cgroups::writeControl(hierarchy, "/prof", "tasks", pid).isSome());
 
   Try<std::set<pid_t> > tasks = cgroups::getTasks(hierarchy, "/prof");
   ASSERT_TRUE(tasks.isSome());
@@ -348,8 +313,7 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_WriteCo
   std::set<pid_t> pids = tasks.get();
   EXPECT_NE(pids.find(::getpid()), pids.end());
 
-  result = cgroups::writeControl(hierarchy, "/", "tasks", pid);
-  ASSERT_TRUE(result.isSome());
+  ASSERT_TRUE(cgroups::writeControl(hierarchy, "/", "tasks", pid).isSome());
 }
 
 
@@ -392,19 +356,17 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_GetTask
 TEST_F(CgroupsTest, ROOT_CGROUPS_ListenEvent)
 {
   // Disable oom killer.
-  Try<bool> disableResult = cgroups::writeControl(hierarchy,
-                                                  "/prof",
-                                                  "memory.oom_control",
-                                                  "1");
-  ASSERT_TRUE(disableResult.isSome());
+  ASSERT_TRUE(cgroups::writeControl(hierarchy,
+                                    "/prof",
+                                    "memory.oom_control",
+                                    "1").isSome());
 
   // Limit the memory usage of "/prof" to 64MB.
   size_t limit = 1024 * 1024 * 64;
-  Try<bool> writeResult = cgroups::writeControl(hierarchy,
-                                                "/prof",
-                                                "memory.limit_in_bytes",
-                                                stringify(limit));
-  ASSERT_TRUE(writeResult.isSome());
+  ASSERT_TRUE(cgroups::writeControl(hierarchy,
+                                    "/prof",
+                                    "memory.limit_in_bytes",
+                                    stringify(limit)).isSome());
 
   // Listen on oom events for "/prof" cgroup.
   Future<uint64_t> future =
@@ -440,9 +402,9 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_ListenE
   } else {
     // In child process. We try to trigger an oom here.
     // Put self into the "/prof" cgroup.
-    Try<bool> assignResult = cgroups::assignTask(hierarchy,
-                                                 "/prof",
-                                                 ::getpid());
+    Try<Nothing> assignResult = cgroups::assignTask(hierarchy,
+                                                    "/prof",
+                                                    ::getpid());
     if (assignResult.isError()) {
       FAIL() << "Failed to assign cgroup: " << assignResult.error();
     }
@@ -501,9 +463,9 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_Freezer
     close(pipes[0]);
 
     // Put self into the "/prof" cgroup.
-    Try<bool> assign = cgroups::assignTask(hierarchy,
-                                           "/prof",
-                                           ::getpid());
+    Try<Nothing> assign = cgroups::assignTask(hierarchy,
+                                              "/prof",
+                                              ::getpid());
     if (assign.isError()) {
       FAIL() << "Failed to assign cgroup: " << assign.error();
     }
@@ -556,7 +518,7 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_KillTas
     ::fork();
 
     // Put self into "/prof" cgroup.
-    Try<bool> assign = cgroups::assignTask(hierarchy, "/prof", ::getpid());
+    Try<Nothing> assign = cgroups::assignTask(hierarchy, "/prof", ::getpid());
     if (assign.isError()) {
       FAIL() << "Failed to assign cgroup: " << assign.error();
     }
@@ -617,7 +579,7 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_Destroy
     ::fork();
 
     // Put self into "/prof" cgroup.
-    Try<bool> assign = cgroups::assignTask(hierarchy, "/prof", ::getpid());
+    Try<Nothing> assign = cgroups::assignTask(hierarchy, "/prof", ::getpid());
     if (assign.isError()) {
       FAIL() << "Failed to assign cgroup: " << assign.error();
     }

Modified: incubator/mesos/trunk/src/tests/configurator_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/configurator_tests.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/configurator_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/configurator_tests.cpp Wed Sep 19 00:08:13 2012
@@ -130,11 +130,11 @@ TEST(ConfiguratorTest, CommandLine)
 // Check whether specifying just MESOS_CONF allows a config file to be loaded
 TEST_WITH_WORKDIR(ConfiguratorTest, ConfigFileWithConfDir)
 {
-  ASSERT_TRUE(os::mkdir("conf2"));
+  ASSERT_TRUE(os::mkdir("conf2").isSome());
   ASSERT_TRUE(os::write("conf2/mesos.conf",
                         "test3=shake # sugar bomb\n"
                         "# just a comment\n"
-                        "test4=milk\n").get());
+                        "test4=milk\n").isSome());
 
   setenv("MESOS_CONF", "conf2", 1);
   Configurator conf;
@@ -150,12 +150,12 @@ TEST_WITH_WORKDIR(ConfiguratorTest, Conf
 // we load values from the config file first and then the command line
 TEST_WITH_WORKDIR(ConfiguratorTest, CommandLineConfFlag)
 {
-  ASSERT_TRUE(os::mkdir("bin"));
-  ASSERT_TRUE(os::mkdir("conf2"));
+  ASSERT_TRUE(os::mkdir("bin").isSome());
+  ASSERT_TRUE(os::mkdir("conf2").isSome());
   ASSERT_TRUE(os::write("conf2/mesos.conf",
                         "a=1\n"
                         "b=2\n"
-                        "c=3").get());
+                        "c=3").isSome());
 
   const int ARGC = 4;
   char* argv[ARGC];
@@ -180,13 +180,13 @@ TEST_WITH_WORKDIR(ConfiguratorTest, Comm
 // second should be environment variables, and last should be the file.
 TEST_WITH_WORKDIR(ConfiguratorTest, LoadingPriorities)
 {
-  ASSERT_TRUE(os::mkdir("bin"));
-  ASSERT_TRUE(os::mkdir("conf"));
+  ASSERT_TRUE(os::mkdir("bin").isSome());
+  ASSERT_TRUE(os::mkdir("conf").isSome());
   ASSERT_TRUE(os::write("conf/mesos.conf",
                         "a=fromFile\n"
                         "b=fromFile\n"
                         "c=fromFile\n"
-                        "d=fromFile\n").get());
+                        "d=fromFile\n").isSome());
 
   // Set environment to contain parameters a and b
   setenv("MESOS_A", "fromEnv", 1);
@@ -220,7 +220,7 @@ TEST_WITH_WORKDIR(ConfiguratorTest, Load
 // Check that spaces before and after the = signs in config files are ignored
 TEST_WITH_WORKDIR(ConfiguratorTest, ConfigFileSpacesIgnored)
 {
-  ASSERT_TRUE(os::mkdir("conf"));
+  ASSERT_TRUE(os::mkdir("conf").isSome());
   ASSERT_TRUE(os::write("conf/mesos.conf",
                         "test1=coffee # beans are tasty\n"
                         "# just a comment\n"
@@ -230,7 +230,7 @@ TEST_WITH_WORKDIR(ConfiguratorTest, Conf
                         "test3=  water\n"
                         "   test4 =  milk\n"
                         "  test5 =  hot  chocolate\t\n"
-                        "\ttest6 =  juice# #\n").get());
+                        "\ttest6 =  juice# #\n").isSome());
 
   Configurator conf;
   setenv("MESOS_CONF", "conf", 1);
@@ -249,11 +249,11 @@ TEST_WITH_WORKDIR(ConfiguratorTest, Conf
 // Check that exceptions are thrown on invalid config file
 TEST_WITH_WORKDIR(ConfiguratorTest, MalformedConfigFile)
 {
-  ASSERT_TRUE(os::mkdir("conf"));
+  ASSERT_TRUE(os::mkdir("conf").isSome());
   ASSERT_TRUE(os::write("conf/mesos.conf",
                         "test1=coffee\n"
                         "JUNK\n"
-                        "test2=tea\n").get());
+                        "test2=tea\n").isSome());
 
   setenv("MESOS_CONF", "conf", 1);
   Configurator conf;

Modified: incubator/mesos/trunk/src/tests/files_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/files_tests.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/files_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/files_tests.cpp Wed Sep 19 00:08:13 2012
@@ -44,16 +44,15 @@ using process::http::Response;
 TEST_WITH_WORKDIR(FilesTest, AttachTest)
 {
   Files files;
-
-  ASSERT_TRUE(os::write("file", "body").get());
-  ASSERT_TRUE(os::mkdir("dir"));
+  ASSERT_TRUE(os::write("file", "body").isSome());
+  ASSERT_TRUE(os::mkdir("dir").isSome());
 
   EXPECT_FUTURE_WILL_SUCCEED(files.attach("file", "myname"));   // Valid file.
   EXPECT_FUTURE_WILL_SUCCEED(files.attach("dir", "mydir"));     // Valid dir.
   EXPECT_FUTURE_WILL_SUCCEED(files.attach("file", "myname"));   // Re-attach.
   EXPECT_FUTURE_WILL_FAIL(files.attach("missing", "somename")); // Missing file.
 
-  ASSERT_TRUE(os::write("file2", "body").get());
+  ASSERT_TRUE(os::write("file2", "body").isSome());
 
   EXPECT_FUTURE_WILL_SUCCEED(files.attach("file2", "myname"));  // Overwrite.
   EXPECT_FUTURE_WILL_FAIL(files.attach("$@", "foo"));           // Bad path.
@@ -64,7 +63,7 @@ TEST_WITH_WORKDIR(FilesTest, DetachTest)
 {
   Files files;
 
-  ASSERT_TRUE(os::write("file", "body").get());
+  ASSERT_TRUE(os::write("file", "body").isSome());
   EXPECT_FUTURE_WILL_SUCCEED(files.attach("file", "myname"));
 
   files.detach("myname");
@@ -98,7 +97,7 @@ TEST_WITH_WORKDIR(FilesTest, ReadTest)
       response);
 
   // Now write a file.
-  ASSERT_TRUE(os::write("file", "body").get());
+  ASSERT_TRUE(os::write("file", "body").isSome());
   EXPECT_FUTURE_WILL_SUCCEED(files.attach("file", "/myname"));
   EXPECT_FUTURE_WILL_SUCCEED(files.attach("file", "myname"));
 
@@ -131,9 +130,9 @@ TEST_WITH_WORKDIR(FilesTest, ResolveTest
   const process::PID<>& pid = files.pid();
 
   // Test the directory / file resolution.
-  ASSERT_TRUE(os::mkdir("1/2"));
-  ASSERT_TRUE(os::write("1/two", "two").get());
-  ASSERT_TRUE(os::write("1/2/three", "three").get());
+  ASSERT_TRUE(os::mkdir("1/2").isSome());
+  ASSERT_TRUE(os::write("1/two", "two").isSome());
+  ASSERT_TRUE(os::write("1/2/three", "three").isSome());
 
   // Attach some paths.
   EXPECT_FUTURE_WILL_SUCCEED(files.attach("1", "one"));
@@ -191,10 +190,10 @@ TEST_WITH_WORKDIR(FilesTest, BrowseTest)
   Files files;
   const process::PID<>& pid = files.pid();
 
-  ASSERT_TRUE(os::mkdir("1/2"));
-  ASSERT_TRUE(os::mkdir("1/3"));
-  ASSERT_TRUE(os::write("1/two", "two").get());
-  ASSERT_TRUE(os::write("1/three", "three").get());
+  ASSERT_TRUE(os::mkdir("1/2").isSome());
+  ASSERT_TRUE(os::mkdir("1/3").isSome());
+  ASSERT_TRUE(os::write("1/two", "two").isSome());
+  ASSERT_TRUE(os::write("1/three", "three").isSome());
 
   EXPECT_FUTURE_WILL_SUCCEED(files.attach("1", "one"));
 

Modified: incubator/mesos/trunk/src/tests/stout_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/stout_tests.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/stout_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/stout_tests.cpp Wed Sep 19 00:08:13 2012
@@ -353,37 +353,31 @@ TEST_F(StoutUtilsTest, nonblock)
   int pipes[2];
   ASSERT_NE(-1, pipe(pipes));
 
-  Try<bool> result = false;
+  Try<bool> isNonBlock = false;
 
-  result = os::isNonblock(pipes[0]);
-  ASSERT_TRUE(result.isSome());
-  EXPECT_FALSE(result.get());
+  isNonBlock = os::isNonblock(pipes[0]);
+  ASSERT_TRUE(isNonBlock.isSome());
+  EXPECT_FALSE(isNonBlock.get());
 
-  result = os::nonblock(pipes[0]);
-  ASSERT_TRUE(result.isSome());
-  EXPECT_TRUE(result.get());
+  ASSERT_TRUE(os::nonblock(pipes[0]).isSome());
 
-  result = os::isNonblock(pipes[0]);
-  ASSERT_TRUE(result.isSome());
-  EXPECT_TRUE(result.get());
+  isNonBlock = os::isNonblock(pipes[0]);
+  ASSERT_TRUE(isNonBlock.isSome());
+  EXPECT_TRUE(isNonBlock.get());
 
   close(pipes[0]);
   close(pipes[1]);
 
-  result = os::nonblock(pipes[0]);
-  EXPECT_TRUE(result.isError());
-
-  result = os::isNonblock(pipes[0]);
-  EXPECT_TRUE(result.isError());
+  EXPECT_TRUE(os::nonblock(pipes[0]).isError());
+  EXPECT_TRUE(os::nonblock(pipes[0]).isError());
 }
 
 
 TEST_F(StoutUtilsTest, touch)
 {
   const std::string& testfile  = tmpdir + "/" + UUID::random().toString();
-  Try<bool> result = os::touch(testfile);
 
-  ASSERT_TRUE(result.get());
+  ASSERT_TRUE(os::touch(testfile).isSome());
   ASSERT_TRUE(os::exists(testfile));
 }
 
@@ -393,8 +387,7 @@ TEST_F(StoutUtilsTest, readWriteString)
   const std::string& testfile  = tmpdir + "/" + UUID::random().toString();
   const std::string& teststr = "test";
 
-  Try<bool> result = os::write(testfile, teststr);
-  ASSERT_TRUE(result.get());
+  ASSERT_TRUE(os::write(testfile, teststr).isSome());
 
   Result<std::string> readstr = os::read(testfile);
 
@@ -407,16 +400,16 @@ TEST_F(StoutUtilsTest, find)
 {
   const std::string& testdir  = tmpdir + "/" + UUID::random().toString();
   const std::string& subdir = testdir + "/test1";
-  ASSERT_TRUE(os::mkdir(subdir)); // Create the directories.
+  ASSERT_TRUE(os::mkdir(subdir).isSome()); // Create the directories.
 
   // Now write some files.
   const std::string& file1 = testdir + "/file1.txt";
   const std::string& file2 = subdir + "/file2.txt";
   const std::string& file3 = subdir + "/file3.jpg";
 
-  ASSERT_TRUE(os::touch(file1).get());
-  ASSERT_TRUE(os::touch(file2).get());
-  ASSERT_TRUE(os::touch(file3).get());
+  ASSERT_TRUE(os::touch(file1).isSome());
+  ASSERT_TRUE(os::touch(file2).isSome());
+  ASSERT_TRUE(os::touch(file3).isSome());
 
   // Find "*.txt" files.
   Try<std::list<std::string> > result = os::find(testdir, ".txt");

Modified: incubator/mesos/trunk/src/tests/zookeeper_server.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/zookeeper_server.hpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/zookeeper_server.hpp (original)
+++ incubator/mesos/trunk/src/tests/zookeeper_server.hpp Wed Sep 19 00:08:13 2012
@@ -73,8 +73,10 @@ private:
     ~TemporaryDirectory()
     {
       jvm->deleteGlobalRef(file);
-      if (!os::rmdir(path)) {
-        LOG(WARNING) << "Failed to delete temp dir: " << path;
+      Try<Nothing> rmdir = os::rmdir(path);
+      if (rmdir.isError()) {
+        LOG(WARNING) << "Failed to delete temp dir '"
+                     << path << "': " << rmdir.error();
       }
     }
   };

Modified: incubator/mesos/trunk/src/webui/webui.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/webui/webui.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/src/webui/webui.cpp (original)
+++ incubator/mesos/trunk/src/webui/webui.cpp Wed Sep 19 00:08:13 2012
@@ -107,13 +107,13 @@ void start(const std::string& directory,
   }
 
   // Set the FD_CLOEXEC flags on these pipes
-  Try<bool> result = os::cloexec(pipes[0]);
-  CHECK(result.isSome()) << "Error setting FD_CLOEXEC on pipe[0] "
-                         << result.error();
-
-  result = os::cloexec(pipes[1]);
-  CHECK(result.isSome()) << "Error setting FD_CLOEXEC on pipe[1] "
-                         << result.error();
+  Try<Nothing> cloexec = os::cloexec(pipes[0]);
+  CHECK(cloexec.isSome()) << "Error setting FD_CLOEXEC on pipe[0] "
+                          << cloexec.error();
+
+  cloexec = os::cloexec(pipes[1]);
+  CHECK(cloexec.isSome()) << "Error setting FD_CLOEXEC on pipe[1] "
+                          << cloexec.error();
 
   pid_t pid;
   if ((pid = fork()) == -1) {

Modified: incubator/mesos/trunk/third_party/libprocess/include/stout/os.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/stout/os.hpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/stout/os.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/stout/os.hpp Wed Sep 19 00:08:13 2012
@@ -29,6 +29,7 @@
 #include <string>
 
 #include "foreach.hpp"
+#include "nothing.hpp"
 #include "result.hpp"
 #include "strings.hpp"
 #include "try.hpp"
@@ -112,43 +113,45 @@ inline Try<int> open(const std::string& 
 }
 
 
-inline Try<bool> close(int fd)
+inline Try<Nothing> close(int fd)
 {
   if (::close(fd) != 0) {
-    return Try<bool>::error(strerror(errno));
+    return Try<Nothing>::error(strerror(errno));
   }
 
-  return true;
+  return Nothing();
 }
 
 
-inline Try<bool> cloexec(int fd)
+inline Try<Nothing> cloexec(int fd)
 {
   int flags = ::fcntl(fd, F_GETFD);
+
   if (flags == -1) {
-    return Try<bool>::error(strerror(errno));
+    return Try<Nothing>::error(strerror(errno));
   }
+
   if (::fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) {
-    return Try<bool>::error(strerror(errno));;
+    return Try<Nothing>::error(strerror(errno));;
   }
-  return true;
+
+  return Nothing();
 }
 
 
-// TODO(bmahler): Refactor this and others into Try<Nothing> as appropriate.
-inline Try<bool> nonblock(int fd)
+inline Try<Nothing> nonblock(int fd)
 {
   int flags = ::fcntl(fd, F_GETFL);
 
   if (flags == -1) {
-    return Try<bool>::error(strerror(errno));
+    return Try<Nothing>::error(strerror(errno));
   }
 
   if (::fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
-    return Try<bool>::error(strerror(errno));
+    return Try<Nothing>::error(strerror(errno));
   }
 
-  return true;
+  return Nothing();
 }
 
 
@@ -164,59 +167,52 @@ inline Try<bool> isNonblock(int fd)
 }
 
 
-inline Try<bool> touch(const std::string& path)
+inline Try<Nothing> touch(const std::string& path)
 {
   Try<int> fd =
       open(path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IRWXO);
 
   if (fd.isError()) {
-    return Try<bool>::error("Failed to open file " + path);
+    return Try<Nothing>::error("Failed to open file " + path);
   }
 
   // TODO(benh): Is opening/closing sufficient to have the same
   // semantics as the touch utility (i.e., doesn't the utility change
   // the modified date)?
-
-  Try<bool> result = close(fd.get());
-
-  if (result.isError()) {
-    return Try<bool>::error("Failed to close file " + path);
-  }
-
-  return true;
+  return close(fd.get());
 }
 
 
 // Write out the string to the file at the current fd position.
-inline Try<bool> write(int fd, const std::string& message)
+inline Try<Nothing> write(int fd, const std::string& message)
 {
   ssize_t length = ::write(fd, message.data(), message.length());
 
   if (length == -1) {
-    return Try<bool>::error(strerror(errno));
+    return Try<Nothing>::error(strerror(errno));
   }
 
   CHECK(length > 0);
   // TODO(benh): Handle a non-blocking fd?
   CHECK(static_cast<size_t>(length) == message.length());
 
-  return true;
+  return Nothing();
 }
 
 
 // A wrapper function that wraps the above write() with
 // open and closing the file.
-inline Try<bool> write(const std::string& path,
+inline Try<Nothing> write(const std::string& path,
                        const std::string& message)
 {
   Try<int> fd = os::open(path, O_WRONLY | O_CREAT | O_TRUNC,
                          S_IRUSR | S_IWUSR | S_IRGRP | S_IRWXO);
   if (fd.isError()) {
-    return Try<bool>::error("Failed to open file " + path + " : " +
+    return Try<Nothing>::error("Failed to open file " + path + " : " +
         strerror(errno));
   }
 
-  Try<bool> result = write(fd.get(), message);
+  Try<Nothing> result = write(fd.get(), message);
 
   // NOTE: We ignore the return value of close(). This is because users calling
   // this function are interested in the return value of write(). Also an
@@ -288,13 +284,13 @@ inline Result<std::string> read(const st
 }
 
 
-inline Try<bool> rm(const std::string& path)
+inline Try<Nothing> rm(const std::string& path)
 {
   if (::remove(path.c_str()) != 0) {
-    return Try<bool>::error(strerror(errno));
+    return Try<Nothing>::error(strerror(errno));
   }
 
-  return true;
+  return Nothing();
 }
 
 
@@ -368,7 +364,7 @@ inline Try<long> mtime(const std::string
 }
 
 
-inline bool mkdir(const std::string& directory)
+inline Try<Nothing> mkdir(const std::string& directory)
 {
   try {
     std::vector<std::string> tokens = strings::tokenize(directory, "/");
@@ -382,39 +378,43 @@ inline bool mkdir(const std::string& dir
     foreach (const std::string& token, tokens) {
       path += token;
       if (::mkdir(path.c_str(), 0755) < 0 && errno != EEXIST) {
-        PLOG(ERROR) << "Failed to make directory, mkdir";
-        return false;
+        return Try<Nothing>::error(
+            std::string("Failed to mkdir: ") + strerror(errno));
       }
       path += "/";
     }
   } catch (...) {
-    return false;
+    return Try<Nothing>::error("");
   }
 
-  return true;
+  return Nothing();
 }
 
 
 // Recursively deletes a directory akin to: 'rm -r'. Note that this
 // function expects an absolute path.
-inline bool rmdir(const std::string& directory)
+inline Try<Nothing> rmdir(const std::string& directory)
 {
   char* paths[] = {const_cast<char*>(directory.c_str()), NULL};
 
   FTS* tree = fts_open(paths, FTS_NOCHDIR, NULL);
   if (tree == NULL) {
-    return false;
+    return Try<Nothing>::error(strerror(errno));
   }
 
   FTSENT* node;
   while ((node = fts_read(tree)) != NULL) {
     switch (node->fts_info) {
       case FTS_DP:
-        ::rmdir(node->fts_path);
+        if (::rmdir(node->fts_path) < 0 && errno != ENOENT) {
+          return Try<Nothing>::error(strerror(errno));
+        }
         break;
       case FTS_F:
       case FTS_SL:
-        ::unlink(node->fts_path);
+        if (::unlink(node->fts_path) < 0 && errno != ENOENT) {
+          return Try<Nothing>::error(strerror(errno));
+        }
         break;
       default:
         break;
@@ -422,13 +422,18 @@ inline bool rmdir(const std::string& dir
   }
 
   if (errno != 0) {
-    return false;
+    return Try<Nothing>::error(strerror(errno));
+  }
+
+  if (fts_close(tree) < 0) {
+    return Try<Nothing>::error(strerror(errno));
   }
 
-  return fts_close(tree) == 0;
+  return Nothing();
 }
 
 
+// TODO(bmahler): Clean these bool functions to return Try<Nothing>.
 // Changes the specified path's user and group ownership to that of
 // the specified user..
 inline bool chown(const std::string& user, const std::string& path)

Modified: incubator/mesos/trunk/third_party/libprocess/include/stout/try.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/stout/try.hpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/stout/try.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/stout/try.hpp Wed Sep 19 00:08:13 2012
@@ -76,54 +76,4 @@ private:
 };
 
 
-template <>
-class Try<void>
-{
-public:
-  static Try<void> some()
-  {
-    return Try<void>(SOME);
-  }
-
-  static Try<void> error(const std::string& message)
-  {
-    return Try<void>(ERROR, message);
-  }
-
-  Try(const Try<void>& that)
-  {
-    state = that.state;
-    message = that.message;
-  }
-
-  ~Try() {}
-
-  Try<void>& operator = (const Try<void>& that)
-  {
-    if (this != &that) {
-      state = that.state;
-      message = that.message;
-    }
-
-    return *this;
-  }
-
-  bool isSome() const { return state == SOME; }
-  bool isError() const { return state == ERROR; }
-
-  std::string error() const { assert(state == ERROR); return message; }
-
-private:
-  enum State {
-    SOME,
-    ERROR
-  };
-
-  Try(State _state, const std::string& _message = "")
-    : state(_state), message(_message) {}
-
-  State state;
-  std::string message;
-};
-
 #endif // __STOUT_TRY_HPP__

Modified: incubator/mesos/trunk/third_party/libprocess/src/process.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/process.cpp?rev=1387409&r1=1387408&r2=1387409&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/process.cpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/process.cpp Wed Sep 19 00:08:13 2012
@@ -1,6 +1,5 @@
 #include <errno.h>
 #include <ev.h>
-#include <fcntl.h>
 #include <limits.h>
 #include <libgen.h>
 #include <netdb.h>
@@ -634,25 +633,6 @@ void Clock::settle()
 }
 
 
-// TODO(bmahler): Kill this in favor of os::nonblock().
-int set_nbio(int fd)
-{
-  int flags;
-
-  /* If they have O_NONBLOCK, use the Posix way to do it. */
-#ifdef O_NONBLOCK
-  /* TODO(*): O_NONBLOCK is defined but broken on SunOS 4.1.x and AIX 3.2.5. */
-  if (-1 == (flags = fcntl(fd, F_GETFL, 0)))
-    flags = 0;
-  return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
-#else
-  /* Otherwise, use the old way of doing it. */
-  flags = 1;
-  return ioctl(fd, FIOBIO, &flags);
-#endif
-}
-
-
 static Message* encode(const UPID& from,
                        const UPID& to,
                        const string& name,
@@ -1107,14 +1087,18 @@ void accept(struct ev_loop* loop, ev_io*
     return;
   }
 
-  if (set_nbio(s) < 0) {
-    PLOG_IF(INFO, VLOG_IS_ON(1)) << "Failed to accept, set_nbio";
+  Try<Nothing> nonblock = os::nonblock(s);
+  if (nonblock.isError()) {
+    LOG_IF(INFO, VLOG_IS_ON(1)) << "Failed to accept, nonblock: "
+                                << nonblock.error();
     close(s);
     return;
   }
 
-  if (fcntl(s, F_SETFD, FD_CLOEXEC)) {
-    PLOG_IF(INFO, VLOG_IS_ON(1)) << "Failed to accept, FD_CLOEXEC";
+  Try<Nothing> cloexec = os::cloexec(s);
+  if (cloexec.isError()) {
+    LOG_IF(INFO, VLOG_IS_ON(1)) << "Failed to accept, cloexec: "
+                                << cloexec.error();
     close(s);
     return;
   }
@@ -1293,13 +1277,15 @@ void initialize(const string& delegate)
   }
 
   // Make socket non-blocking.
-  if (set_nbio(__s__) < 0) {
-    PLOG(FATAL) << "Failed to initialize, set_nbio";
+  Try<Nothing> nonblock = os::nonblock(__s__);
+  if (nonblock.isError()) {
+    LOG(FATAL) << "Failed to initialize, nonblock: " << nonblock.error();
   }
 
   // Set FD_CLOEXEC flag.
-  if (fcntl(__s__, F_SETFD, FD_CLOEXEC)) {
-    PLOG(FATAL) << "Failed to initialize, FD_CLOEXEC";
+  Try<Nothing> cloexec = os::cloexec(__s__);
+  if (cloexec.isError()) {
+    LOG(FATAL) << "Failed to initialize, cloexec: " << cloexec.error();
   }
 
   // Allow address reuse.
@@ -1630,12 +1616,14 @@ void SocketManager::link(ProcessBase* pr
         PLOG(FATAL) << "Failed to link, socket";
       }
 
-      if (set_nbio(s) < 0) {
-        PLOG(FATAL) << "Failed to link, set_nbio";
+      Try<Nothing> nonblock = os::nonblock(s);
+      if (nonblock.isError()) {
+        LOG(FATAL) << "Failed to link, nonblock: " << nonblock.error();
       }
 
-      if (fcntl(s, F_SETFD, FD_CLOEXEC)) {
-        PLOG(FATAL) << "Failed to link, FD_CLOEXEC";
+      Try<Nothing> cloexec = os::cloexec(s);
+      if (cloexec.isError()) {
+        LOG(FATAL) << "Failed to link, cloexec: " << cloexec.error();
       }
 
       Socket socket = Socket(s);
@@ -1785,12 +1773,14 @@ void SocketManager::send(Message* messag
         PLOG(FATAL) << "Failed to send, socket";
       }
 
-      if (set_nbio(s) < 0) {
-        PLOG(FATAL) << "Failed to send, set_nbio";
+      Try<Nothing> nonblock = os::nonblock(s);
+      if (nonblock.isError()) {
+        LOG(FATAL) << "Failed to send, nonblock: " << nonblock.error();
       }
 
-      if (fcntl(s, F_SETFD, FD_CLOEXEC)) {
-        PLOG(FATAL) << "Failed to send, FD_CLOEXEC";
+      Try<Nothing> cloexec = os::cloexec(s);
+      if (cloexec.isError()) {
+        LOG(FATAL) << "Failed to send, cloexec: " << cloexec.error();
       }
 
       sockets[s] = Socket(s);
@@ -3242,13 +3232,9 @@ Future<Response> get(const PID<>& pid, c
         string("Failed to create socket: ") + strerror(errno));
   }
 
-  Try<bool> cloexec = os::cloexec(s);
+  Try<Nothing> cloexec = os::cloexec(s);
   if (!cloexec.isSome()) {
-    return Future<Response>::failed(
-        string("Failed to cloexec: ") + cloexec.error());
-  } else if (!cloexec.get()) {
-    // TODO(bmahler): Never happens, refactor later into Try<Nothing>.
-    return Future<Response>::failed("Failed to cloexec");
+    return Future<Response>::failed("Failed to cloexec: " + cloexec.error());
   }
 
   sockaddr_in addr;
@@ -3285,13 +3271,10 @@ Future<Response> get(const PID<>& pid, c
     remaining -= n;
   }
 
-  Try<bool> nonblock = os::nonblock(s);
+  Try<Nothing> nonblock = os::nonblock(s);
   if (!nonblock.isSome()) {
     return Future<Response>::failed(
-        string("Failed to set nonblocking: ") + nonblock.error());
-  } else if (!nonblock.get()) {
-    // TODO(bmahler): Never happens, refactor later into Try<Nothing>.
-    return Future<Response>::failed("Failed to set nonblocking");
+        "Failed to set nonblock: " + nonblock.error());
   }
 
   // Decode once the async read completes.