2 static char sccsid[] = "@(#)sfs_m_snc.c 2.1 97/10/23";
6 * Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
8 * Standard Performance Evaluation Corporation (SPEC)
9 * 6585 Merchant Place, Suite 100
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.
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.
20 * The source code is provided to the user or company under the license
21 * agreement for the SPEC Benchmark Suite for this product.
24 /*****************************************************************
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. *
33 *****************************************************************/
40 * void sfs_syncprog_1(struct svc_req *, SVCXPRT *)
41 * int * signal_sync_sfs_1(struct sync_string *)
42 * void lad_syncd_cleanup(int)
45 * 04-Dec-91 Keith Include sfs_def.h for SYSV/SVR4 mem*
46 * functions. Include string.h for SYSV/SVR4.
47 * 28-Nov-91 Teeluckingh Fixed 'multiple signals to sfs'
48 * problem. Uses a 'transaction id' field in
49 * the sync rpc xdr structure to compare
50 * previous rpc, if the current transaction id
51 * matches the previous one then sfs_syncd
52 * just return 'success' to the client. If the
53 * transaction ids do not match, the actions
54 * are performed and the transaction id value
56 * 17-Jun-91 Teelucksingh Creation - multi-client
57 * synchronization server sfs_syncd.
58 * Processes the sfs sync rpcs between systems.
63 * ------------------------- Include Files -------------------------
76 #include <sys/types.h>
79 #include <sys/signal.h>
82 #include "sfs_c_def.h"
83 #include "sfs_m_def.h"
87 * ----------------------- External Definitions -----------------------
90 /* forward definitions for local routines */
91 static void sfs_syncprog_1(struct svc_req *, SVCXPRT *);
92 static int * signal_sync_sfs_1(struct sync_string *);
93 static void lad_syncd_cleanup(int);
96 * ----------------------- Static Definitions -----------------------
99 int Debug_level = 0; /* flag indicates prime client debug mode */
100 char *sfs_Myname; /* program name */
102 static char previous_transaction[MAX_STR1_LEN]; /* to hold transaction id */
106 * ------------------- Multi-client Synchronization -------------------
119 #if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
120 struct sigaction sig_act, old_sig_act;
121 #endif /* USE_POSIX_SIGNALS */
124 * Place pid in pid log file
126 if ((pid_fp = fopen(SFS_SYNCD_PID, "a+")) == NULL) {
127 perror(SFS_SYNCD_PID);
128 (void) unlink(SFS_SYNCD_PID);
131 (void) fprintf(pid_fp, "%d\n", getpid());
132 (void) fclose(pid_fp);
134 sfs_Myname = argv[0];
136 if ((nameptr = strrchr(argv[0], '/')) != NULL)
137 sfs_Myname = ++nameptr;
139 #if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
140 /* use XOPEN signal handling */
141 sig_act.sa_handler = generic_catcher;
142 (void)sigemptyset(&sig_act.sa_mask);
143 sig_act.sa_flags = 0;
145 /* signals handlers for signals used by sfs_prime */
146 sig_act.sa_handler = lad_syncd_cleanup;
147 if (sigaction(SIGINT,&sig_act,&old_sig_act) != 0) {
148 perror("sigaction failed: SIGINT");
149 (void) unlink(SFS_SYNCD_PID);
153 /* set up SIGINT signal handler */
154 (void) signal(SIGINT, lad_syncd_cleanup);
155 #endif /* USE_POSIX_SIGNALS */
157 (void) fprintf(stderr,"--------------------\n");
158 (void) fprintf(stderr,"Start of sfs run.\n");
160 (void) pmap_unset(SFS_SYNCPROG, SFS_SYNCVERS);
162 transp = svcudp_create(RPC_ANYSOCK);
163 if (transp == ((SVCXPRT *) NULL)) {
164 (void) fprintf(stderr, "%s: cannot create udp service.\n", sfs_Myname);
165 (void) unlink(SFS_SYNCD_PID);
168 if (!svc_register(transp, SFS_SYNCPROG, SFS_SYNCVERS,
169 sfs_syncprog_1, IPPROTO_UDP)) {
170 (void) fprintf(stderr,
171 "%s: unable to register (SFS_SYNCPROG,SFS_SYNCVERS, udp).\n",
173 (void) unlink(SFS_SYNCD_PID);
177 transp = svctcp_create(RPC_ANYSOCK, 0, 0);
178 if (transp == ((SVCXPRT *) NULL)) {
179 (void) fprintf(stderr, "%s: cannot create tcp service.\n", sfs_Myname);
180 (void) unlink(SFS_SYNCD_PID);
183 if (!svc_register(transp, SFS_SYNCPROG, SFS_SYNCVERS,
184 sfs_syncprog_1, IPPROTO_TCP)) {
185 (void) fprintf(stderr,
186 "%s: unable to register (SFS_SYNCPROG, SFS_SYNCVERS, tcp).\n",
188 (void) unlink(SFS_SYNCD_PID);
193 (void) fprintf(stderr, "%s: svc_run returned\n", sfs_Myname);
201 struct svc_req * rqstp,
205 sync_string signal_sync_sfs_1_arg;
208 bool_t (*xdr_argument)(), (*xdr_result)();
211 switch (rqstp->rq_proc) {
212 case SIGNAL_NULLPROC:
213 (void) svc_sendreply(transp, xdr_void, (char *)NULL);
217 xdr_argument = xdr_sync_string;
218 xdr_result = xdr_int;
219 local = (char * (*)()) signal_sync_sfs_1;
223 svcerr_noproc(transp);
226 (void) memset((char *) &argument, '\0', sizeof(argument));
227 if (!svc_getargs(transp, xdr_argument, (caddr_t)&argument)) {
228 svcerr_decode(transp);
231 result = (*local)(&argument);
232 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
233 svcerr_systemerr(transp);
235 if (!svc_freeargs(transp, xdr_argument, (caddr_t)&argument)) {
236 (void) fprintf(stderr, "%s: unable to free arguments\n", sfs_Myname);
237 (void) unlink(SFS_SYNCD_PID);
241 } /* sfs_syncprog_1 */
245 * signal_sync_sfs_1 - multi-client synch RPC
246 * Provides interface between sfs program running
247 * on multiple clients and the controlling sfs_prime program.
251 struct sync_string * sfs_signal)
253 static int result = 0 ; /* return status - failure */
255 int sfs_pid; /* sfs parent process pid */
256 char datafile[SFS_MAXPATHLEN]; /* results file */
257 char CL_Logname[SFS_MAXPATHLEN];
260 /* if a duplicate transactions then just return success to calling client */
261 if (strcmp(sfs_signal->clnt_transaction, previous_transaction) == 0) {
262 (void) fprintf(stderr,"%s: Got a duplicate signal - %s\n",
263 sfs_Myname, sfs_signal->clnt_transaction);
268 if (strcmp(sfs_signal->clnt_type,"CLIENT_SIGNAL") == 0) {
271 * message from parent sfs process on client to Prime-client
274 * Append client id to Prime client sync logfile
276 fp = fopen(SFS_PRIME_SYNC_LOG, "a");
278 (void) fprintf(stderr,"%s: Cannot open %s\n",
279 sfs_Myname, SFS_PRIME_SYNC_LOG);
282 (void) fwrite((char *)&sfs_signal->clnt_id,
283 sizeof(sfs_signal->clnt_id), 1, fp);
286 (void) sprintf(previous_transaction, sfs_signal->clnt_transaction);
287 (void) fprintf(stderr,"%s: Got Client_SIGNAL - %s\n",
288 sfs_Myname, sfs_signal->clnt_transaction);
289 return (&result); /* success */
291 } else if (strcmp(sfs_signal->clnt_type,"CLIENT_DATA") == 0) {
294 * message from parent sfs process on client to Prime-client
295 * completed run, here are my results. Write it to file and let
296 * Prime client know about it.
298 (void) sprintf(datafile,"%s%d",
299 PRIME_RESULTS_LOG, sfs_signal->clnt_id);
300 fp = fopen(datafile, "w");
302 (void) fprintf(stderr,"%s: Cannot open %s\n",
303 sfs_Myname, datafile);
306 (void) fprintf(fp,"%s",sfs_signal->clnt_data);
309 /* after writing data write client id to sync log */
310 fp = fopen(SFS_PRIME_SYNC_LOG, "a");
312 (void) fprintf(stderr,"%s: Cannot open %s\n",
313 sfs_Myname, SFS_PRIME_SYNC_LOG);
316 (void) fwrite((char *)&sfs_signal->clnt_id,
317 sizeof(sfs_signal->clnt_id), 1, fp);
320 /* let the remote process know success */
322 (void) sprintf(previous_transaction, sfs_signal->clnt_transaction);
323 (void) fprintf(stderr,"%s: Got Client_DATA - %s\n",
324 sfs_Myname, sfs_signal->clnt_transaction);
327 } else if (strcmp(sfs_signal->clnt_type,"CLIENT_STOP") == 0) {
330 * message from parent sfs process on client to Prime-client
331 * (sfs_prime) to stop due to error.
333 fp = fopen(SFS_PRIME_SYNC_LOG, "a");
335 (void) fprintf(stderr,"%s: Cannot open %s\n",
336 sfs_Myname, SFS_PRIME_SYNC_LOG);
340 * Write out client id 1000 times to fool prime into thinking
341 * all clients have responded and will get an error when it
342 * tries to communicate to it.
344 for (result = 0; result < 1000; result++)
345 (void) fwrite((char *)&sfs_signal->clnt_id,
346 sizeof(sfs_signal->clnt_id), 1, fp);
349 (void) sprintf(previous_transaction, sfs_signal->clnt_transaction);
350 (void) fprintf(stderr,"%s: Got Client_STOP - %s\n",
351 sfs_Myname, sfs_signal->clnt_transaction);
352 return (&result); /* success */
354 } else if (strcmp(sfs_signal->clnt_type,"PRIME_SIGNAL") == 0) {
357 * message from the Prime client (sfs_prime)
358 * send SIGUSR1 signal to parent sfs process on
359 * client - signals it to proceed
361 (void) sprintf(CL_Logname,"%s%d",
362 SFS_CLIENT_SYNC_LOG, sfs_signal->clnt_id);
363 fp = fopen(CL_Logname, "r");
365 (void) fprintf(stderr,"%s: Cannot open %s\n",
366 sfs_Myname, CL_Logname);
369 if (fscanf(fp,"%d",&sfs_pid) != 1)
371 if ((int) generic_kill(sfs_pid, SIGUSR1) == 0) {
373 (void) sprintf(previous_transaction,
374 sfs_signal->clnt_transaction);
375 (void) fprintf(stderr,"%s: Got PRIME_SIGNAL(SIGUSR1) - %s\n",
376 sfs_Myname, sfs_signal->clnt_transaction);
377 (void) fprintf(stderr," Sent SIGUSR1\n");
378 return (&result); /* success */
382 } else if (strcmp(sfs_signal->clnt_type,"PRIME_ALARM") == 0) {
385 * message from the Prime client (sfs_prime)
386 * send SIGALRM signal to parent sfs process on
387 * client - tell it to wake up and finish execution at this time
390 (void) sprintf(CL_Logname,"%s%d",
391 SFS_CLIENT_SYNC_LOG, sfs_signal->clnt_id);
392 fp = fopen(CL_Logname, "r");
394 (void) fprintf(stderr,"%s: Cannot open %s\n",
395 sfs_Myname, CL_Logname);
398 if (fscanf(fp,"%d",&sfs_pid) != 1)
400 if ((int) generic_kill(sfs_pid, SIGALRM) == 0) {
402 (void) sprintf(previous_transaction,
403 sfs_signal->clnt_transaction);
404 (void) fprintf(stderr,"%s: Got PRIME_ALARM(SIGALRM) - %s\n",
405 sfs_Myname, sfs_signal->clnt_transaction);
406 (void) fprintf(stderr," Sent SIGALRM\n");
407 return (&result); /* success */
411 } else if (strcmp(sfs_signal->clnt_type,"PRIME_STOP") == 0) {
414 * message from Prime-client
415 * sent SIGINT signal to sfs parent process
416 * to tell it to terminate experiment now
418 (void) sprintf(CL_Logname,"%s%d",
419 SFS_CLIENT_SYNC_LOG, sfs_signal->clnt_id);
420 fp = fopen(CL_Logname, "r");
422 (void) fprintf(stderr,"%s: Cannot open %s\n",
423 sfs_Myname, CL_Logname);
426 if (fscanf(fp,"%d",&sfs_pid) != 1)
428 if ((int) generic_kill(sfs_pid, SIGINT) == 0) {
430 (void) sprintf(previous_transaction,
431 sfs_signal->clnt_transaction);
432 (void) fprintf(stderr,"%s: Got PRIME_STOP(SIGSTOP) - %s\n",
433 sfs_Myname, sfs_signal->clnt_transaction);
434 (void) fprintf(stderr," Sent SIGINT\n");
435 return (&result); /* success */
440 return (&result); /* failure */
442 } /* signal_sync_sfs_1 */
449 (void) pmap_unset(SFS_SYNCPROG, SFS_SYNCVERS);
450 (void) fprintf(stderr, "Unregistered sfs_syncd.\n");
451 (void) unlink(SFS_SYNCD_PID);
454 } /* lad_syncd_cleanup */