mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-16 22:26:16 +00:00
Fix ExecFile waitpid error handling.
This commit is contained in:
+15
-9
@@ -1,6 +1,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
#include <cstring>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -18,7 +19,7 @@ namespace rpc {
|
|||||||
|
|
||||||
int
|
int
|
||||||
ExecFile::execute(const char* file, char* const* argv, int flags) {
|
ExecFile::execute(const char* file, char* const* argv, int flags) {
|
||||||
// Write the execued command and its parameters to the log fd.
|
// Write the executed command and its parameters to the log fd.
|
||||||
[[maybe_unused]] int result;
|
[[maybe_unused]] int result;
|
||||||
|
|
||||||
if (m_log_fd != -1) {
|
if (m_log_fd != -1) {
|
||||||
@@ -117,18 +118,23 @@ ExecFile::execute(const char* file, char* const* argv, int flags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int status;
|
int status;
|
||||||
int wpid;
|
|
||||||
|
|
||||||
do {
|
while (waitpid(childPid, &status, 0) == -1) {
|
||||||
wpid = waitpid(childPid, &status, 0);
|
switch (errno) {
|
||||||
} while (wpid == -1 && WIFEXITED(status) == 0);
|
case EINTR:
|
||||||
|
continue;
|
||||||
if (wpid != childPid)
|
case ECHILD:
|
||||||
throw torrent::internal_error("ExecFile::execute(...) waitpid failed.");
|
throw torrent::internal_error("ExecFile::execute(...) waitpid failed with ECHILD, child process not found.");
|
||||||
|
case EINVAL:
|
||||||
|
throw torrent::internal_error("ExecFile::execute(...) waitpid failed with EINVAL.");
|
||||||
|
default:
|
||||||
|
throw torrent::internal_error("ExecFile::execute(...) waitpid failed with unexpected error: " + std::string(std::strerror(errno)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Check return value?
|
// Check return value?
|
||||||
if (m_log_fd != -1) {
|
if (m_log_fd != -1) {
|
||||||
if (status == 0)
|
if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
|
||||||
result = write(m_log_fd, "\n--- Success ---\n", sizeof("\n--- Success ---\n"));
|
result = write(m_log_fd, "\n--- Success ---\n", sizeof("\n--- Success ---\n"));
|
||||||
else
|
else
|
||||||
result = write(m_log_fd, "\n--- Error ---\n", sizeof("\n--- Error ---\n"));
|
result = write(m_log_fd, "\n--- Error ---\n", sizeof("\n--- Error ---\n"));
|
||||||
|
|||||||
Reference in New Issue
Block a user