Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * Test sproc_ch.c |
michael@0 | 8 | * |
michael@0 | 9 | * The purpose of this test and the sproc_p.c test is to test the shutdown |
michael@0 | 10 | * of all the IRIX sprocs in a program when one of them dies due to an error. |
michael@0 | 11 | * |
michael@0 | 12 | * There are three sprocs in this test: the parent, the child, and the |
michael@0 | 13 | * grandchild. The parent and child sprocs never stop on their own. |
michael@0 | 14 | * The grandchild sproc gets a segmentation fault and dies. You should |
michael@0 | 15 | * You should use "ps" to see if the parent and child sprocs are killed |
michael@0 | 16 | * after the grandchild dies. |
michael@0 | 17 | */ |
michael@0 | 18 | |
michael@0 | 19 | #include "prinit.h" |
michael@0 | 20 | #include <stdio.h> |
michael@0 | 21 | |
michael@0 | 22 | #if !defined(IRIX) |
michael@0 | 23 | |
michael@0 | 24 | int main(int argc, char **argv) |
michael@0 | 25 | { |
michael@0 | 26 | printf("This test applies to IRIX only.\n"); |
michael@0 | 27 | return 0; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | #else /* IRIX */ |
michael@0 | 31 | |
michael@0 | 32 | #include "prthread.h" |
michael@0 | 33 | #include <sys/types.h> |
michael@0 | 34 | #include <unistd.h> |
michael@0 | 35 | |
michael@0 | 36 | void SegFault(void *unused) |
michael@0 | 37 | { |
michael@0 | 38 | int *p = 0; |
michael@0 | 39 | |
michael@0 | 40 | printf("The grandchild sproc has pid %d.\n", getpid()); |
michael@0 | 41 | printf("The grandchild sproc will get a segmentation fault and die.\n"); |
michael@0 | 42 | printf("The parent and child sprocs should be killed after the " |
michael@0 | 43 | "grandchild sproc dies.\n"); |
michael@0 | 44 | printf("Use 'ps' to make sure this is so.\n"); |
michael@0 | 45 | fflush(stdout); |
michael@0 | 46 | /* Force a segmentation fault */ |
michael@0 | 47 | *p = 0; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | void NeverStops(void *unused) |
michael@0 | 51 | { |
michael@0 | 52 | int i = 0; |
michael@0 | 53 | |
michael@0 | 54 | printf("The child sproc has pid %d.\n", getpid()); |
michael@0 | 55 | printf("The child sproc won't stop on its own.\n"); |
michael@0 | 56 | fflush(stdout); |
michael@0 | 57 | |
michael@0 | 58 | /* create the grandchild sproc */ |
michael@0 | 59 | PR_CreateThread(PR_USER_THREAD, SegFault, NULL, |
michael@0 | 60 | PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0); |
michael@0 | 61 | |
michael@0 | 62 | while (1) { |
michael@0 | 63 | i++; |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | int main() |
michael@0 | 68 | { |
michael@0 | 69 | int i= 0; |
michael@0 | 70 | |
michael@0 | 71 | PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); |
michael@0 | 72 | |
michael@0 | 73 | printf("The parent sproc has pid %d.\n", getpid()); |
michael@0 | 74 | printf("The parent sproc won't stop on its own.\n"); |
michael@0 | 75 | fflush(stdout); |
michael@0 | 76 | |
michael@0 | 77 | /* create the child sproc */ |
michael@0 | 78 | PR_CreateThread(PR_USER_THREAD, NeverStops, NULL, |
michael@0 | 79 | PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0); |
michael@0 | 80 | |
michael@0 | 81 | while (1) { |
michael@0 | 82 | i++; |
michael@0 | 83 | } |
michael@0 | 84 | return 0; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | #endif /* IRIX */ |