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_p.c |
michael@0 | 8 | * |
michael@0 | 9 | * The purpose of this test and the sproc_ch.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 | * In this test, the parent sproc gets a segmentation fault and dies. |
michael@0 | 13 | * The child sproc never stops on its own. You should use "ps" to see if |
michael@0 | 14 | * the child sproc is killed after the parent dies. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #include "prinit.h" |
michael@0 | 18 | #include <stdio.h> |
michael@0 | 19 | |
michael@0 | 20 | #if !defined(IRIX) |
michael@0 | 21 | |
michael@0 | 22 | int main(int argc, char **argv) |
michael@0 | 23 | { |
michael@0 | 24 | printf("This test applies to IRIX only.\n"); |
michael@0 | 25 | return 0; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | #else /* IRIX */ |
michael@0 | 29 | |
michael@0 | 30 | #include "prthread.h" |
michael@0 | 31 | #include <sys/types.h> |
michael@0 | 32 | #include <unistd.h> |
michael@0 | 33 | |
michael@0 | 34 | void NeverStops(void *unused) |
michael@0 | 35 | { |
michael@0 | 36 | int i = 0; |
michael@0 | 37 | |
michael@0 | 38 | printf("The child sproc has pid %d.\n", getpid()); |
michael@0 | 39 | printf("The child sproc won't stop on its own.\n"); |
michael@0 | 40 | fflush(stdout); |
michael@0 | 41 | |
michael@0 | 42 | /* I never stop */ |
michael@0 | 43 | while (1) { |
michael@0 | 44 | i++; |
michael@0 | 45 | } |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | int main() |
michael@0 | 49 | { |
michael@0 | 50 | int *p = 0; |
michael@0 | 51 | |
michael@0 | 52 | PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); |
michael@0 | 53 | |
michael@0 | 54 | printf("The parent sproc has pid %d.\n", getpid()); |
michael@0 | 55 | printf("The parent sproc will first create a child sproc.\n"); |
michael@0 | 56 | printf("Then the parent sproc will get a segmentation fault and die.\n"); |
michael@0 | 57 | printf("The child sproc should be killed after the parent sproc dies.\n"); |
michael@0 | 58 | printf("Use 'ps' to make sure this is so.\n"); |
michael@0 | 59 | fflush(stdout); |
michael@0 | 60 | |
michael@0 | 61 | PR_CreateThread(PR_USER_THREAD, NeverStops, NULL, |
michael@0 | 62 | PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0); |
michael@0 | 63 | |
michael@0 | 64 | /* Force a segmentation fault */ |
michael@0 | 65 | *p = 0; |
michael@0 | 66 | return 0; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | #endif /* IRIX */ |