| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <assert.h> | 5 #include <assert.h> |
| 6 #include <dirent.h> | 6 #include <dirent.h> |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 #include <pty.h> | 9 #include <pty.h> |
| 10 #include <sys/prctl.h> | 10 #include <sys/prctl.h> |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 write(fds[0], &ch, 1); | 700 write(fds[0], &ch, 1); |
| 701 read(fds[0], &ch, 1); | 701 read(fds[0], &ch, 1); |
| 702 _exit(1); | 702 _exit(1); |
| 703 } | 703 } |
| 704 rc = ptrace(PTRACE_ATTACH, pid, 0, 0); | 704 rc = ptrace(PTRACE_ATTACH, pid, 0, 0); |
| 705 assert(rc == -1 && errno == EPERM); | 705 assert(rc == -1 && errno == EPERM); |
| 706 write(fds[1], &ch, 1); | 706 write(fds[1], &ch, 1); |
| 707 read(fds[1], &ch, 1); | 707 read(fds[1], &ch, 1); |
| 708 rc = ptrace(PTRACE_ATTACH, pid, 0, 0); | 708 rc = ptrace(PTRACE_ATTACH, pid, 0, 0); |
| 709 assert(rc == 0); | 709 assert(rc == 0); |
| 710 |
| 711 // Now clean up. We have to collect the subprocess's stopped state |
| 712 // with waitpid() otherwise PTRACE_KILL will not successfully kill |
| 713 // the subprocess. |
| 714 int status; |
| 715 rc = waitpid(pid, &status, 0); |
| 716 assert(rc == pid); |
| 717 assert(WIFSTOPPED(status)); |
| 718 assert(WSTOPSIG(status) == SIGSTOP); |
| 719 |
| 710 rc = ptrace(PTRACE_KILL, pid, 0, 0); | 720 rc = ptrace(PTRACE_KILL, pid, 0, 0); |
| 711 assert(rc == 0); | 721 assert(rc == 0); |
| 722 |
| 723 rc = waitpid(pid, &status, 0); |
| 724 assert(rc == pid); |
| 725 assert(WIFSIGNALED(status)); |
| 726 assert(WTERMSIG(status) == SIGKILL); |
| 712 } | 727 } |
| 713 | 728 |
| 714 struct testcase { | 729 struct testcase { |
| 715 const char *test_name; | 730 const char *test_name; |
| 716 void (*test_func)(); | 731 void (*test_func)(); |
| 717 }; | 732 }; |
| 718 | 733 |
| 719 struct testcase all_tests[] = { | 734 struct testcase all_tests[] = { |
| 720 #include "test-list.h" | 735 #include "test-list.h" |
| 721 { NULL, NULL }, | 736 { NULL, NULL }, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 if (failures == 0) { | 821 if (failures == 0) { |
| 807 printf("OK\n"); | 822 printf("OK\n"); |
| 808 return 0; | 823 return 0; |
| 809 } | 824 } |
| 810 else { | 825 else { |
| 811 printf("%i FAILURE(S)\n", failures); | 826 printf("%i FAILURE(S)\n", failures); |
| 812 return 1; | 827 return 1; |
| 813 } | 828 } |
| 814 } | 829 } |
| 815 } | 830 } |
| OLD | NEW |