Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / TBBT / trace_play / sfs_c_sig.c
1 #ifndef lint
2 static char sfs_c_sigSid[] = "@(#)sfs_c_sig.c   2.1     97/10/23";
3 #endif
4
5 /*
6  *   Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
7  *      All rights reserved.
8  *              Standard Performance Evaluation Corporation (SPEC)
9  *              6585 Merchant Place, Suite 100
10  *              Warrenton, VA 20187
11  *
12  *      This product contains benchmarks acquired from several sources who
13  *      understand and agree with SPEC's goal of creating fair and objective
14  *      benchmarks to measure computer performance.
15  *
16  *      This copyright notice is placed here only to protect SPEC in the
17  *      event the source is misused in any manner that is contrary to the
18  *      spirit, the goals and the intent of SPEC.
19  *
20  *      The source code is provided to the user or company under the license
21  *      agreement for the SPEC Benchmark Suite for this product.
22  */
23
24 /*****************************************************************
25  *                                                               *
26  *      Copyright 1991,1992  Legato Systems, Inc.                *
27  *      Copyright 1991,1992  Auspex Systems, Inc.                *
28  *      Copyright 1991,1992  Data General Corporation            *
29  *      Copyright 1991,1992  Digital Equipment Corporation       *
30  *      Copyright 1991,1992  Interphase Corporation              *
31  *      Copyright 1991,1992  Sun Microsystems, Inc.              *
32  *                                                               *
33  *****************************************************************/
34
35 /*
36  * ---------------------- sfs_c_sig.c ---------------------
37  *
38  *      Signal handling.  Routines to send and catch signals.
39  *
40  *.Exported_Routines
41  *      void sfs_alarm(int)
42  *      void sfs_startup(int)
43  *      void sfs_stop(int)
44  *      void sfs_cleanup(int)
45  *
46  *.Local_Routines
47  *      None.
48  *
49  *.Revision_History
50  *      16-Dec-91       Wittle          Created.
51  */
52
53
54 /*
55  * -------------------------  Include Files  -------------------------
56  */
57
58 /*
59  * ANSI C headers
60  */
61 #include <stdio.h>
62 #include <stdlib.h>
63 #include <string.h>
64 #include <errno.h>
65 #include <signal.h>
66  
67 #include <sys/types.h>
68 #include <sys/stat.h> 
69
70 #include <sys/signal.h>
71
72 #include <unistd.h>
73
74 #include "sfs_c_def.h"
75
76 #ifndef RFS
77 /*
78  * -------------------------  Signal Handlers  -------------------------
79  */
80
81 void
82 sfs_alarm(
83     int         sig_id)
84 {
85 #if !(defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
86     (void) signal(sig_id, sfs_alarm);
87 #endif
88     if (DEBUG_CHILD_SIGNAL)
89         (void) fprintf(stderr, "%s: caught Signal %d\n", sfs_Myname, sig_id);
90     (void) fflush(stderr);
91
92 } /* sfs_alarm */
93
94
95 /*
96  * Signal Handler
97  * Catch the parent's "start" signal.
98  */
99 void
100 sfs_startup(
101     int         sig_id)
102 {
103 #if !(defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
104     (void) signal(SIGUSR1, sfs_startup);
105 #endif
106     if (DEBUG_CHILD_SIGNAL)
107         (void) fprintf(stderr, "%s: caught Signal %d SIGUSR1\n",
108                        sfs_Myname, sig_id);
109
110     if (Child_num == -1)
111         /* I'm the parent, ignore the signal */
112         return;
113
114     /*
115      * SIGUSR1 is used to make all phase transitions, but we
116      * only want to make the Warmup -> Testrun switch here
117      */
118     if (Current_test_phase != Warmup_phase)
119         return;
120
121     Current_test_phase = Testrun_phase;
122     start_run_phase++;
123 } /* sfs_startup */
124
125
126 /*
127  * Signal Handler
128  * Catch the parent's "stop" signal.
129  */
130 void
131 sfs_stop(
132     int         sig_id)
133 {
134 #if !(defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
135     (void) signal(SIGUSR2, sfs_stop);
136 #endif
137     if (DEBUG_CHILD_SIGNAL)
138         (void) fprintf(stderr, "%s: caught Signal %d SIGUSR2\n",
139                        sfs_Myname, sig_id);
140
141     /* end the test */
142     Runtime = 0;
143     Current_test_phase = Results_phase;
144
145 } /* sfs_stop */
146
147 #endif
148
149
150 /*
151  * SIGINT, SIGTERM handler
152  * Clean up and exit due to an error/abort condition.
153  * We assume if NFS_client was valid, then MOUNT_client was also valid.
154  */
155 void
156 sfs_cleanup(
157     int         sig_id)
158 {
159     if (DEBUG_CHILD_SIGNAL)
160         (void) fprintf(stderr, "%s: caught Signal %d SIGINT\n",
161                        sfs_Myname, sig_id);
162
163     (void) unlink(Logname);
164     if (NFS_client != ((CLIENT *) NULL))
165         clnt_destroy(NFS_client);
166     exit(65);
167
168 } /* sfs_cleanup */
169
170 /* sfs_c_sig.c */