Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / TBBT / trace_play / sfs_c_sub.c
1 #ifndef lint
2 static char sfs_c_subSid[] = "@(#)sfs_c_sub.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_sub.c ---------------------
37  *
38  *      Subroutines common to both sfs and sfs_prime_client.
39  *
40  *.Exported_Routines
41  *      int generic_kill(int, int)
42  *      void generic_catcher(int)
43  *      char * lad_timestamp(void)
44  *
45  *.Local_Routines
46  *      None.
47  *
48  *.Revision_History
49  *      16-Dec-91       Wittle          Created.
50  */
51
52
53 /*
54  * -------------------------  Include Files  -------------------------
55  */
56
57 /*
58  * ANSI C headers
59  */
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <string.h>
63 #include <ctype.h>
64 #include <errno.h>
65 #include <signal.h>
66 #include <time.h>
67
68 #include <sys/types.h>
69 #include <sys/stat.h> 
70  
71 #include <sys/signal.h>
72
73 #include <unistd.h>
74
75 #include "sfs_c_def.h"
76
77 /*
78  * Common data shared between sfs and sfs_prime
79  *
80  * Values for invalid runs
81  */
82 char *invalid_str[INVALID_MAX] = {
83         "No error",
84         "Unknown",
85         "IO distribution file",
86         "Mix file",
87         "Runtime",
88         "Access percentage",
89         "Append percentage",
90         "KB per block",
91         "Number client directories",
92         "Fileset delta",
93         "Max biod reads",
94         "Number symlinks",
95         "Max biod writes",
96         "Warmup time",
97         "No good calls",
98         "Failed RPC calls",
99         "Op mix missed",
100 };
101
102 /*
103  * -------------------------  Signal Handlers  -------------------------
104  */
105
106 /*
107  * Signal Sender.  Send signal 'sig' to process 'pid'.
108  */
109 int
110 generic_kill(
111     int         pid,
112     int         signal)
113 {
114     if (DEBUG_PARENT_SIGNAL)
115         (void) fprintf(stderr,
116                         "%s: sending Pid %d Signal %d\n", sfs_Myname, pid ,signal);
117     return(kill((pid_t)pid, signal));
118
119 } /* generic_kill */
120
121
122 /*
123  * Signal Handler.  Catch and reset the handler for signal 'i'.
124  */
125 void
126 generic_catcher(
127     int         i)
128 {
129 #if !(defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
130     (void) signal(i, generic_catcher);
131 #endif
132     if (DEBUG_CHILD_SIGNAL)
133         (void) fprintf(stderr, "%s: caught Signal %d\n", sfs_Myname, i);
134     (void) fflush(stderr);
135
136 } /* generic_catcher */
137
138
139
140 /*
141  * get the date and time and return a string, remove the END-OF-LINE (\n)
142  */
143 char *
144 lad_timestamp(void)
145 {
146     static time_t       run_date;
147     static char         date_string[26];
148
149     run_date = time((time_t *)NULL);
150     (void) strncpy((char *) date_string, (char *) ctime(&run_date), 24);
151     return(date_string);
152
153 } /* lad_timestamp */
154
155 int
156 set_debug_level(char *s)
157 {
158     unsigned int i;
159     unsigned int first;
160     unsigned int last;
161     unsigned int level = 0;
162
163     if (s == NULL || *s == '\0')
164         return(0);
165
166     for (;;) {
167         if (*s == ',') {
168             s++;
169             continue;
170         }
171
172         /* find first flag to set */
173         i = 0;
174         while (isdigit(*s))
175             i = i * 10 + (*s++ - '0');
176         first = i;
177
178         /* find last flag to set */
179         if (*s == '-') {
180             i = 0;
181             while (isdigit(*++s))
182                 i = i * 10 + (*s - '0');
183         }
184         last = i;
185
186         if (first != 0 && last != 0 && first < 32 && last < 32) {
187             for (i = first - 1; i < last; i++) {
188                 level |= (1 << i);
189             }
190         }
191
192         /* more arguments? */
193         if (*s++ == '\0')
194                 return (level);
195     }
196 }
197
198 /* sfs_c_sub.c */