Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / TBBT / trace_play / sfs_mcr
1 #! /bin/sh
2 #       @(#)sfs_mcr     2.1     97/10/23
3 #
4 #
5 #    Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
6 #       All rights reserved.
7 #               Standard Performance Evaluation Corporation (SPEC)
8 #               6585 Merchant Place, Suite 100
9 #               Warrenton, VA 20187
10 #       This product contains benchmarks acquired from several sources who
11 #       understand and agree with SPEC's goal of creating fair and objective
12 #       benchmarks to measure computer performance.
13 #
14 #       This copyright notice is placed here only to protect SPEC in the
15 #       event the source is misused in any manner that is contrary to the
16 #       spirit, the goals and the intent of SPEC.
17 #
18 #       The source code is provided to the user or company under the license
19 #       agreement for the SPEC Benchmark Suite for this product.
20 #
21 # *****************************************************************
22 # *                                                               *
23 # *     Copyright 1991,1992  Legato Systems, Inc.                 *
24 # *     Copyright 1991,1992  Auspex Systems, Inc.                 *
25 # *     Copyright 1991,1992  Data General Corporation             *
26 # *     Copyright 1991,1992  Digital Equipment Corporation        *
27 # *     Copyright 1991,1992  Interphase Corporation               *
28 # *     Copyright 1991,1992  Sun Microsystems, Inc.               *
29 # *                                                               *
30 # *****************************************************************
31 #
32 # Usage sfs_mcr <sfs parameter string>
33 #
34 # Teelucksingh - Creation (6/17/91)
35 #
36 # This script is remotely started from the Prime-client
37 # by sfs_mgr .
38 #
39
40 #
41 # Client pid files
42 #
43 SFS_PNT_PID="/tmp/sfs_pnt_pid"
44 SFS_SYNCD_PID="/tmp/sfs_syncd_pid"
45
46 # SFS client log files
47 CLIENT_LOG_FILES="/tmp/sfs_CL$CLIENT_NUM \
48                 /tmp/sfs_sig$CLIENT_NUM \
49                 /tmp/sfs_x$CLIENT_NUM"
50
51 if [ "$1" = "cleanup" ]; then
52     #
53     # do cleanup
54     #
55     rm -f $CLIENT_LOG_FILES
56
57     #
58     # clean up any 'old' sfs processes
59     #
60     if [ -f $SFS_PNT_PID ]; then
61         kill -2 `cat $SFS_PNT_PID` > /dev/null 2>&1
62         rm -f $SFS_PNT_PID
63     fi
64     if [ -f $SFS_SYNCD_PID ]; then
65         kill -2 `cat $SFS_SYNCD_PID` > /dev/null 2>&1
66         rm -f $SFS_SYNCD_PID
67     fi
68
69     exit
70 fi
71
72 # read command line arguments
73 SFS_PROG=$1
74 shift
75 SFS_DIR=$1
76 shift
77 S_LOGFILE=$1
78 shift
79 C_LOGFILE=$1
80 shift
81 CLIENT_NUM=$1
82 shift
83
84 # print start message
85 echo "========================================================================" >> $C_LOGFILE
86 echo "" >> $C_LOGFILE
87
88 #
89 # decide whether to use BSD (which one) or SYSV variant of commands
90 #
91 # do test to see whether to use hostname or uname
92 sh -c "hostname > /dev/null 2>&1" > /dev/null 2>&1
93 if [ $? -eq 0 ]; then
94         HOSTNAME_CMD="hostname"
95 else
96         sh -c "uname -n  > /dev/null 2>&1" > /dev/null 2>&1
97         if [ $? -eq 0 ]; then
98                 HOSTNAME_CMD="uname -n"
99         else
100          echo "sfs_mcr: can't use hostname(1) or uname(1), exiting." >> $C_LOGFILE
101                 exit 1
102         fi
103 fi
104
105 #
106 # trap for signals used by sfs
107 #
108 # Try to find cpp in the common places, if not there then let PATH find it
109 if [ "$CPP" = "" ]
110 then
111     if [ -f /lib/cpp ]
112     then
113         CPP=/lib/cpp
114     elif [ -f /usr/ccs/lib/cpp ]
115     then
116         CPP=/usr/ccs/lib/cpp
117     else
118         CPP=cpp
119     fi
120 fi
121
122 #
123 # Allow trap numbers to be defined externally for broken systems
124 #
125 if [ "$TRAP_NUMS" = "" ]
126 then
127     echo "#include <signal.h>" > /tmp/sfs_sig$CLIENT_NUM
128     echo "myprint SIGINT SIGALRM SIGTERM SIGUSR1 SIGUSR2" >> \
129          /tmp/sfs_sig$CLIENT_NUM
130     cat /tmp/sfs_sig$CLIENT_NUM | $CPP | grep myprint | \
131         awk '{print $2 " " $3 " " $4 " " $5 " " $6}'  > /tmp/sfs_x$CLIENT_NUM
132     TRAP_NUMS=`cat /tmp/sfs_x$CLIENT_NUM`
133 fi
134 trap "" $TRAP_NUMS
135
136 #
137 # start the sync daemon on the client
138 #
139 # Let's truncate the syncd log file at the start of each invocation
140 # of sfs_mcr. Else it grows unbounded.
141 #
142 trap "" $TRAP_NUMS
143 $SFS_DIR/sfs_syncd > $S_LOGFILE 2>&1 &
144 echo "Started: sfs_syncd on client (`$HOSTNAME_CMD`). " >> $C_LOGFILE
145
146 #
147 # start SFS
148 trap "" $TRAP_NUMS
149 echo "Starting: $SFS_DIR/$SFS_PROG -N $CLIENT_NUM $*" >> $C_LOGFILE
150
151 $SFS_DIR/$SFS_PROG -N $CLIENT_NUM $*  >> $C_LOGFILE 2>&1
152
153 if [ $? -ne 0 ]; then     # error condition
154    # clean up
155    echo "sfs_mcr: sfs benchmark terminated with error status" >>$C_LOGFILE
156 fi
157
158 #
159 # clean up any 'old' sfs processes
160 #
161 if [ -f $SFS_PNT_PID ]; then
162     kill -2 `cat $SFS_PNT_PID` > /dev/null 2>&1
163     rm -f $SFS_PNT_PID
164 fi
165 if [ -f $SFS_SYNCD_PID ]; then
166     kill -2 `cat $SFS_SYNCD_PID` > /dev/null 2>&1
167     rm -f $SFS_SYNCD_PID
168 fi
169
170 trap $TRAP_NUMS