2018-09-06 13:47:33 +00:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2017-2018, U.S. Government
|
|
|
|
*/
|
|
|
|
#ifndef HIRS_PROVISIONERTPM2_INCLUDE_PROCESS_H_
|
|
|
|
#define HIRS_PROVISIONERTPM2_INCLUDE_PROCESS_H_
|
|
|
|
|
|
|
|
#include "Logger.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace hirs {
|
|
|
|
namespace utils {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Process class represents a Linux process, its return value,
|
|
|
|
* and the standard output stream.
|
|
|
|
*/
|
|
|
|
class Process {
|
|
|
|
private:
|
|
|
|
static const hirs::log::Logger LOGGER;
|
|
|
|
|
2018-11-26 21:45:22 +00:00
|
|
|
static const char* const kPgrepCommand;
|
|
|
|
static const int kMaxStatFileProcessNameLength;
|
|
|
|
|
2018-09-06 13:47:33 +00:00
|
|
|
std::string executable;
|
|
|
|
|
|
|
|
std::string arguments;
|
|
|
|
|
|
|
|
std::string output;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit Process(const std::string& executable,
|
|
|
|
const std::string& arguments = "");
|
|
|
|
|
|
|
|
int run();
|
|
|
|
|
|
|
|
int run(std::ostream& osForErrorLogging);
|
|
|
|
|
|
|
|
std::string getOutputString() const;
|
|
|
|
|
|
|
|
static std::string run(const std::string& executable,
|
2018-12-11 18:27:24 +00:00
|
|
|
const std::string& arguments,
|
|
|
|
const std::string& sourceFileName,
|
|
|
|
int sourceLineNumber);
|
2018-11-26 21:45:22 +00:00
|
|
|
|
2021-05-25 13:05:21 +00:00
|
|
|
static std::string runData(const std::string& executable,
|
|
|
|
const std::string& arguments,
|
|
|
|
const std::string& sourceFileName,
|
|
|
|
int sourceLineNumber);
|
|
|
|
|
2018-11-26 21:45:22 +00:00
|
|
|
static bool isRunning(const std::string& executable);
|
2018-09-06 13:47:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace utils
|
|
|
|
} // namespace hirs
|
|
|
|
|
|
|
|
#endif // HIRS_PROVISIONERTPM2_INCLUDE_PROCESS_H_
|