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