*** cfengine-1.6.0/src/cfrun.c Tue Sep 26 08:19:32 2000 --- cfrun.c-1.6.0 Thu Dec 21 02:17:03 2000 *************** *** 30,33 **** --- 30,34 ---- /* Mark Burgess 1997 */ /* modified : Bas van der Vlies 1998 */ + /* modified : Andrew Mayhew 2000 */ /* */ /*******************************************************************/ *************** *** 53,57 **** struct Item *VCFRUNHOSTLIST = NULL; ! char *VCFRUNHOSTS = "cfrun.hosts"; char CFRUNOPTIONS[bufsize]; --- 54,58 ---- struct Item *VCFRUNHOSTLIST = NULL; ! char VCFRUNHOSTS[bufsize] = "cfrun.hosts"; char CFRUNOPTIONS[bufsize]; *************** *** 66,69 **** --- 67,71 ---- void SendClassData(int sd, char *sendbuffer); void CheckAccess(char *users); + void cfrunSyntax(); /*******************************************************************/ *************** *** 122,126 **** ip = ip->next; } ! } while (i > 0 ) --- 124,128 ---- ip = ip->next; } ! } // end forking while while (i > 0 ) *************** *** 149,156 **** FILE *fp; int i; /* Read hosts file */ ! if ((sp=getenv(CFINPUTSVAR)) != NULL) { strcpy(filename,sp); --- 151,247 ---- FILE *fp; int i; + int optgroup = 0; + /* Separate command args into options and classes */ + bzero(CFRUNOPTIONS,bufsize); + + for (i = 1; i < argc; i++) + { + if (optgroup == 0) + { + if (strncmp(argv[i],"-h",2) == 0) + { + cfrunSyntax(); + } + else if (strncmp(argv[i],"-f",2) == 0) + { + i++; + if ((i >= argc) || (strncmp(argv[i],"-",1) == 0)) { + printf("Error: No filename listed after -f option.\n"); + cfrunSyntax(); + exit(0); + } + bzero(VCFRUNHOSTS,bufsize); + strcat(VCFRUNHOSTS,argv[i]); + Debug("cfrun: cfrun file = %s\n",VCFRUNHOSTS); + } + else if (strncmp(argv[i],"-d",2) == 0) + { + DEBUG = true; + VERBOSE = true; + } + else if (strncmp(argv[i],"-v",2) == 0) + { + VERBOSE=true; + } + else if (strncmp(argv[i],"-S",2) == 0) + { + SILENT = true; + } + else if (strncmp(argv[i],"--",2) == 0) + { + optgroup++; + } + else + { + printf("Error: Unknown option.\n"); + cfrunSyntax(); + exit(0); + } + } + else if (optgroup == 1) + { + if (strncmp(argv[i],"--",2) == 0) + { + optgroup++; + } + else + { + strcat(CFRUNOPTIONS,argv[i]); + strcat(CFRUNOPTIONS," "); + } + } + else + { + AppendItem(&VCFRUNCLASSES,argv[i],""); + } + } + + Debug("CFRUNOPTIONS string: %s\n",CFRUNOPTIONS); + + for (ip = VCFRUNCLASSES; ip != NULL; ip=ip->next) + { + Debug("Class item: %s\n",ip->name); + } + + if (uname(&VSYSNAME) == -1) + { + perror("uname "); + printf("cfrun: uname couldn't get kernel name info!!\n"); + exit(1); + } + + if ((strlen(VDOMAIN) > 0) && !strchr (VSYSNAME.nodename, '.')) + { + sprintf(VFQNAME,"%s.%s",VSYSNAME.nodename,VDOMAIN); + } + else + { + sprintf(VFQNAME,"%s",VSYSNAME.nodename); + } + /* Read hosts file */ ! if ( ((sp=getenv(CFINPUTSVAR)) != NULL) && (!strchr(VCFRUNHOSTS, '/')) ) { strcpy(filename,sp); *************** *** 191,195 **** MAXCHILD = 1; ! Verbose("maxchild = %d\n", MAXCHILD); continue; } --- 282,286 ---- MAXCHILD = 1; ! Verbose("cfrun: maxchild = %d\n", MAXCHILD); continue; } *************** *** 198,201 **** --- 289,293 ---- { sscanf(line,"outputdir = %295[^# \n]", OUTPUTDIR); + Verbose("cfrun: outputdir = %s\n", OUTPUTDIR); if ( opendir(OUTPUTDIR) == NULL) { *************** *** 254,316 **** fclose(fp); - bzero(CFRUNOPTIONS,bufsize); - - /* Separate command args into options and classes */ - - for (i = 1; i < argc; i++) - { - if (*argv[i] == '-') - { - if (strncmp(argv[i],"-d",2) == 0) - { - DEBUG = true; - VERBOSE = true; - } - else if (strncmp(argv[i],"-v",2) == 0) - { - VERBOSE=true; - strcat(CFRUNOPTIONS,argv[i]); - strcat(CFRUNOPTIONS," "); - } - else if (strncmp(argv[i],"-S",2) == 0) - { - SILENT = true; - strcat(CFRUNOPTIONS,argv[i]); - strcat(CFRUNOPTIONS," "); - } - else - { - strcat(CFRUNOPTIONS,argv[i]); - strcat(CFRUNOPTIONS," "); - } - } - else - { - AppendItem(&VCFRUNCLASSES,argv[i],""); - } - } - - Debug("CFRUNOPTIONS string: %s\n",CFRUNOPTIONS); - - for (ip = VCFRUNCLASSES; ip != NULL; ip=ip->next) - { - Debug("Class item: %s\n",ip->name); - } - - if (uname(&VSYSNAME) == -1) - { - perror("uname "); - printf("cfrun: uname couldn't get kernel name info!!\n"); - exit(1); - } - - if ((strlen(VDOMAIN) > 0) && !strchr (VSYSNAME.nodename, '.')) - { - sprintf(VFQNAME,"%s.%s",VSYSNAME.nodename,VDOMAIN); - } - else - { - sprintf(VFQNAME,"%s",VSYSNAME.nodename); - } } --- 346,349 ---- *************** *** 585,588 **** --- 618,641 ---- } + void cfrunSyntax() { + printf("Usage: cfrun [-f cfrun.hosts|-h|-d|-S|-v] [-- OPTIONS [-- CLASSES]]\n"); + printf("-f cfrun.hosts\tcfrun file to read in list of hosts (see below for syntax.)\n"); + printf("-h\t\tGet this help message.\n"); + printf("-d\t\tDebug mode, turns on verbose as well.\n"); + printf("-S\t\tSilent mode.\n"); + printf("-v\t\tVerbose mode.\n"); + printf("-- OPTIONS\tArguments to be passed to host application.\n"); + printf("-- CLASSES\tClasses to be defined for the hosts.\n\n"); + printf("cfrun.hosts file syntax:\n"); + printf("# starts a comment\n"); + printf("domain = [domain]\t# Domain to use for connection(s).\n"); + printf("maxchild = [num]\t# Maximum number of children to spawn during run.\n"); + printf("outputdir = [dir]\t# Directory where to put host output files.\n"); + printf("access = [user]\t\t# User allowed to do cfrun?\n"); + printf("[host]\t\t\t# One host per line list to cycle through.\n"); + printf("\t\t\t# Only the hosts are required for cfrun to operate.\n"); + + exit(0); + } /********************************************************************/