void ccMore(char *fileName, char *hostList, int start, char *lockDir) /* Copy source file to hostList starting at start. Look at * lock files in lock dir to see which one to do next. */ { char **hosts; char *newHost; char *hostBuf; int hostCount; int i; readAllWords(hostList, &hosts, &hostCount, &hostBuf); if (hostCount <= 0) errAbort("%s is empty.", hostList); for (i=start; i<hostCount; ++i) { int lockFd; newHost = hosts[i]; if ((lockFd = makeLock(newHost, lockDir)) >= 0) { char ok = TRUE; if (scpFile(fileName, newHost, fileName) != 0) ok = FALSE; write(lockFd, &ok, 1); close(lockFd); if (ok ) { if (i <= (hostCount+1)/2) /* Don't spawn off on last round. */ sshSelf(hostList, newHost, i+1, fileName, lockDir); } } } }
int main(int argc, char* argv[]) { struct bParamList * paramList = NULL; const char *strPtr; int ii; for (ii=0; ii<TCX_MAX_CLIENTS; ii++) { CLIENT[ii] = NULL; } /* * Set some parameters */ /* add some defaults */ paramList = bParametersAddEntry(paramList, "*", "base.bps", "9600"); paramList = bParametersAddEntry(paramList, "*", "base.dev", "/dev/cur0"); paramList = bParametersAddEntry(paramList, "", "TCXHOST", "localhost"); paramList = bParametersAddEntry(paramList, "", "fork", "yes"); /* add some parameter files */ paramList = bParametersAddFile(paramList, "etc/beeSoft.ini"); /* add some enviroment variables */ paramList = bParametersAddEnv(paramList, "", "TCXHOST"); /* add command line arguements */ paramList = bParametersAddArray(paramList, "", argc, argv); /* here is where we should add non "parameter format" options */ bParametersFillParams(paramList); strPtr = bParametersGetParam(paramList, "robot", "name"); if (!strPtr) { fprintf(stderr, "Robot name not set. Check the value in beeSoft.ini.\n"); exit(1); } else if (!strcmp("none", strPtr)) { fprintf(stderr, "Robot name set to 'none'. Check value in beeSoft.ini.\n"); exit(1); } strPtr = bParametersGetParam(paramList, strPtr, "base.type"); if (!strPtr) { fprintf(stderr, "Base type not set. Check the value in beeSoft.ini.\n"); exit(1); } else if ( strcmp("B14", strPtr) && strcmp("B21", strPtr) && strcmp("Ramona", strPtr) ) { fprintf(stderr, "Arm type set to unrecognized type '%s'. Check the\n" "value in beeSoft.ini.\n", strPtr); exit(1); } /* * */ argv0 = argv[0]; if (makeLock(BASE_SERVER_LOCK)<0) { fprintf(stderr,"%s: Already running base server\n",argv[0]); exit(-1); } if (findArg(argc,argv,"-v")) { VERBOSE = TRUE; fprintf(stderr,"baseServer started in verbose mode\n"); } if (findArg(argc,argv,"-noIrs")) { IRS = FALSE; fprintf(stderr,"baseServer started without IRs\n"); } if (findArg(argc,argv,"-noTactiles")) { TACTILES = FALSE; fprintf(stderr,"baseServer started without Tactiles\n"); } if (findArg(argc,argv,"-noSonars")) { SONARS= FALSE; fprintf(stderr,"baseServer started without Sonars\n"); } if (findArg(argc,argv,"-simulator")) { useSimulator=TRUE; fprintf(stderr,"baseServer connecting to simulator.\n"); } RaiInit(); BaseInit(bRobot.base_dev, bRobot.base_bps); catchInterrupts(); initBaseServerTCX(bRobot.TCXHOST); if (useSimulator==TRUE) { simulatorHandle = tcxConnectModule(TCX_SIMULATOR_MODULE_NAME); } registerWatchdogCallback(watchdogToClient); /* * GRUMBLE - It is going to be a bit ugly to get the sensor * structures initialized without opening /dev/abus. tds */ if (SONARS && !useSimulator) { sonarInit(); registerSonarCallback(sonarToClient); SIM_sonarStop(); /* turn off sonar until we have a client */ } if (IRS && !useSimulator) { irInit(); registerIrCallback(irToClient); SIM_irStop(); /* turn off ir until we have a client */ } if (TACTILES && !useSimulator) { tactileInit(); registerTactileCallback(tactileToClient); tactileStop(); } registerStatusCallback(statusToClient); registerBaseCallback(baseToClient); initBaseServerModules(); if (bRobot.fork) { bDaemonize("baseServer.log"); } rotateLimp(); translateLimp(); RaiStart(); exit(0); }
void ccFirst(char *source, char *dest, char *hostList, char *lockDir) /* Do first instance of this program. Copy file to first host, * make up lock directory, and then poll lock directory to see * if we're done. */ { char *firstHost, *lastHost; char **hosts; char *hostBuf; int hostCount; int firstLock; int childPid; char *thisHost = getenv("HOST"); char ok; long startTime = clock1000(); if (thisHost == NULL) errAbort("HOST environment variable undefined\n"); readAllWords(hostList, &hosts, &hostCount, &hostBuf); if (hostCount <= 0) errAbort("%s is empty.", hostList); if (stringArrayIx(thisHost, hosts, hostCount) < 0) errAbort("Current host (%s) not in host list\n", thisHost); if (mkdir(lockDir, 0777) < 0) errAbort("Couldn't make lock directory %s\n", lockDir); firstHost = thisHost; lastHost = hosts[hostCount-1]; if (sameString(lastHost, thisHost) && hostCount > 1) lastHost = hosts[hostCount-2]; firstLock = makeLock(firstHost, lockDir); if (firstLock < 0) errAbort("Couldn't make lock file %s/%s\n", lockDir, firstHost); if (cpFile(source, dest) != 0) { warn("Couldn't copy %s to %s:%d\n", source, firstHost, dest); close(firstLock); cleanupLocks(lockDir); errAbort("Cleaned up locks in %s, aborting copy.", lockDir); } ok = 1; write(firstLock, &ok, 1); close(firstLock); childPid = fork(); if (childPid == 0) { /* Have child process keep copying. */ ccMore(dest, hostList, 0, lockDir); } else { int sleepIx = 0; int sleepTime = 10; int lastStart = 0, lastErr = 0, lastEnd = 0; /* Have parent process wait until last file done. */ for (sleepIx = 0; ; ++sleepIx) { int lockFd; int i; int startCount = 0; int endCount = 0; int errCount = 0; int toGo = 0; int procCount = 0; int lastProcCount = 0; int finCount; boolean reportErr; for (i=0; i<hostCount; ++i) { char *ln = lockName(lockDir, hosts[i]); lockFd = open(ln, O_RDONLY); if (lockFd < 0) ++toGo; else { char ok; if (read(lockFd, &ok, 1) < 1) ++startCount; else { if (ok) ++endCount; else ++errCount; } close(lockFd); } } finCount = endCount + errCount; // if (lastStart != startCount || lastEnd != endCount || lastErr != errCount) { printf(" copies in progress %d finished %d errors %d total %d\n", startCount, endCount, errCount, hostCount); lastStart = startCount; lastEnd = endCount; lastErr = errCount; } if (finCount >= hostCount) { if (errCount > 0) { fprintf(stderr, "Errors copying to hosts:"); for (i=0; i<hostCount; ++i) { char *ln = lockName(lockDir, hosts[i]); lockFd = open(ln, O_RDONLY); if (lockFd < 0) { fprintf(stderr, " ??%s??", hosts[i]); } else { char ok; if (read(lockFd, &ok, 1) < 1) { fprintf(stderr, " ?%s?", hosts[i]); ++startCount; } else { if (!ok) { fprintf(stderr, " %s", hosts[i]); ++errCount; } } close(lockFd); } } fprintf(stderr, "\n"); } cleanupLocks(lockDir); break; } sleep(sleepTime); } } }