Skip to content

Commit

Permalink
Merge pull request #1500 from Sonicadvance1/rootfsfetch_check_curl
Browse files Browse the repository at this point in the history
FEXRootFSFetcher: Check if curl is installed and fail before running
  • Loading branch information
Sonicadvance1 authored Jan 11, 2022
2 parents 6022715 + 5a5a498 commit 784cbdd
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion Source/Tools/FEXRootFSFetcher/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,38 @@ namespace Exec {
int32_t Status{};
waitpid(pid, &Status, 0);
if (WIFEXITED(Status)) {
return WEXITSTATUS(Status);
return (int8_t)WEXITSTATUS(Status);
}
}

return -1;
}

int32_t ExecAndWaitForResponseRedirect(const char *path, char* const* args, int stdoutRedirect = STDOUT_FILENO, int stderrRedirect = STDERR_FILENO) {
pid_t pid = fork();
if (pid == 0) {
if (stdoutRedirect == -1) {
close(STDOUT_FILENO);
}
else if (stdoutRedirect != STDOUT_FILENO) {
close(STDOUT_FILENO);
dup2(stdoutRedirect, STDOUT_FILENO);
}
if (stderrRedirect == -1) {
close(STDERR_FILENO);
}
else if (stderrRedirect != STDOUT_FILENO) {
close(STDERR_FILENO);
dup2(stderrRedirect, STDERR_FILENO);
}
execvp(path, args);
_exit(-1);
}
else {
int32_t Status{};
waitpid(pid, &Status, 0);
if (WIFEXITED(Status)) {
return (int8_t)WEXITSTATUS(Status);
}
}

Expand Down Expand Up @@ -778,6 +809,19 @@ int main(int argc, char **argv, char **const envp) {
return 0;
}

// Check if curl exists on the host
std::vector<const char*> ExecveArgs = {
"curl",
"-V",
nullptr,
};

int32_t Result = Exec::ExecAndWaitForResponseRedirect(ExecveArgs[0], const_cast<char* const*>(ExecveArgs.data()), -1, -1);
if (Result == -1) {
ExecWithInfo("curl is required to use this tool. Please install curl before using.");
return -1;
}

FEX_CONFIG_OPT(LDPath, ROOTFS);

std::error_code ec;
Expand Down

0 comments on commit 784cbdd

Please sign in to comment.