param: shell: fix unused variable warning

pull/1290/head
flightlessmango 1 month ago
parent fb0b559d04
commit cdd8043489

@ -2,6 +2,7 @@
#include <thread> #include <thread>
#include <iostream> #include <iostream>
#include <sys/wait.h> #include <sys/wait.h>
#include <spdlog/spdlog.h>
std::string Shell::readOutput() { std::string Shell::readOutput() {
std::string output; std::string output;
@ -37,8 +38,22 @@ std::string Shell::readOutput() {
} }
Shell::Shell() { Shell::Shell() {
pipe(to_shell); static bool failed;
pipe(from_shell); if (pipe(to_shell) == -1) {
SPDLOG_ERROR("Failed to create to_shell pipe: {}", strerror(errno));
failed = true;
}
if (pipe(from_shell) == -1) {
SPDLOG_ERROR("Failed to create from_shell pipe: {}", strerror(errno));
failed = true;
}
// if either pipe fails, there's no point in continuing.
if (failed){
SPDLOG_ERROR("Shell has failed, will not be able to use exec");
return;
}
shell_pid = fork(); shell_pid = fork();
@ -58,9 +73,13 @@ Shell::Shell() {
// Set the read end of the from_shell pipe to non-blocking // Set the read end of the from_shell pipe to non-blocking
setNonBlocking(from_shell[0]); setNonBlocking(from_shell[0]);
} }
success = true;
} }
std::string Shell::exec(std::string cmd) { std::string Shell::exec(std::string cmd) {
if (!success)
return "";
writeCommand(cmd); writeCommand(cmd);
return readOutput(); return readOutput();
} }

@ -13,6 +13,7 @@ private:
int to_shell[2]; int to_shell[2];
int from_shell[2]; int from_shell[2];
pid_t shell_pid; pid_t shell_pid;
bool success;
#ifdef __linux__ #ifdef __linux__
void setNonBlocking(int fd) { void setNonBlocking(int fd) {

Loading…
Cancel
Save