fix linux exit finished
This commit is contained in:
@@ -211,23 +211,18 @@ PRIVATE_DEFINITION_START(PIProcess)
|
|||||||
while (1) {
|
while (1) {
|
||||||
# ifdef WINDOWS
|
# ifdef WINDOWS
|
||||||
DWORD available = 0;
|
DWORD available = 0;
|
||||||
BOOL ok = PeekNamedPipe(pipes[pipe_type][PipeRead], nullptr, 0, nullptr, &available, nullptr);
|
PeekNamedPipe(pipes[pipe_type][PipeRead], nullptr, 0, nullptr, &available, nullptr);
|
||||||
// piCout << "ReadFile" << available;
|
if (available > 0) {
|
||||||
if (available == 0) {
|
BOOL ok = ReadFile(pipes[pipe_type][PipeRead],
|
||||||
read_buffer.resize(offset);
|
read_buffer.data(offset),
|
||||||
break;
|
piMini(available, read_buffer.size() - offset),
|
||||||
|
&bytes_read,
|
||||||
|
nullptr);
|
||||||
|
if (!ok) bytes_read = 0;
|
||||||
}
|
}
|
||||||
ok = ReadFile(pipes[pipe_type][PipeRead],
|
|
||||||
read_buffer.data(offset),
|
|
||||||
piMini(available, read_buffer.size() - offset),
|
|
||||||
&bytes_read,
|
|
||||||
nullptr);
|
|
||||||
// piCout << "ReadFile" << ok;
|
|
||||||
if (!ok) bytes_read = 0;
|
|
||||||
# else
|
# else
|
||||||
bytes_read = ::read(pipes[pipe_type][PipeRead], read_buffer.data(offset), read_buffer.size() - offset);
|
bytes_read = ::read(pipes[pipe_type][PipeRead], read_buffer.data(offset), read_buffer.size() - offset);
|
||||||
# endif
|
# endif
|
||||||
// piCout << "readed" << bytes_read;
|
|
||||||
if (bytes_read > 0) {
|
if (bytes_read > 0) {
|
||||||
offset += bytes_read;
|
offset += bytes_read;
|
||||||
read_buffer.resize(offset + read_buffer_size);
|
read_buffer.resize(offset + read_buffer_size);
|
||||||
@@ -236,7 +231,6 @@ PRIVATE_DEFINITION_START(PIProcess)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// piCout << "readPipe" << PIString::fromConsole(read_buffer);
|
|
||||||
return read_buffer;
|
return read_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,7 +243,6 @@ PRIVATE_DEFINITION_START(PIProcess)
|
|||||||
# else
|
# else
|
||||||
sz = ::write(pipes[StdIn][PipeWrite], data.data(), data.size());
|
sz = ::write(pipes[StdIn][PipeWrite], data.data(), data.size());
|
||||||
# endif
|
# endif
|
||||||
// piCout << "writePipe" << sz;
|
|
||||||
return sz == data.size_s();
|
return sz == data.size_s();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +291,6 @@ void PIProcess::startProc(bool detached) {
|
|||||||
if (PRIVATE->grab[StdErr]) si.hStdError = PRIVATE->pipes[StdErr][PipeWrite];
|
if (PRIVATE->grab[StdErr]) si.hStdError = PRIVATE->pipes[StdErr][PipeWrite];
|
||||||
si.dwFlags |= STARTF_USESTDHANDLES;
|
si.dwFlags |= STARTF_USESTDHANDLES;
|
||||||
const auto cmd = convertWindowsCmd(args);
|
const auto cmd = convertWindowsCmd(args);
|
||||||
// piCout << cmd;
|
|
||||||
if (CreateProcessA(0, // No module name (use command line)
|
if (CreateProcessA(0, // No module name (use command line)
|
||||||
(LPSTR)cmd.data(), // Command line
|
(LPSTR)cmd.data(), // Command line
|
||||||
0, // Process handle not inheritable
|
0, // Process handle not inheritable
|
||||||
@@ -310,7 +302,6 @@ void PIProcess::startProc(bool detached) {
|
|||||||
&si, // Pointer to STARTUPINFO structure
|
&si, // Pointer to STARTUPINFO structure
|
||||||
&(PRIVATE->pi))) // Pointer to PROCESS_INFORMATION structure
|
&(PRIVATE->pi))) // Pointer to PROCESS_INFORMATION structure
|
||||||
{
|
{
|
||||||
// piCout << "started";
|
|
||||||
exec_start = true;
|
exec_start = true;
|
||||||
if (!detached) {
|
if (!detached) {
|
||||||
WaitForSingleObject(PRIVATE->pi.hProcess, INFINITE);
|
WaitForSingleObject(PRIVATE->pi.hProcess, INFINITE);
|
||||||
@@ -347,6 +338,7 @@ void PIProcess::startProc(bool detached) {
|
|||||||
execve(str.data(), largs, lenv);
|
execve(str.data(), largs, lenv);
|
||||||
// normaly execve can't return, if it returns - error occured
|
// normaly execve can't return, if it returns - error occured
|
||||||
piCoutObj << "\"execve" << str << args << "\" error :" << errorString();
|
piCoutObj << "\"execve" << str << args << "\" error :" << errorString();
|
||||||
|
exit(127);
|
||||||
} else {
|
} else {
|
||||||
PRIVATE->closePipe(StdIn, PipeRead);
|
PRIVATE->closePipe(StdIn, PipeRead);
|
||||||
PRIVATE->closePipe(StdOut, PipeWrite);
|
PRIVATE->closePipe(StdOut, PipeWrite);
|
||||||
@@ -358,7 +350,9 @@ void PIProcess::startProc(bool detached) {
|
|||||||
exec_start = true;
|
exec_start = true;
|
||||||
if (!detached) {
|
if (!detached) {
|
||||||
waitpid(pid_, &exit_code, 0);
|
waitpid(pid_, &exit_code, 0);
|
||||||
exec_finished = true;
|
if (WIFEXITED(exit_code)) {
|
||||||
|
exec_finished = WEXITSTATUS(exit_code) != 127;
|
||||||
|
}
|
||||||
pid_ = 0;
|
pid_ = 0;
|
||||||
if (!detached) PRIVATE->pid = pid_;
|
if (!detached) PRIVATE->pid = pid_;
|
||||||
}
|
}
|
||||||
@@ -419,7 +413,7 @@ bool PIProcess::writeInput(const PIByteArray & data) {
|
|||||||
void PIProcess::closeInput() {
|
void PIProcess::closeInput() {
|
||||||
if (PRIVATE->grab[StdIn]) {
|
if (PRIVATE->grab[StdIn]) {
|
||||||
# ifdef WINDOWS
|
# ifdef WINDOWS
|
||||||
// PRIVATE->writePipe({0x1A});
|
PRIVATE->writePipe({0x1A});
|
||||||
# endif
|
# endif
|
||||||
PRIVATE->closePipe(StdIn, PipeWrite);
|
PRIVATE->closePipe(StdIn, PipeWrite);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,9 +74,6 @@ TEST_F(ProcessTest, Input) {
|
|||||||
EXPECT_TRUE(!launcher.isExecFinished());
|
EXPECT_TRUE(!launcher.isExecFinished());
|
||||||
|
|
||||||
PIString test_input = "Test input string\n";
|
PIString test_input = "Test input string\n";
|
||||||
#ifdef WINDOWS
|
|
||||||
test_input += (char)0x1A;
|
|
||||||
#endif
|
|
||||||
EXPECT_TRUE(launcher.writeInput(test_input.toAscii()));
|
EXPECT_TRUE(launcher.writeInput(test_input.toAscii()));
|
||||||
launcher.closeInput();
|
launcher.closeInput();
|
||||||
|
|
||||||
@@ -91,6 +88,9 @@ TEST_F(ProcessTest, Input) {
|
|||||||
TEST_F(ProcessTest, NonexistentCommand) {
|
TEST_F(ProcessTest, NonexistentCommand) {
|
||||||
const PIString command = {"nonexistent_command_12345"};
|
const PIString command = {"nonexistent_command_12345"};
|
||||||
|
|
||||||
|
launcher.enableWriteStdIn(false);
|
||||||
|
launcher.enableReadStdOut(false);
|
||||||
|
launcher.enableReadStdErr(false);
|
||||||
launcher.exec(command);
|
launcher.exec(command);
|
||||||
ASSERT_TRUE(launcher.isRunning());
|
ASSERT_TRUE(launcher.isRunning());
|
||||||
ASSERT_TRUE(launcher.waitForFinish());
|
ASSERT_TRUE(launcher.waitForFinish());
|
||||||
|
|||||||
Reference in New Issue
Block a user