Skip to content

Commit

Permalink
Issue #149: tests: Add regression test for fork+exec of another binary
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonKagstrom committed Aug 10, 2016
1 parent 46ff733 commit 5807902
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ add_executable(setpgid-kill setpgid-kill/setpgid-kill-main.cc ../src/utils.cc)
add_executable(issue31 daemon/test-issue31.cc)
add_executable(dlopen dlopen/dlopen.cc dlopen/dlopen-main.cc)
add_executable(s short-file.c)
add_executable(fork+exec fork/fork+exec.c)

add_executable(pie pie.c)
set_target_properties(pie PROPERTIES COMPILE_FLAGS "-g -fpie -fPIE")
Expand Down
32 changes: 32 additions & 0 deletions tests/fork/fork+exec.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <unistd.h>
#include <stdio.h>
#include <sys/ptrace.h>
#include <sys/user.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sched.h>

int main(int argc, const char *argv[])
{
pid_t child;
int status;

child = fork();
if (child < 0) {
fprintf(stderr, "fork failed!\n");
return -1;
}

if (child > 0) {
printf("Parent %d\n", getpid());
} else if (child < 0) {
printf("ERROR!\n");
} else {
printf("Child, will exec()\n");
execvp(argv[1], NULL);
}

waitpid(child, &status, 0);

return 0;
}

0 comments on commit 5807902

Please sign in to comment.