diff -ru old/CVS/Entries clusterit-1.1/CVS/Entries --- old/CVS/Entries Thu Oct 15 17:35:45 1998 +++ clusterit-1.1/CVS/Entries Tue Oct 20 00:27:51 1998 @@ -3,5 +3,6 @@ D/pcp//// D/src//// D/barrier//// -/Makefile/1.3/Wed Oct 14 07:24:32 1998// -/README/1.3/Fri Oct 16 00:35:45 1998// +D/regress//// +/Makefile/1.4/Tue Oct 20 07:27:51 1998// +/README/1.4/Tue Oct 20 07:27:51 1998// diff -ru old/Makefile clusterit-1.1/Makefile --- old/Makefile Wed Oct 14 00:24:32 1998 +++ clusterit-1.1/Makefile Tue Oct 20 00:37:05 1998 @@ -1,24 +1,24 @@ -# $Id: Makefile,v 1.3 1998/10/14 07:24:32 garbled Exp $ +# $Id: Makefile,v 1.4 1998/10/20 07:27:51 garbled Exp $ # Makefile for clusterit: Tim Rightnour OPSYS!= uname -CC?= /usr/local/bin/gcc +#CC= /usr/local/bin/gcc CFLAGS= -O2 -Wall PREFIX?= /usr/local SUBDIR= dsh pcp barrier all: - for dir in ${SUBDIR} ; do \ + @for dir in ${SUBDIR} ; do \ (cd $$dir && make CC=${CC} "CFLAGS=${CFLAGS}" OPSYS=${OPSYS}) ;\ done clean: - for dir in ${SUBDIR} ; do \ + @for dir in ${SUBDIR} ; do \ (cd $$dir && make clean OPSYS=${OPSYS}) ;\ done install: - for dir in ${SUBDIR} ; do \ + @for dir in ${SUBDIR} ; do \ (cd $$dir && make install OPSYS=${OPSYS} PREFIX=${PREFIX}) ;\ done diff -ru old/README clusterit-1.1/README --- old/README Thu Oct 15 17:35:45 1998 +++ clusterit-1.1/README Tue Oct 20 00:27:51 1998 @@ -1,4 +1,4 @@ -$Id: README,v 1.3 1998/10/16 00:35:45 garbled Exp $ +$Id: README,v 1.4 1998/10/20 07:27:51 garbled Exp $ Welcome to clusterit-1.1 ! @@ -74,9 +74,6 @@ this suite. Things to do still: - -anynode - Run a program on "any old node" on the cluster. supper Mimic IBM's supper suite.. but do a better job of diff -ru old/barrier/CVS/Entries clusterit-1.1/barrier/CVS/Entries --- old/barrier/CVS/Entries Wed Oct 14 13:43:51 1998 +++ clusterit-1.1/barrier/CVS/Entries Tue Oct 20 00:27:14 1998 @@ -1,6 +1,6 @@ -/Makefile/1.1/Wed Oct 14 07:23:24 1998// /barrierd.1/1.1/Wed Oct 14 09:23:15 1998// -/barrier.c/1.4/Wed Oct 14 20:43:50 1998// /barrier.1/1.2/Wed Oct 14 20:43:50 1998// -/barrierd.c/1.3/Wed Oct 14 20:43:51 1998// +/barrier.c/1.5/Tue Oct 20 07:26:33 1998// +/barrierd.c/1.4/Tue Oct 20 07:26:34 1998// +/Makefile/1.3/Tue Oct 20 07:27:14 1998// D diff -ru old/barrier/Makefile clusterit-1.1/barrier/Makefile --- old/barrier/Makefile Wed Oct 14 02:56:32 1998 +++ clusterit-1.1/barrier/Makefile Tue Oct 20 00:27:14 1998 @@ -1,22 +1,26 @@ -# $Id: Makefile,v 1.1 1998/10/14 07:23:24 garbled Exp $ +# $Id: Makefile,v 1.3 1998/10/20 07:27:14 garbled Exp $ # barrier Makefile: Tim Rightnour -CC?= /usr/local/bin/gcc +# Some options need to be uncommented for Solaris + +#CC= /usr/local/bin/gcc CFLAGS?= -Wall -O2 PROGS= barrierd barrier - +#LIBS= -lsocket -lnsl +# BSRCS= barrier.c DSRCS= barrierd.c +#DSRCS+= strsep.c MAN= barrierd.1 barrier.1 all: barrier barrierd barrier: ${BSRCS:.c=.o} - ${CC} ${CFLAGS} -o $@ ${BSRCS:.c=.o} + ${CC} ${CFLAGS} -o $@ ${BSRCS:.c=.o} ${LIBS} barrierd: ${DSRCS:.c=.o} - ${CC} ${CFLAGS} -o $@ ${DSRCS:.c=.o} + ${CC} ${CFLAGS} -o $@ ${DSRCS:.c=.o} ${LIBS} install: ${PROGS} /usr/bin/install -c -s -o bin -g bin -m 0755 barrier ${PREFIX}/bin diff -ru old/barrier/barrier.c clusterit-1.1/barrier/barrier.c --- old/barrier/barrier.c Wed Oct 14 13:43:50 1998 +++ clusterit-1.1/barrier/barrier.c Tue Oct 20 00:26:33 1998 @@ -1,4 +1,4 @@ -/* $Id: barrier.c,v 1.4 1998/10/14 20:43:50 garbled Exp $ */ +/* $Id: barrier.c,v 1.5 1998/10/20 07:26:33 garbled Exp $ */ /* * Copyright (c) 1998 * Tim Rightnour. All rights reserved. @@ -40,14 +40,14 @@ #include #include -#ifndef lint +#if !defined(lint) && defined(__NetBSD__) __COPYRIGHT( "@(#) Copyright (c) 1998\n\ Tim Rightnour. All rights reserved\n"); #endif /* not lint */ -#ifndef lint -__RCSID("$Id: barrier.c,v 1.4 1998/10/14 20:43:50 garbled Exp $"); +#if !defined(lint) && defined(__NetBSD__) +__RCSID("$Id: barrier.c,v 1.5 1998/10/20 07:26:33 garbled Exp $"); #endif #define BARRIER_SOCK 1933 /* default socket for barrier */ @@ -118,7 +118,7 @@ exit(EXIT_FAILURE); } - code = make_barrier(key,nodes); + code = make_barrier(key, nodes); if (code == 6) { if (!quietflag) (void)printf("Barrier met, continuing: %s\n", key); @@ -163,7 +163,7 @@ } if (!quietflag) (void)printf("Barrier syncing with token: %s\n", key); - sprintf(message, "%s %d", key, nodes); + (void)sprintf(message, "%s %d", key, nodes); write_to_server(sock, message); return(read(sock, &p, 6)); } diff -ru old/barrier/barrierd.c clusterit-1.1/barrier/barrierd.c --- old/barrier/barrierd.c Wed Oct 14 13:43:51 1998 +++ clusterit-1.1/barrier/barrierd.c Tue Oct 20 00:26:34 1998 @@ -1,4 +1,4 @@ -/* $Id: barrierd.c,v 1.3 1998/10/14 20:43:51 garbled Exp $ */ +/* $Id: barrierd.c,v 1.4 1998/10/20 07:26:34 garbled Exp $ */ /* * Copyright (c) 1998 * Tim Rightnour. All rights reserved. @@ -41,14 +41,14 @@ #include #include -#ifndef lint +#if !defined(lint) && defined(__NetBSD__) __COPYRIGHT( "@(#) Copyright (c) 1998\n\ Tim Rightnour. All rights reserved\n"); #endif /* not lint */ -#ifndef lint -__RCSID("$Id: barrierd.c,v 1.3 1998/10/14 20:43:51 garbled Exp $"); +#if !defined(lint) && defined(__NetBSD__) +__RCSID("$Id: barrierd.c,v 1.4 1998/10/20 07:26:34 garbled Exp $"); #endif #define BARRIER_SOCK 1933 /* default socket for barrier */ @@ -63,6 +63,11 @@ int sleeper __P((void)); int write_to_client __P((int filedes, char *buf)); int read_from_client __P((int filedes, char **j)); +#else +int make_socket(void); +int sleeper(void); +int write_to_client(int filedes, char *buf); +int read_from_client(int filedes, char **j); #endif int main(argc, argv) @@ -212,11 +217,11 @@ #endif FD_SET(new, &active_fd_set); if (read_from_client(new, &buf) > 0) { - key = strsep(&buf, " "); + key = (char *)strsep(&buf, " "); found = 0; for (k=0; (found == 0 && k < MAX_TOKENS); ) { if (tokens[k] != NULL) - if (strcmp(tokens[k],key) == 0) + if (strcmp(tokens[k], key) == 0) found = 1; if (!found) k++; Only in clusterit-1.1/barrier: strsep.c diff -ru old/dsh/CVS/Entries clusterit-1.1/dsh/CVS/Entries --- old/dsh/CVS/Entries Thu Oct 15 17:58:03 1998 +++ clusterit-1.1/dsh/CVS/Entries Tue Oct 20 00:32:39 1998 @@ -1,9 +1,9 @@ /strsep.c/1.2/Tue Oct 13 07:05:23 1998// -/dsh.c/1.4/Thu Oct 15 07:04:47 1998// -/dsh.1/1.5/Thu Oct 15 19:40:28 1998// -/seq.c/1.3/Thu Oct 15 19:47:38 1998// -/run.1/1.1/Thu Oct 15 21:49:43 1998// -/run.c/1.2/Thu Oct 15 21:49:43 1998// -/seq.1/1.2/Thu Oct 15 21:49:44 1998// -/Makefile/1.7/Fri Oct 16 00:58:02 1998// +/Makefile/1.8/Tue Oct 20 07:28:43 1998// +/dsh.c/1.5/Tue Oct 20 07:28:44 1998// +/run.c/1.3/Tue Oct 20 07:28:44 1998// +/seq.c/1.4/Tue Oct 20 07:28:44 1998// +/dsh.1/1.6/Tue Oct 20 07:32:38 1998// +/run.1/1.2/Tue Oct 20 07:32:39 1998// +/seq.1/1.3/Tue Oct 20 07:32:39 1998// D diff -ru old/dsh/Makefile clusterit-1.1/dsh/Makefile --- old/dsh/Makefile Thu Oct 15 17:58:02 1998 +++ clusterit-1.1/dsh/Makefile Tue Oct 20 00:28:43 1998 @@ -1,22 +1,22 @@ -# $Id: Makefile,v 1.7 1998/10/16 00:58:02 garbled Exp $ +# $Id: Makefile,v 1.8 1998/10/20 07:28:43 garbled Exp $ # dsh Makefile: Tim Rightnour +# Some of the below needs to be uncommented for Solaris to work. + #CC= /usr/local/bin/gcc CFLAGS= -Wall -O2 PROGS= dsh seq run -OPSYS!= uname -.if ${OPSYS} != NetBSD -SSRCS= strsep.c -.else +OBJS= dsh.o seq.o run.o +#SSRCS= strsep.o SSRCS= -.endif MAN= dsh.1 seq.1 run.1 -all: ${PROGS}.c ${SSRCS} - for prog in ${PROGS} ; do \ - ${CC} ${CFLAGS} -o $$prog $$prog.c ${SSRCS}; \ +all: ${OBJS} ${SSRCS} + @for prog in ${PROGS} ; do \ + echo ${CC} ${CFLAGS} -o $$prog $$prog.o ${SSRCS}; \ + ${CC} ${CFLAGS} -o $$prog $$prog.o ${SSRCS}; \ done install: ${PROGS} ${MAN} Only in old/dsh: dsh diff -ru old/dsh/dsh.1 clusterit-1.1/dsh/dsh.1 --- old/dsh/dsh.1 Thu Oct 15 12:40:28 1998 +++ clusterit-1.1/dsh/dsh.1 Tue Oct 20 00:32:38 1998 @@ -1,4 +1,4 @@ -.\" $Id: dsh.1,v 1.5 1998/10/15 19:40:28 garbled Exp $ +.\" $Id: dsh.1,v 1.6 1998/10/20 07:32:38 garbled Exp $ .\" Copyright (c) 1998 .\" Tim Rightnour. All rights reserved. .\" @@ -39,7 +39,7 @@ .Nm .Op Fl eiq .Op Ar -f fanout -.Op Ar -g rungroup +.Op Ar -g rungroup1,...,rungroupN .Op Ar -l username .Op Ar -w node1,...,nodeN .Op Ar command ... @@ -81,7 +81,7 @@ .It Fl g If the .Fl g -option is specified, followed by a group name, the command will only be run on that group +option is specified, followed by a comma separated list of group names, the command will only be run on that group of nodes. A node may be a part of more than one group if desired, however running without the .Fl g option will run the command on the same node as many times as it appears in the diff -ru old/dsh/dsh.c clusterit-1.1/dsh/dsh.c --- old/dsh/dsh.c Thu Oct 15 00:04:47 1998 +++ clusterit-1.1/dsh/dsh.c Tue Oct 20 00:28:44 1998 @@ -1,4 +1,4 @@ -/* $Id: dsh.c,v 1.4 1998/10/15 07:04:47 garbled Exp $ */ +/* $Id: dsh.c,v 1.5 1998/10/20 07:28:44 garbled Exp $ */ /* * Copyright (c) 1998 * Tim Rightnour. All rights reserved. @@ -38,18 +38,19 @@ #include #include -#ifndef lint +#if !defined(lint) && defined(__NetBSD__) __COPYRIGHT( "@(#) Copyright (c) 1998\n\ Tim Rightnour. All rights reserved\n"); #endif /* not lint */ -#ifndef lint -__RCSID("$Id: dsh.c,v 1.4 1998/10/15 07:04:47 garbled Exp $"); +#if !defined(lint) && defined(__NetBSD__) +__RCSID("$Id: dsh.c,v 1.5 1998/10/20 07:28:44 garbled Exp $"); #endif #define MAX_CLUSTER 512 #define DEFAULT_FANOUT 64 +#define MAX_GROUPS 32 extern int errno; #ifdef __NetBSD__ @@ -68,7 +69,7 @@ int debug; int errorflag; char *grouplist[MAX_CLUSTER]; -char *rungroup; +char *rungroup[MAX_GROUPS]; /* * dsh is a cluster management tool derrived from the IBM tool of the @@ -101,7 +102,8 @@ fanout = DEFAULT_FANOUT; username = NULL; group = NULL; - rungroup = NULL; + for (i=0; i < MAX_GROUPS; i++) + rungroup[i] = NULL; while ((ch = getopt(argc, argv, "?eiqf:g:l:w:x:")) != -1) switch (ch) { @@ -122,12 +124,19 @@ fanflag = 1; break; case 'g': /* pick a group to run on */ - rungroup = strdup(optarg); + i = 0; + for (p = optarg; p != NULL && i < MAX_GROUPS - 1; ) { + group = (char *)strsep(&p, ","); + if (group != NULL) + rungroup[i++] = strdup(group); + } + rungroup[i] = '\0'; + group = NULL; break; case 'x': /* exclude nodes, w overrides this */ exclusion = 1; i = 0; - for (p = optarg; p != NULL; ) { + for (p = optarg; p != NULL && i < MAX_CLUSTER - 1; ) { nodename = (char *)strsep(&p, ","); if (nodename != NULL) exclude[i++] = strdup(nodename); @@ -137,7 +146,7 @@ case 'w': /* perform operation on these nodes */ someflag = 1; i = 0; - for (p = optarg; p != NULL; ) { + for (p = optarg; p != NULL && i < MAX_CLUSTER - 1; ) { nodename = (char *)strsep(&p, ","); if (nodename != NULL) nodelist[i++] = strdup(nodename); @@ -146,7 +155,7 @@ break; case '?': /* you blew it */ (void)fprintf(stderr, - "usage: dsh [-eiq] [-f fanout] [-g rungroup] [-l username] [-x node1,...,nodeN] [-w node1,..,nodeN] [command ...]\n"); + "usage: dsh [-eiq] [-f fanout] [-g rungroup1,...,rungroupN] [-l username] [-x node1,...,nodeN] [-w node1,..,nodeN] [command ...]\n"); exit(EXIT_FAILURE); break; default: @@ -158,7 +167,7 @@ if (!someflag) { /* if -w wasn't specified, we need to parse the cluster file */ clusterfile = getenv("CLUSTER"); if (clusterfile == NULL) { - fprintf(stderr, "must use -w flag without CLUSTER environment setting.\n"); + (void)fprintf(stderr, "must use -w flag without CLUSTER environment setting.\n"); exit(EXIT_FAILURE); } fd = fopen(clusterfile, "r"); @@ -169,7 +178,7 @@ if (exclusion) { /* this handles the -x option */ fail = 0; for (j = 0; exclude[j] != NULL; j++) - if (strcmp(p,exclude[j]) == 0) + if (strcmp(p, exclude[j]) == 0) fail = 1; if (!fail) { if (strstr(p, "GROUP") != NULL) { @@ -207,6 +216,7 @@ exit(EXIT_SUCCESS); } do_command(argv, nodelist, fanout, username); + exit(EXIT_SUCCESS); } /* @@ -222,8 +232,7 @@ int i, j, l, n; i = l = 0; - - if (rungroup == NULL) + if (rungroup[0] == NULL) for (i=0; nodelist[i] != NULL; i++) /* just count the nodes */ ; else @@ -235,22 +244,36 @@ if (i % fanout) j++; - if (rungroup != NULL) - (void)printf("Rungroup: %s\n", rungroup); + if (rungroup[0] != NULL) { + (void)printf("Rungroup:"); + for (i=0; rungroup[i] != NULL; i++) { + if (!(i % 4) && i > 0) + (void)printf("\n"); + (void)printf("\t%s", rungroup[i]); + } + if (i % 4) + (void)printf("\n"); + } if (getenv("CLUSTER")) (void)printf("Cluster file: %s\n", getenv("CLUSTER")); - printf("Fanout size: %d\n", fanout); + (void)printf("Fanout size: %d\n", fanout); for (n=0; n <= j; n++) { for (i=n * fanout; ((nodelist[i] != NULL) && (i < (n + 1) * fanout)); i++) { - if (rungroup != NULL) { + if (rungroup[0] != NULL) { if (test_node(i)) { l++; - printf("Node: %3d Fangroup: %3d Rungroup: %s Host: %s\n", l, n + 1, grouplist[i], nodelist[i]); + if (grouplist[i] == NULL) + (void)printf("Node: %3d\tFangroup: %3d\tRungroup: None\tHost: %s\n", l, n + 1, nodelist[i]); + else + (void)printf("Node: %3d\tFangroup: %3d\tRungroup: %s\tHost: %s\n", l, n + 1, grouplist[i], nodelist[i]); } } else { l++; - printf("Node: %3d Fangroup: %3d Rungroup: %s Host: %s\n", l, n + 1, grouplist[i], nodelist[i]); + if (grouplist[i] == NULL) + (void)printf("Node: %3d\tFangroup: %3d\tRungroup: None\tHost: %s\n", l, n + 1, nodelist[i]); + else + (void)printf("Node: %3d\tFangroup: %3d\tRungroup: %s\tHost: %s\n", l, n + 1, grouplist[i], nodelist[i]); } } } @@ -283,23 +306,23 @@ if (debug) { if (username != NULL) - printf("As User: %s\n",username); - printf("On nodes:"); + (void)printf("As User: %s\n", username); + (void)printf("On nodes:"); for (i=0; nodelist[i] != NULL; i++) { if (!(j % 4) && j > 0) - printf("\n"); - if (rungroup != NULL) { + (void)printf("\n"); + if (rungroup[0] != NULL) { if (test_node(i)) { - printf("%s\t", nodelist[i]); + (void)printf("%s\t", nodelist[i]); j++; } } else { - printf("%s\t", nodelist[i]); + (void)printf("%s\t", nodelist[i]); j++; } } } else { - if (rungroup == NULL) + if (rungroup[0] == NULL) for (i=0; nodelist[i] != NULL; i++) /* just count the nodes */ ; else @@ -318,13 +341,13 @@ strcat(command, " "); } if (debug) { - printf("\nDo Command: %s\n", command); - printf("Fanout: %d Groups:%d\n", fanout, j); + (void)printf("\nDo Command: %s\n", command); + (void)printf("Fanout: %d Groups:%d\n", fanout, j); } if (strcmp(command,"") == 0) { piping = 1; if (isatty(STDIN_FILENO) && piping) /* are we a terminal? then go interactive! */ - printf("dsh>"); + (void)printf("dsh>"); in = fdopen(STDIN_FILENO, "r"); command = fgets(buf, sizeof(buf), in); /* start reading stuff from stdin and process */ if (command != NULL) @@ -338,7 +361,7 @@ if (test_node(i)) { g = i - n * fanout; #ifdef DEBUG - printf("Working node: %d, group %d, fanout part: %d\n", i, n, g); + (void)printf("Working node: %d, group %d, fanout part: %d\n", i, n, g); #endif pipe(out[i]); /* we set up pipes for each node, to prepare for the oncoming barrage of data */ pipe(err[i]); @@ -359,7 +382,7 @@ if (rsh == NULL) rsh = "rsh"; #ifdef DEBUG - printf("%s %s %s\n", rsh, nodelist[i], command); + (void)printf("%s %s %s\n", rsh, nodelist[i], command); #endif if (username != NULL) /* interestingly enough, this -l thing works great with ssh */ execlp(rsh, rsh, "-l", username, nodelist[i], command, (char *)0); @@ -378,12 +401,12 @@ bailout(__LINE__); fd = fdopen(out[g][0], "r"); /* stdout */ while ((p = fgets(buf, sizeof(buf), fd))) - printf("%s:\t%s", nodelist[i], p); + (void)printf("%s:\t%s", nodelist[i], p); fclose(fd); fd = fdopen(err[g][0], "r"); /* stderr */ while ((p = fgets(buf, sizeof(buf), fd))) if (errorflag) - printf("%s:\t%s", nodelist[i], p); + (void)printf("%s:\t%s", nodelist[i], p); fclose(fd); (void)wait(&status); } /* test_node */ @@ -391,7 +414,7 @@ } /* for n */ if (piping) { if (isatty(STDIN_FILENO) && piping) /* yes, this is code repetition, no need to adjust your monitor */ - printf("dsh>"); + (void)printf("dsh>"); command = fgets(buf, sizeof(buf), in); if (command != NULL) if (strcmp(command,"\n") == 0) @@ -409,12 +432,15 @@ int test_node(int count) { - if (rungroup == NULL) + int i; + + if (rungroup[0] == NULL) return(1); else if (grouplist[count] != NULL) - if (strcmp(rungroup,grouplist[count]) == 0) - return(1); + for (i=0; rungroup[i] != NULL; i++) + if (strcmp(rungroup[i], grouplist[count]) == 0) + return(1); return(0); } Only in old/dsh: run diff -ru old/dsh/run.1 clusterit-1.1/dsh/run.1 --- old/dsh/run.1 Thu Oct 15 14:49:43 1998 +++ clusterit-1.1/dsh/run.1 Tue Oct 20 00:32:39 1998 @@ -1,4 +1,4 @@ -.\" $Id: run.1,v 1.1 1998/10/15 21:49:43 garbled Exp $ +.\" $Id: run.1,v 1.2 1998/10/20 07:32:39 garbled Exp $ .\" Copyright (c) 1998 .\" Tim Rightnour. All rights reserved. .\" @@ -38,7 +38,7 @@ .Sh SYNOPSIS .Nm .Op Fl aeiq -.Op Ar -g rungroup +.Op Ar -g rungroup1,...,rungroupN .Op Ar -l username .Op Ar -w node1,...,nodeN .Op Ar command ... @@ -76,7 +76,7 @@ .It Fl g If the .Fl g -option is specified, followed by a group name, the command will only be run on that group +option is specified, followed by a comma separated list of group names, the command will only be run on that group of nodes. A node may be a part of more than one group if desired, however running without the .Fl g option will run the command on the same node as many times as it appears in the diff -ru old/dsh/run.c clusterit-1.1/dsh/run.c --- old/dsh/run.c Thu Oct 15 14:49:43 1998 +++ clusterit-1.1/dsh/run.c Tue Oct 20 00:28:44 1998 @@ -1,4 +1,4 @@ -/* $Id: run.c,v 1.2 1998/10/15 21:49:43 garbled Exp $ */ +/* $Id: run.c,v 1.3 1998/10/20 07:28:44 garbled Exp $ */ /* * Copyright (c) 1998 * Tim Rightnour. All rights reserved. @@ -38,18 +38,19 @@ #include #include -#ifndef lint +#if !defined(lint) && defined(__NetBSD__) __COPYRIGHT( "@(#) Copyright (c) 1998\n\ Tim Rightnour. All rights reserved\n"); #endif /* not lint */ -#ifndef lint -__RCSID("$Id: run.c,v 1.2 1998/10/15 21:49:43 garbled Exp $"); +#if !defined(lint) && defined(__NetBSD__) +__RCSID("$Id: run.c,v 1.3 1998/10/20 07:28:44 garbled Exp $"); #endif #define MAX_CLUSTER 512 #define DEFAULT_FANOUT 64 +#define MAX_GROUPS 32 extern int errno; #ifdef __NetBSD__ @@ -70,7 +71,7 @@ int debug; int errorflag; char *grouplist[MAX_CLUSTER]; -char *rungroup; +char *rungroup[MAX_GROUPS]; /* * run is a cluster management tool derrived from the IBM tool of the @@ -102,8 +103,8 @@ allflag = 0; username = NULL; group = NULL; - rungroup = NULL; - + for (i=0; i < MAX_GROUPS; i++) + rungroup[i] = NULL; srand48(getpid()); /* seed the random number generator */ while ((ch = getopt(argc, argv, "?aeiqg:l:w:x:")) != -1) @@ -124,12 +125,19 @@ showflag = 1; break; case 'g': /* pick a group to run on */ - rungroup = strdup(optarg); + i = 0; + for (p = optarg; p != NULL && i < MAX_GROUPS - 1; ) { + group = (char *)strsep(&p, ","); + if (group != NULL) + rungroup[i++] = strdup(group); + } + rungroup[i] = '\0'; + group = NULL; break; case 'x': /* exclude nodes, w overrides this */ exclusion = 1; i = 0; - for (p = optarg; p != NULL; ) { + for (p = optarg; p != NULL && i < MAX_CLUSTER - 1; ) { nodename = (char *)strsep(&p, ","); if (nodename != NULL) exclude[i++] = strdup(nodename); @@ -139,7 +147,7 @@ case 'w': /* perform operation on these nodes */ someflag = 1; i = 0; - for (p = optarg; p != NULL; ) { + for (p = optarg; p != NULL && i < MAX_CLUSTER - 1; ) { nodename = (char *)strsep(&p, ","); if (nodename != NULL) nodelist[i++] = strdup(nodename); @@ -148,7 +156,7 @@ break; case '?': /* you blew it */ (void)fprintf(stderr, - "usage: run [-aeiq] [-g rungroup] [-l username] [-x node1,...,nodeN] [-w node1,..,nodeN] [command ...]\n"); + "usage: run [-aeiq] [-g rungroup1,...,rungroupN] [-l username] [-x node1,...,nodeN] [-w node1,..,nodeN] [command ...]\n"); exit(EXIT_FAILURE); break; default: @@ -157,7 +165,7 @@ if (!someflag) { /* if -w wasn't specified, we need to parse the cluster file */ clusterfile = getenv("CLUSTER"); if (clusterfile == NULL) { - fprintf(stderr, "must use -w flag without CLUSTER environment setting.\n"); + (void)fprintf(stderr, "must use -w flag without CLUSTER environment setting.\n"); exit(EXIT_FAILURE); } fd = fopen(clusterfile, "r"); @@ -168,7 +176,7 @@ if (exclusion) { /* this handles the -x option */ fail = 0; for (j = 0; exclude[j] != NULL; j++) - if (strcmp(p,exclude[j]) == 0) + if (strcmp(p, exclude[j]) == 0) fail = 1; if (!fail) { if (strstr(p, "GROUP") != NULL) { @@ -206,6 +214,7 @@ exit(EXIT_SUCCESS); } do_command(argv, nodelist, allflag, username); + exit(EXIT_SUCCESS); } /* @@ -221,30 +230,44 @@ l = 0; - if (rungroup != NULL) - (void)printf("Rungroup: %s\n", rungroup); + if (rungroup[0] != NULL) { + (void)printf("Rungroup:"); + for (i=0; rungroup[i] != NULL; i++) { + if (!(i % 4) && i > 0) + (void)printf("\n"); + (void)printf("\t%s", rungroup[i]); + } + if (i % 4) + (void)printf("\n"); + } if (getenv("CLUSTER")) (void)printf("Cluster file: %s\n", getenv("CLUSTER")); for (i=0; nodelist[i] != NULL; i++) { - if (rungroup != NULL) { + if (rungroup[0] != NULL) { if (test_node(i)) { l++; - printf("Node: %3d Rungroup: %s Host: %s\n", l, grouplist[i], nodelist[i]); + if (grouplist[i] == NULL) + (void)printf("Node: %3d\tRungroup: None\tHost: %s\n", l, nodelist[i]); + else + (void)printf("Node: %3d\tRungroup: %s\tHost: %s\n", l, grouplist[i], nodelist[i]); } } else { l++; - printf("Node: %3d Rungroup: %s Host: %s\n", l, grouplist[i], nodelist[i]); + if (grouplist[i] == NULL) + (void)printf("Node: %3d\tRungroup: None\tHost: %s\n", l, nodelist[i]); + else + (void)printf("Node: %3d\tRungroup: %s\tHost: %s\n", l, grouplist[i], nodelist[i]); } } - printf("Command would run on node: %s\n", nodelist[check_rand(nodelist)]); + (void)printf("Command would run on node: %s\n", nodelist[check_rand(nodelist)]); } int check_rand(char *nodelist[]) { int i, g, n; - if (rungroup == NULL) { + if (rungroup[0] != NULL) { for (n=0; nodelist[n] != NULL && test_node(n) == 0; n++) ; for (i=n; nodelist[i] != NULL && test_node(i) == 1; i++) @@ -285,8 +308,8 @@ if (debug) { if (username != NULL) - printf("As User: %s\n",username); - printf("On node: %s", nodelist[check_rand(nodelist)]); + (void)printf("As User: %s\n", username); + (void)printf("On node: %s", nodelist[check_rand(nodelist)]); } buf[0] = '\0'; @@ -296,12 +319,12 @@ strcat(command, " "); } if (debug) { - printf("\nDo Command: %s\n", command); + (void)printf("\nDo Command: %s\n", command); } if (strcmp(command,"") == 0) { piping = 1; if (isatty(STDIN_FILENO) && piping) /* are we a terminal? then go interactive! */ - printf("run>"); + (void)printf("run>"); in = fdopen(STDIN_FILENO, "r"); command = fgets(buf, sizeof(buf), in); /* start reading stuff from stdin and process */ if (command != NULL) @@ -349,17 +372,17 @@ bailout(__LINE__); fd = fdopen(out[0], "r"); /* stdout */ while ((p = fgets(buf, sizeof(buf), fd))) - printf("%s:\t%s", nodelist[i], p); + (void)printf("%s:\t%s", nodelist[i], p); fclose(fd); fd = fdopen(err[0], "r"); /* stderr */ while ((p = fgets(buf, sizeof(buf), fd))) if (errorflag) - printf("%s:\t%s", nodelist[i], p); + (void)printf("%s:\t%s", nodelist[i], p); fclose(fd); (void)wait(&status); if (piping) { if (isatty(STDIN_FILENO) && piping) /* yes, this is code repetition, no need to adjust your monitor */ - printf("run>"); + (void)printf("run>"); command = fgets(buf, sizeof(buf), in); if (command != NULL) if (strcmp(command,"\n") == 0) @@ -377,12 +400,15 @@ int test_node(int count) { - if (rungroup == NULL) + int i; + + if (rungroup[0] == NULL) return(1); else if (grouplist[count] != NULL) - if (strcmp(rungroup,grouplist[count]) == 0) - return(1); + for (i=0; rungroup[i] != NULL; i++) + if (strcmp(rungroup[i], grouplist[count]) == 0) + return(1); return(0); } Only in old/dsh: seq diff -ru old/dsh/seq.1 clusterit-1.1/dsh/seq.1 --- old/dsh/seq.1 Thu Oct 15 14:49:44 1998 +++ clusterit-1.1/dsh/seq.1 Tue Oct 20 00:32:39 1998 @@ -1,4 +1,4 @@ -.\" $Id: seq.1,v 1.2 1998/10/15 21:49:44 garbled Exp $ +.\" $Id: seq.1,v 1.3 1998/10/20 07:32:39 garbled Exp $ .\" Copyright (c) 1998 .\" Tim Rightnour. All rights reserved. .\" @@ -38,7 +38,7 @@ .Sh SYNOPSIS .Nm .Op Fl aeiq -.Op Ar -g rungroup +.Op Ar -g rungroup1,...,rungroupN .Op Ar -l username .Op Ar -w node1,...,nodeN .Op Ar command ... @@ -77,7 +77,7 @@ .It Fl g If the .Fl g -option is specified, followed by a group name, the command will only be run on that group +option is specified, followed by a comma separated list of group names, the command will only be run on that group of nodes. A node may be a part of more than one group if desired, however running without the .Fl g option will run the command on the same node as many times as it appears in the diff -ru old/dsh/seq.c clusterit-1.1/dsh/seq.c --- old/dsh/seq.c Thu Oct 15 12:47:38 1998 +++ clusterit-1.1/dsh/seq.c Tue Oct 20 00:28:44 1998 @@ -1,4 +1,4 @@ -/* $Id: seq.c,v 1.3 1998/10/15 19:47:38 garbled Exp $ */ +/* $Id: seq.c,v 1.4 1998/10/20 07:28:44 garbled Exp $ */ /* * Copyright (c) 1998 * Tim Rightnour. All rights reserved. @@ -38,18 +38,19 @@ #include #include -#ifndef lint +#if !defined(lint) && defined(__NetBSD__) __COPYRIGHT( "@(#) Copyright (c) 1998\n\ Tim Rightnour. All rights reserved\n"); #endif /* not lint */ -#ifndef lint -__RCSID("$Id: seq.c,v 1.3 1998/10/15 19:47:38 garbled Exp $"); +#if !defined(lint) && defined(__NetBSD__) +__RCSID("$Id: seq.c,v 1.4 1998/10/20 07:28:44 garbled Exp $"); #endif #define MAX_CLUSTER 512 #define DEFAULT_FANOUT 64 +#define MAX_GROUPS 32 extern int errno; #ifdef __NetBSD__ @@ -69,12 +70,13 @@ int debug; int errorflag; +int seqnumber; char *grouplist[MAX_CLUSTER]; -char *rungroup; +char *rungroup[MAX_GROUPS]; /* - * seq is a cluster management tool derrived from the IBM tool of the - * same name. It allows a user, or system administrator to issue + * seq is a cluster management tool based upon the IBM tool dsh. + * It allows a user, or system administrator to issue * commands in paralell on a group of machines. */ @@ -85,9 +87,9 @@ extern char *optarg; extern int optind; - FILE *fd, *sd; + FILE *fd; int someflag, ch, i, allflag, showflag, exclusion, j, fail; - char *p, *group, *nodelist[MAX_CLUSTER], *nodename, *clusterfile, *username, *seqfile; + char *p, *group, *nodelist[MAX_CLUSTER], *nodename, *clusterfile, *username; char *exclude[MAX_CLUSTER]; char buf[256]; @@ -95,6 +97,7 @@ extern int errorflag; someflag = 0; + seqnumber = -1; showflag = 0; exclusion = 0; debug = 0; @@ -102,7 +105,8 @@ allflag = 0; username = NULL; group = NULL; - rungroup = NULL; + for (i=0; i < MAX_GROUPS; i++) + rungroup[i] = NULL; while ((ch = getopt(argc, argv, "?aeiqg:l:w:x:")) != -1) switch (ch) { @@ -122,12 +126,19 @@ showflag = 1; break; case 'g': /* pick a group to run on */ - rungroup = strdup(optarg); + i = 0; + for (p = optarg; p != NULL && i < MAX_GROUPS - 1; ) { + group = (char *)strsep(&p, ","); + if (group != NULL) + rungroup[i++] = strdup(group); + } + rungroup[i] = '\0'; + group = NULL; break; case 'x': /* exclude nodes, w overrides this */ exclusion = 1; i = 0; - for (p = optarg; p != NULL; ) { + for (p = optarg; p != NULL && i < MAX_CLUSTER - 1; ) { nodename = (char *)strsep(&p, ","); if (nodename != NULL) exclude[i++] = strdup(nodename); @@ -137,7 +148,7 @@ case 'w': /* perform operation on these nodes */ someflag = 1; i = 0; - for (p = optarg; p != NULL; ) { + for (p = optarg; p != NULL && i < MAX_CLUSTER - 1; ) { nodename = (char *)strsep(&p, ","); if (nodename != NULL) nodelist[i++] = strdup(nodename); @@ -146,7 +157,7 @@ break; case '?': /* you blew it */ (void)fprintf(stderr, - "usage: seq [-aeiq] [-g rungroup] [-l username] [-x node1,...,nodeN] [-w node1,..,nodeN] [command ...]\n"); + "usage: seq [-aeiq] [-g rungroup1,...,rungroupN] [-l username] [-x node1,...,nodeN] [-w node1,..,nodeN] [command ...]\n"); exit(EXIT_FAILURE); break; default: @@ -155,7 +166,7 @@ if (!someflag) { /* if -w wasn't specified, we need to parse the cluster file */ clusterfile = getenv("CLUSTER"); if (clusterfile == NULL) { - fprintf(stderr, "must use -w flag without CLUSTER environment setting.\n"); + (void)fprintf(stderr, "must use -w flag without CLUSTER environment setting.\n"); exit(EXIT_FAILURE); } fd = fopen(clusterfile, "r"); @@ -166,7 +177,7 @@ if (exclusion) { /* this handles the -x option */ fail = 0; for (j = 0; exclude[j] != NULL; j++) - if (strcmp(p,exclude[j]) == 0) + if (strcmp(p, exclude[j]) == 0) fail = 1; if (!fail) { if (strstr(p, "GROUP") != NULL) { @@ -199,33 +210,49 @@ } argc -= optind; argv += optind; - /* now we do the magic to increment. God I wish netbsd semget worked */ + if (showflag) { + do_showcluster(nodelist); + exit(EXIT_SUCCESS); + } + do_command(argv, nodelist, allflag, username); + exit(EXIT_SUCCESS); +} + +/* this should be atomic, but *hello* this is *userland* */ + +void test_and_set(char *nodelist[]) +{ + int i; + char *p, *seqfile; + char buf[256]; + FILE *sd; + p = NULL; + i = 0; + seqfile = getenv("SEQ_FILE"); if (seqfile == NULL) { - sprintf(buf,"/tmp/%d.seq", getppid()); + (void)sprintf(buf, "/tmp/%d.seq", (int)getppid()); seqfile = strdup(buf); } sd = fopen(seqfile, "r"); if (sd == NULL) sd = fopen(seqfile, "w"); else { - fscanf(sd,"%s", buf); + fscanf(sd, "%s", buf); p = strdup(buf); - setenv("SEQ_LAST", p, 1); + seqnumber = atoi(p); fclose(sd); sd = fopen(seqfile, "w"); } if (sd == NULL) bailout(__LINE__); - if (showflag) { - do_showcluster(nodelist); - exit(EXIT_SUCCESS); - } - do_command(argv, nodelist, allflag, username); - p = getenv("SEQ_LAST"); - fprintf(sd,"%s",p); + i = check_seq(nodelist); + if (i == -1) + i++; + (void)fprintf(sd, "%d", i); fclose(sd); + seqnumber = i; } /* @@ -241,8 +268,16 @@ l = 0; - if (rungroup != NULL) - (void)printf("Rungroup: %s\n", rungroup); + if (rungroup[0] == NULL) { + (void)printf("Rungroup:"); + for (i=0; rungroup[i] != NULL; i++) { + if (!(i % 4) && i > 0) + (void)printf("\n"); + (void)printf("\t%s", rungroup[i]); + } + if (i % 4) + (void)printf("\n"); + } if (getenv("CLUSTER")) (void)printf("Cluster file: %s\n", getenv("CLUSTER")); @@ -250,25 +285,31 @@ if (rungroup != NULL) { if (test_node(i)) { l++; - printf("Node: %3d Rungroup: %s Host: %s\n", l, grouplist[i], nodelist[i]); + if (grouplist[i] == NULL) + (void)printf("Node: %3d\tRungroup: None\tHost: %s\n", l, nodelist[i]); + else + (void)printf("Node: %3d\tRungroup: %s\tHost: %s\n", l, grouplist[i], nodelist[i]); } } else { l++; - printf("Node: %3d Rungroup: %s Host: %s\n", l, grouplist[i], nodelist[i]); + if (grouplist[i] == NULL) + (void)printf("Node: %3d\tRungroup: None\tHost: %s\n", l, nodelist[i]); + else + (void)printf("Node: %3d\tRungroup: %s\tHost: %s\n", l, grouplist[i], nodelist[i]); } } - printf("Command would run on node: %s\n", nodelist[check_seq(nodelist)]); + (void)printf("Command would run on node: %s\n", nodelist[check_seq(nodelist)]); } int check_seq(char *nodelist[]) { int i, g; - if (rungroup == NULL) - if (getenv("SEQ_LAST") == NULL) + if (rungroup[0] == NULL) + if (seqnumber == -1) return(0); else { - g = atoi(getenv("SEQ_LAST")); + g = seqnumber; if (nodelist[g+1] == NULL) { for (i=0; nodelist[i] != NULL && test_node(i) == 0; i++) ; @@ -277,12 +318,12 @@ return(g+1); } else { - if (getenv("SEQ_LAST") == NULL) { + if (seqnumber == -1) { for (i=0; nodelist[i] != NULL && test_node(i) == 0; i++) ; return(i); } else { - g = atoi(getenv("SEQ_LAST")); + g = seqnumber; for (i=g+1; nodelist[i] != NULL && test_node(i) == 0; i++) ; if (nodelist[i] == NULL) @@ -308,7 +349,6 @@ int out[2]; int err[2]; char buf[1024]; - char bufx[6]; int status, i, piping; char *p, *command, *rsh; @@ -320,8 +360,7 @@ if (debug) { if (username != NULL) - printf("As User: %s\n",username); - printf("On node: %s", nodelist[check_seq(nodelist)]); + (void)printf("As User: %s\n", username); } buf[0] = '\0'; @@ -331,12 +370,12 @@ strcat(command, " "); } if (debug) { - printf("\nDo Command: %s\n", command); + (void)printf("Do Command: %s\n", command); } if (strcmp(command,"") == 0) { piping = 1; if (isatty(STDIN_FILENO) && piping) /* are we a terminal? then go interactive! */ - printf("seq>"); + (void)printf("seq>"); in = fdopen(STDIN_FILENO, "r"); command = fgets(buf, sizeof(buf), in); /* start reading stuff from stdin and process */ if (command != NULL) @@ -344,13 +383,13 @@ command = NULL; } if (allrun) - i = check_seq(nodelist); + test_and_set(nodelist); while (command != NULL) { if (!allrun) - i = check_seq(nodelist); -#ifdef DEBUG - printf("Working node: %d\n", i); -#endif + test_and_set(nodelist); + i = seqnumber; + if (debug) + (void)printf("On node: %s\n", nodelist[check_seq(nodelist)]); pipe(out); /* we set up pipes for each node, to prepare for the oncoming barrage of data */ pipe(err); switch (fork()) { /* its the ol fork and switch routine eh? */ @@ -384,32 +423,24 @@ bailout(__LINE__); fd = fdopen(out[0], "r"); /* stdout */ while ((p = fgets(buf, sizeof(buf), fd))) - printf("%s:\t%s", nodelist[i], p); + (void)printf("%s:\t%s", nodelist[i], p); fclose(fd); fd = fdopen(err[0], "r"); /* stderr */ while ((p = fgets(buf, sizeof(buf), fd))) if (errorflag) - printf("%s:\t%s", nodelist[i], p); + (void)printf("%s:\t%s", nodelist[i], p); fclose(fd); (void)wait(&status); if (piping) { if (isatty(STDIN_FILENO) && piping) /* yes, this is code repetition, no need to adjust your monitor */ - printf("seq>"); + (void)printf("seq>"); command = fgets(buf, sizeof(buf), in); if (command != NULL) if (strcmp(command,"\n") == 0) command = NULL; } else command = NULL; - if (!allrun) { - sprintf(bufx,"%d", i); - setenv("SEQ_LAST",bufx,1); - } } /* while loop */ - if (allrun) { - sprintf(bufx,"%d", i); - setenv("SEQ_LAST",bufx,1); - } if (piping) { /* I learned this the hard way */ fflush(in); fclose(in); @@ -420,12 +451,15 @@ int test_node(int count) { - if (rungroup == NULL) + int i; + + if (rungroup[0] == NULL) return(1); else if (grouplist[count] != NULL) - if (strcmp(rungroup,grouplist[count]) == 0) - return(1); + for (i=0; rungroup[i] != NULL; i++) + if (strcmp(rungroup[i], grouplist[count]) == 0) + return(1); return(0); } diff -ru old/pcp/CVS/Entries clusterit-1.1/pcp/CVS/Entries --- old/pcp/CVS/Entries Tue Oct 13 16:44:38 1998 +++ clusterit-1.1/pcp/CVS/Entries Tue Oct 20 00:35:50 1998 @@ -1,11 +1,11 @@ -/Makefile/1.2/Tue Oct 13 19:59:31 1998// /dshbak.1/1.1/Tue Oct 13 19:55:09 1998// /dshbak.sh/1.1/Tue Oct 13 06:58:51 1998// /pcp.1/1.2/Tue Oct 13 20:02:19 1998// -/pcp.c/1.2/Tue Oct 13 07:10:46 1998// /pdf.1/1.2/Tue Oct 13 20:01:02 1998// /pdf.sh/1.1/Tue Oct 13 06:58:51 1998// /prm.1/1.2/Tue Oct 13 20:00:20 1998// /prm.sh/1.1/Tue Oct 13 06:58:51 1998// /strsep.c/1.1/Tue Oct 13 06:58:51 1998// +/pcp.c/1.3/Tue Oct 20 07:32:58 1998// +/Makefile/1.4/Tue Oct 20 07:35:50 1998// D diff -ru old/pcp/Makefile clusterit-1.1/pcp/Makefile --- old/pcp/Makefile Tue Oct 13 12:59:31 1998 +++ clusterit-1.1/pcp/Makefile Tue Oct 20 00:35:50 1998 @@ -1,13 +1,13 @@ -# $Id: Makefile,v 1.2 1998/10/13 19:59:31 garbled Exp $ +# $Id: Makefile,v 1.4 1998/10/20 07:35:50 garbled Exp $ # Makefile for dsh: Tim Rightnour +#Uncomment things for solaris. + +#CC= /usr/local/bin/gcc PROG= pcp -.if (${OPSYS} != NetBSD) -SRCS= pcp.c strsep.c -.else +#SRCS= pcp.c strsep.c SRCS= pcp.c -.endif SCRIPTS= prm pdf dshbak MAN= pcp.1 prm.1 pdf.1 diff -ru old/pcp/pcp.c clusterit-1.1/pcp/pcp.c --- old/pcp/pcp.c Tue Oct 13 00:10:46 1998 +++ clusterit-1.1/pcp/pcp.c Tue Oct 20 00:32:58 1998 @@ -1,4 +1,4 @@ -/* $Id: pcp.c,v 1.2 1998/10/13 07:10:46 garbled Exp $ */ +/* $Id: pcp.c,v 1.3 1998/10/20 07:32:58 garbled Exp $ */ /* * Copyright (c) 1998 * Tim Rightnour. All rights reserved. @@ -36,28 +36,35 @@ #include #include -#ifndef lint +#if !defined(lint) && defined(__NetBSD__) __COPYRIGHT( "@(#) Copyright (c) 1998\n\ Tim Rightnour. All rights reserved.\n"); #endif /* not lint */ -#ifndef lint -__RCSID("$Id: pcp.c,v 1.2 1998/10/13 07:10:46 garbled Exp $"); +#if !defined(lint) && defined(__NetBSD__) +__RCSID("$Id: pcp.c,v 1.3 1998/10/20 07:32:58 garbled Exp $"); #endif - -#define MAX_CLUSTER 90 +#define MAX_CLUSTER 512 +#define DEFAULT_FANOUT 64 +#define MAX_GROUPS 32 extern int errno; #ifdef __NetBSD__ -void do_copy __P((char **argv, char *nodelist[], int recurse, int preserve)); +void do_copy __P((char **argv, char *nodelist[], int recurse, int preserve, char *username)); +int test_node __P((int count)); #else -void do_copy(char **argv, char *nodelist[], int recurse, int preserve); +void do_copy(char **argv, char *nodelist[], int recurse, int preserve, char *username); char * strsep(char **stringp, const char *delim); +int test_node(int count); #endif + +char *grouplist[MAX_CLUSTER]; +char *rungroup[MAX_GROUPS]; + /* - * pcp is a cluster management tool derrived from the IBM tool of the + * pcp is a cluster management tool based on the IBM tool of the * same name. It allows a user, or system administrator to copy files * to a cluster of machines with a single command. */ @@ -70,26 +77,55 @@ extern int optind; FILE *fd; - int someflag, ch, i, preserve, recurse; - char *p, *nodelist[MAX_CLUSTER], *nodename, *clusterfile; + int someflag, ch, i, preserve, recurse, exclusion, j, fail; + char *p, *nodelist[MAX_CLUSTER], *nodename, *clusterfile, *username, *group; char buf[256]; + char *exclude[MAX_CLUSTER]; someflag = 0; preserve = 0; recurse = 0; + exclusion = 0; + username = NULL; + group = NULL; + for (i=0; i < MAX_GROUPS; i++) + rungroup[i] = NULL; - while ((ch = getopt(argc, argv, "?prw:")) != -1) + while ((ch = getopt(argc, argv, "?prg:l:w:x:")) != -1) switch (ch) { - case 'p': + case 'p': /* preserve file modes */ preserve = 1; break; - case 'r': + case 'r': /* recursive directory operations */ recurse = 1; break; - case 'w': + case 'l': /* invoke me as some other user */ + username = strdup(optarg); + break; + case 'g': /* pick a group to run on */ + i = 0; + for (p = optarg; p != NULL && i < MAX_GROUPS - 1; ) { + group = (char *)strsep(&p, ","); + if (group != NULL) + rungroup[i++] = strdup(group); + } + rungroup[i] = '\0'; + group = NULL; + break; + case 'x': /* exclude nodes, w overrides this */ + exclusion = 1; + i = 0; + for (p = optarg; p != NULL && i < MAX_CLUSTER - 1; ) { + nodename = (char *)strsep(&p, ","); + if (nodename != NULL) + exclude[i++] = strdup(nodename); + } + exclude[i] = '\0'; + break; + case 'w': /* perform operation on these nodes */ someflag = 1; i = 0; - for (p = optarg; p != NULL; ) { + for (p = optarg; p != NULL && i < MAX_CLUSTER - 1; ) { nodename = (char *)strsep(&p, ","); if (nodename != NULL) nodelist[i++] = strdup(nodename); @@ -97,7 +133,7 @@ nodelist[i] = '\0'; break; case '?': - (void)fprintf(stderr, "usage: pcp [-w node1,..,nodeN] source_file [desitination_file]\n"); + (void)fprintf(stderr, "usage: pcp [-pr] [-g rungroup1,...,rungroupN] [-l username] [-x node1,...,nodeN] [-w node1,..,nodeN] source_file [desitination_file]\n"); exit(EXIT_FAILURE); break; default: @@ -106,22 +142,52 @@ if (!someflag) { clusterfile = getenv("CLUSTER"); if (clusterfile == NULL) { - fprintf(stderr, "must use -w flag without CLUSTER environment setting.\n"); + (void)fprintf(stderr, "must use -w flag without CLUSTER environment setting.\n"); exit(EXIT_FAILURE); } fd = fopen(clusterfile, "r"); i = 0; - while ((nodename = fgets(buf, sizeof(buf), fd))) { + while ((nodename = fgets(buf, sizeof(buf), fd)) && i < MAX_CLUSTER - 1) { p = (char *)strsep(&nodename, "\n"); if (strcmp(p, "") != 0) - nodelist[i++] = (char *)strdup(p); + if (exclusion) { /* this handles the -x args */ + fail = 0; + for (j = 0; exclude[j] != NULL; j++) + if (strcmp(p,exclude[j]) == 0) + fail = 1; + if (!fail) { + if (strstr(p, "GROUP") != NULL) { + strsep(&p, ":"); + group = strdup(p); + } else { + if (group == NULL) + grouplist[i] = NULL; + else + grouplist[i] = (char *)strdup(group); + nodelist[i++] = (char *)strdup(p); + } + } + } else { + if (strstr(p, "GROUP") != NULL) { + strsep(&p, ":"); + group = strdup(p); + } else { + if (group == NULL) + grouplist[i] = NULL; + else + grouplist[i] = (char *)strdup(group); + nodelist[i++] = (char *)strdup(p); + } + } } nodelist[i] = '\0'; + grouplist[i] = '\0'; fclose(fd); } argc -= optind; argv += optind; - do_copy(argv, nodelist, recurse, preserve); + do_copy(argv, nodelist, recurse, preserve, username); + exit(EXIT_SUCCESS); } /* @@ -129,10 +195,11 @@ * have all been parsed out. */ -void do_copy(argv, nodelist, recurse, preserve) +void do_copy(argv, nodelist, recurse, preserve, username) char **argv; char *nodelist[]; int recurse, preserve; + char *username; { char buf[256]; char args[8]; @@ -144,8 +211,11 @@ for (i=0; nodelist[i] != NULL; i++) printf("%s ", nodelist[i]); #endif - if (*argv != NULL) - source_file = strdup(*argv); + if (*argv == (char *) NULL) { + (void)fprintf(stderr, "Must specify at least one file to copy\n"); + exit(EXIT_FAILURE); + } + source_file = strdup(*argv); if (*++argv != NULL) { destination_file = strdup(*argv); } else @@ -154,20 +224,41 @@ #ifdef DEBUG printf ("\nDo Copy: %s %s\n", source_file, destination_file); #endif - for (i=0; nodelist[i] != NULL; i++) { - rcp = getenv("RCP_CMD"); - if (rcp == NULL) - rcp = "rcp"; - sprintf(args," "); - if (recurse) - strcat(args,"-r "); - if (preserve) - strcat(args,"-p "); - sprintf(buf,"%s %s %s %s:%s", rcp, args, source_file, nodelist[i], destination_file); - command = strdup(buf); + for (i=0; nodelist[i] != NULL; i++) + if (test_node(i)) { + rcp = getenv("RCP_CMD"); + if (rcp == NULL) + rcp = "rcp"; + (void)sprintf(args, " "); + if (recurse) + strcat(args, "-r "); + if (preserve) + strcat(args, "-p "); + if (username != NULL) { + strcat(args, "-l "); + strcat(args, username); + } + (void)sprintf(buf,"%s %s %s %s:%s", rcp, args, source_file, nodelist[i], destination_file); + command = strdup(buf); #ifdef DEBUG - printf("%s\n", command); + printf("%s\n", command); #endif - system(command); - } + system(command); + } +} + +/* test routine, saves a ton of repetive code */ + +int test_node(int count) +{ + int i; + + if (rungroup[0] == NULL) + return(1); + else + if (grouplist[count] != NULL) + for (i=0; rungroup[i] != NULL; i++) + if (strcmp(rungroup[i],grouplist[count]) == 0) + return(1); + return(0); } Only in clusterit-1.1: regress