| 1 | /* |
| 2 | Copyright (C) 2010 by Intra2net AG - Thomas Jarosch |
| 3 | |
| 4 | The software in this package is distributed under the GNU General |
| 5 | Public License version 2 (with a special exception described below). |
| 6 | |
| 7 | A copy of GNU General Public License (GPL) is included in this distribution, |
| 8 | in the file COPYING.GPL. |
| 9 | |
| 10 | As a special exception, if other files instantiate templates or use macros |
| 11 | or inline functions from this file, or you compile this file and link it |
| 12 | with other works to produce a work based on this file, this file |
| 13 | does not by itself cause the resulting work to be covered |
| 14 | by the GNU General Public License. |
| 15 | |
| 16 | However the source code for this file must still be made available |
| 17 | in accordance with section (3) of the GNU General Public License. |
| 18 | |
| 19 | This exception does not invalidate any other reasons why a work based |
| 20 | on this file might be covered by the GNU General Public License. |
| 21 | */ |
| 22 | #ifndef __LIBT2N_TEST_FIXTURES |
| 23 | #define __LIBT2N_TEST_FIXTURES |
| 24 | |
| 25 | #include <sys/wait.h> |
| 26 | #include <sys/types.h> |
| 27 | #include <signal.h> |
| 28 | |
| 29 | class KillChildOnShutdownFixture |
| 30 | { |
| 31 | protected: |
| 32 | pid_t child_pid; |
| 33 | |
| 34 | public: |
| 35 | KillChildOnShutdownFixture() |
| 36 | : child_pid(0) |
| 37 | { |
| 38 | // Work around Boost.test reporting killed childs as "fatal error". |
| 39 | // Can be ignored with boost 1.40.0+, need to check after upgrade |
| 40 | signal(SIGCHLD, SIG_IGN); |
| 41 | } |
| 42 | |
| 43 | ~KillChildOnShutdownFixture() |
| 44 | { |
| 45 | // make sure the server-child is dead before the next test runs |
| 46 | if (child_pid) |
| 47 | { |
| 48 | // std::cout << "Killing child with pid: " << child_pid << std::endl; |
| 49 | kill(child_pid, SIGKILL); |
| 50 | |
| 51 | int status = 0; |
| 52 | waitpid(child_pid, &status, 0); |
| 53 | } |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | #endif |