Changeset 134ac5d in mainline for uspace/lib/pcut/src/os/unix.c
- Timestamp:
- 2014-06-06T07:54:24Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8db09e4
- Parents:
- eeb23f2d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcut/src/os/unix.c
reeb23f2d r134ac5d 32 32 */ 33 33 34 /** We need _POSX_SOURCE because of kill(). */ 35 #define _POSIX_SOURCE 34 36 #include <stdlib.h> 35 37 #include <unistd.h> 36 38 #include <sys/types.h> 39 #include <signal.h> 37 40 #include <errno.h> 38 41 #include <assert.h> … … 51 54 static char extra_output_buffer[OUTPUT_BUFFER_SIZE]; 52 55 53 /** Prepare for a new test. */ 56 /** Prepare for a new test. 57 * 58 * @param test Test that is about to be run. 59 */ 54 60 static void before_test_start(pcut_item_t *test) { 55 61 pcut_report_test_start(test); … … 57 63 memset(error_message_buffer, 0, OUTPUT_BUFFER_SIZE); 58 64 memset(extra_output_buffer, 0, OUTPUT_BUFFER_SIZE); 65 } 66 67 /** PID of the forked process running the actual test. */ 68 static pid_t child_pid; 69 70 /** Signal handler that kills the child. 71 * 72 * @param sig Signal number. 73 */ 74 static void kill_child_on_alarm(int sig) { 75 PCUT_UNUSED(sig); 76 kill(child_pid, SIGKILL); 59 77 } 60 78 … … 124 142 125 143 int link_stdout[2], link_stderr[2]; 126 pid_t pid;127 144 128 145 int rc = pipe(link_stdout); … … 141 158 } 142 159 143 pid = fork();144 if ( pid == (pid_t)-1) {160 child_pid = fork(); 161 if (child_pid == (pid_t)-1) { 145 162 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, 146 163 "fork() failed: %s.", strerror(rc)); … … 149 166 } 150 167 151 if ( pid == 0) {168 if (child_pid == 0) { 152 169 /* We are the child. */ 153 170 dup2(link_stdout[1], STDOUT_FILENO); … … 164 181 close(link_stderr[1]); 165 182 183 signal(SIGALRM, kill_child_on_alarm); 184 alarm(pcut_get_test_timeout(test)); 185 166 186 size_t stderr_size = read_all(link_stderr[0], extra_output_buffer, OUTPUT_BUFFER_SIZE - 1); 167 187 read_all(link_stdout[0], extra_output_buffer, OUTPUT_BUFFER_SIZE - 1 - stderr_size); … … 169 189 int status; 170 190 wait(&status); 191 alarm(0); 171 192 172 193 rc = convert_wait_status_to_outcome(status);
Note:
See TracChangeset
for help on using the changeset viewer.