Replace kill() with waitpid()
This commit is contained in:
parent
0433a47ec1
commit
103b4b3681
|
@ -29,6 +29,7 @@
|
||||||
#include <cppunit/TestRunner.h>
|
#include <cppunit/TestRunner.h>
|
||||||
|
|
||||||
#include <final/final.h>
|
#include <final/final.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#define CPPUNIT_ASSERT_CSTRING(expected, actual) \
|
#define CPPUNIT_ASSERT_CSTRING(expected, actual) \
|
||||||
|
@ -514,15 +515,15 @@ void FTermDetectionTest::ansiTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (ansi);
|
terminalSimulation (ansi);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,19 +572,16 @@ void FTermDetectionTest::xtermTest()
|
||||||
CPPUNIT_ASSERT ( detect.hasSetCursorStyleSupport() );
|
CPPUNIT_ASSERT ( detect.hasSetCursorStyleSupport() );
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
|
closeStandardStreams();
|
||||||
close(0); // fd_slave on stdin
|
exit(EXIT_SUCCESS);
|
||||||
close(1); // fd_slave on stdout
|
|
||||||
close(2); // fd_slave on stderr
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (xterm);
|
terminalSimulation (xterm);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -633,15 +631,15 @@ void FTermDetectionTest::rxvtTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (rxvt);
|
terminalSimulation (rxvt);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -691,15 +689,15 @@ void FTermDetectionTest::urxvtTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (urxvt);
|
terminalSimulation (urxvt);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,15 +748,15 @@ void FTermDetectionTest::mltermTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (mlterm);
|
terminalSimulation (mlterm);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -809,15 +807,15 @@ void FTermDetectionTest::puttyTest()
|
||||||
//debug = true;
|
//debug = true;
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (putty);
|
terminalSimulation (putty);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -867,15 +865,15 @@ void FTermDetectionTest::kdeKonsoleTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (kde_konsole);
|
terminalSimulation (kde_konsole);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -926,15 +924,15 @@ void FTermDetectionTest::gnomeTerminalTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (gnome_terminal);
|
terminalSimulation (gnome_terminal);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -985,15 +983,15 @@ void FTermDetectionTest::ktermTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (kterm);
|
terminalSimulation (kterm);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1044,15 +1042,15 @@ void FTermDetectionTest::teraTermTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (tera_term);
|
terminalSimulation (tera_term);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1103,15 +1101,15 @@ void FTermDetectionTest::cygwinTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (cygwin);
|
terminalSimulation (cygwin);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1162,15 +1160,15 @@ void FTermDetectionTest::minttyTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (mintty);
|
terminalSimulation (mintty);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1221,15 +1219,15 @@ void FTermDetectionTest::linuxTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (linux_con);
|
terminalSimulation (linux_con);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1281,15 +1279,15 @@ void FTermDetectionTest::freebsdTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (freebsd_con);
|
terminalSimulation (freebsd_con);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1341,15 +1339,15 @@ void FTermDetectionTest::netbsdTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (netbsd_con);
|
terminalSimulation (netbsd_con);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1401,15 +1399,15 @@ void FTermDetectionTest::openbsdTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (openbsd_con);
|
terminalSimulation (openbsd_con);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1459,15 +1457,15 @@ void FTermDetectionTest::sunTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (sun_con);
|
terminalSimulation (sun_con);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1519,15 +1517,15 @@ void FTermDetectionTest::screenTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (screen);
|
terminalSimulation (screen);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1579,15 +1577,15 @@ void FTermDetectionTest::tmuxTest()
|
||||||
|
|
||||||
debugOutput();
|
debugOutput();
|
||||||
closeStandardStreams();
|
closeStandardStreams();
|
||||||
return;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else // Parent
|
else // Parent
|
||||||
{
|
{
|
||||||
// Start the terminal simulation
|
// Start the terminal simulation
|
||||||
terminalSimulation (tmux);
|
terminalSimulation (tmux);
|
||||||
|
|
||||||
// Kill child process
|
if ( waitpid(pid, 0, 0) != pid )
|
||||||
kill (pid, SIGKILL);
|
::fprintf (stderr, "waitpid error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1999,14 +1997,17 @@ void FTermDetectionTest::terminalSimulation (console con)
|
||||||
while ( 1 )
|
while ( 1 )
|
||||||
{
|
{
|
||||||
fd_set ifds;
|
fd_set ifds;
|
||||||
|
struct timeval tv;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
FD_ZERO(&ifds);
|
FD_ZERO(&ifds);
|
||||||
FD_SET(fd_stdin, &ifds);
|
FD_SET(fd_stdin, &ifds);
|
||||||
FD_SET(fd_master, &ifds);
|
FD_SET(fd_master, &ifds);
|
||||||
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = 750000; // 750 ms
|
||||||
|
|
||||||
// Wait for data from stdin or the master side of PTY
|
// Wait for data from stdin or the master side of PTY
|
||||||
if ( select(fd_master + 1, &ifds, 0, 0, 0) < 0 )
|
if ( select(fd_master + 1, &ifds, 0, 0, &tv) < 0 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Data on standard input
|
// Data on standard input
|
||||||
|
|
Loading…
Reference in New Issue