2004-08-29 19:20:41 +00:00
|
|
|
//===-- Program.cpp - Implement OS Program Concept --------------*- C++ -*-===//
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2004-08-29 19:20:41 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2004-08-29 19:20:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This header file implements the operating system Program concept.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/Program.h"
|
2004-12-27 06:16:25 +00:00
|
|
|
#include "llvm/Config/config.h"
|
2011-12-13 23:16:49 +00:00
|
|
|
#include "llvm/Support/system_error.h"
|
2010-04-18 03:33:55 +00:00
|
|
|
using namespace llvm;
|
2004-08-29 19:20:41 +00:00
|
|
|
using namespace sys;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//=== WARNING: Implementation here must contain only TRULY operating system
|
2005-04-21 22:55:34 +00:00
|
|
|
//=== independent code.
|
2004-08-29 19:20:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-06-13 20:25:38 +00:00
|
|
|
static bool Execute(void **Data, StringRef Program, const char **args,
|
|
|
|
const char **env, const StringRef **Redirects,
|
2013-06-14 19:38:45 +00:00
|
|
|
unsigned memoryLimit, std::string *ErrMsg);
|
2013-06-13 20:06:28 +00:00
|
|
|
|
2013-06-13 20:25:38 +00:00
|
|
|
static int Wait(void *&Data, StringRef Program, unsigned secondsToWait,
|
2013-06-14 19:38:45 +00:00
|
|
|
std::string *ErrMsg);
|
2013-06-13 20:25:38 +00:00
|
|
|
|
|
|
|
int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,
|
|
|
|
const StringRef **redirects, unsigned secondsToWait,
|
2013-06-12 20:58:35 +00:00
|
|
|
unsigned memoryLimit, std::string *ErrMsg,
|
2013-03-26 23:35:00 +00:00
|
|
|
bool *ExecutionFailed) {
|
2013-06-13 14:39:07 +00:00
|
|
|
void *Data = 0;
|
2013-06-13 20:25:38 +00:00
|
|
|
if (Execute(&Data, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
|
2013-03-26 23:35:00 +00:00
|
|
|
if (ExecutionFailed) *ExecutionFailed = false;
|
2013-06-13 20:25:38 +00:00
|
|
|
return Wait(Data, Program, secondsToWait, ErrMsg);
|
2013-03-26 23:35:00 +00:00
|
|
|
}
|
|
|
|
if (ExecutionFailed) *ExecutionFailed = true;
|
|
|
|
return -1;
|
2009-07-18 21:43:12 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 20:25:38 +00:00
|
|
|
void sys::ExecuteNoWait(StringRef Program, const char **args, const char **envp,
|
|
|
|
const StringRef **redirects, unsigned memoryLimit,
|
2013-06-12 20:58:35 +00:00
|
|
|
std::string *ErrMsg) {
|
2013-06-13 20:25:38 +00:00
|
|
|
Execute(/*Data*/ 0, Program, args, envp, redirects, memoryLimit, ErrMsg);
|
2009-07-18 21:43:12 +00:00
|
|
|
}
|
|
|
|
|
2004-08-29 19:20:41 +00:00
|
|
|
// Include the platform-specific parts of this class.
|
2004-12-27 06:16:25 +00:00
|
|
|
#ifdef LLVM_ON_UNIX
|
2005-01-09 23:29:00 +00:00
|
|
|
#include "Unix/Program.inc"
|
2004-12-27 06:16:25 +00:00
|
|
|
#endif
|
|
|
|
#ifdef LLVM_ON_WIN32
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "Windows/Program.inc"
|
2004-12-27 06:16:25 +00:00
|
|
|
#endif
|