Fix include ordering for OpenSSLPtrTypes.h
[folly.git] / folly / Subprocess.cpp
index d6883392c680054b54f7e93f101bce1d570a831d..6c04e91bddfb45b6eedbb3a44df944d5ab53f4f3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 #include <glog/logging.h>
 
+#include <folly/Assume.h>
 #include <folly/Conv.h>
 #include <folly/Exception.h>
 #include <folly/ScopeGuard.h>
+#include <folly/Shell.h>
 #include <folly/String.h>
 #include <folly/io/Cursor.h>
-#include <folly/portability/Environment.h>
 #include <folly/portability/Sockets.h>
+#include <folly/portability/Stdlib.h>
 #include <folly/portability/Unistd.h>
 
 constexpr int kExecFailure = 127;
@@ -105,8 +107,7 @@ std::string ProcessReturnCode::str() const {
     return to<std::string>("killed by signal ", killSignal(),
                            (coreDumped() ? " (core dumped)" : ""));
   }
-  CHECK(false);  // unreached
-  return "";  // silence GCC warning
+  assume_unreachable();
 }
 
 CalledProcessError::CalledProcessError(ProcessReturnCode rc)
@@ -183,26 +184,10 @@ Subprocess::Subprocess(
     throw std::invalid_argument("usePath() not allowed when running in shell");
   }
 
-  auto argv = Subprocess::shellify(cmd);
+  std::vector<std::string> argv = {"/bin/sh", "-c", cmd};
   spawn(cloneStrings(argv), argv[0].c_str(), options, env);
 }
 
-/* static */ std::vector<std::string> Subprocess::shellify(
-    const std::string& cmd) {
-  std::vector<std::string> argv;
-
-  const char* shell = getenv("SHELL");
-  if (!shell) {
-    shell = "/bin/sh";
-  }
-
-  argv.push_back(shell);
-  argv.push_back("-c");
-  argv.push_back(cmd);
-
-  return argv;
-}
-
 Subprocess::~Subprocess() {
   CHECK_NE(returnCode_.state(), ProcessReturnCode::RUNNING)
     << "Subprocess destroyed without reaping child";