int main(int argc, char *argv[]) { int did_explicit_auth = 0; time_t stoptime; char c; int i, srcindex, nstreams; FILE *localfile; struct chirp_stream *stream[argc - 2]; const char *localmode; int remotemode; debug_config(argv[0]); while((c = getopt(argc, argv, "a:b:d:t:vh")) != (char) -1) { switch (c) { case 'a': auth_register_byname(optarg); did_explicit_auth = 1; break; case 'b': buffer_size = atoi(optarg); break; case 'd': debug_flags_set(optarg); break; case 't': timeout = string_time_parse(optarg); break; case 'v': show_version(argv[0]); exit(0); break; case 'h': show_help(argv[0]); exit(0); break; } } if(!did_explicit_auth) auth_register_all(); if((argc - optind) < 4) { show_help(argv[0]); return 1; } if(!strcmp(argv[optind], "split")) { stream_mode = MODE_SPLIT; localmode = "r"; remotemode = CHIRP_STREAM_WRITE; } else if(!strcmp(argv[optind], "copy")) { stream_mode = MODE_COPY; localmode = "r"; remotemode = CHIRP_STREAM_WRITE; } else if(!strcmp(argv[optind], "join")) { stream_mode = MODE_JOIN; localmode = "w"; remotemode = CHIRP_STREAM_READ; } else { fprintf(stderr, "unknown operation: %s\n", argv[0]); show_help(argv[0]); return 1; } char *buffer = malloc(buffer_size); srcindex = optind + 1; nstreams = (argc - optind - 2) / 2; stoptime = time(0) + timeout; localfile = fopen(argv[srcindex], localmode); if(!localfile) { fprintf(stderr, "couldn't open %s: %s\n", argv[srcindex], strerror(errno)); return 1; } char **hostname = malloc(sizeof(*hostname) * nstreams); char **filename = malloc(sizeof(*filename) * nstreams); for(i = 0; i < nstreams; i++) { hostname[i] = argv[srcindex + (2 * i) + 1]; filename[i] = argv[srcindex + (2 * i) + 2]; stream[i] = chirp_stream_open(hostname[i], filename[i], remotemode, stoptime); if(!stream[i]) { fprintf(stderr, "couldn't open %s:%s: %s\n", hostname[i], filename[i], strerror(errno)); return 1; } } if(stream_mode == MODE_SPLIT) { i = 0; while(fgets(buffer, buffer_size, localfile)) { int length = strlen(buffer); int actual = chirp_stream_write(stream[i], buffer, length, stoptime); if(actual != length) { fprintf(stderr, "couldn't write to %s:%s: %s\n", hostname[i], filename[i], strerror(errno)); return 1; } i = (i + 1) % nstreams; } } else if(stream_mode == MODE_COPY) { while(fgets(buffer, buffer_size, localfile)) { int length = strlen(buffer); for(i = 0; i < nstreams; i++) { int actual = chirp_stream_write(stream[i], buffer, length, stoptime); if(actual != length) { fprintf(stderr, "couldn't write to %s:%s: %s\n", hostname[i], filename[i], strerror(errno)); return 1; } } } } else { int streams_left = nstreams; while(streams_left > 0) { for(i = 0; i < nstreams; i++) { if(!stream[i]) continue; int length = chirp_stream_readline(stream[i], buffer, buffer_size, stoptime); if(length > 0) { length = strlen(buffer); fprintf(localfile, "%s\n", buffer); } else { streams_left--; } } } } for(i = 0; i < nstreams; i++) { chirp_stream_flush(stream[i], stoptime); chirp_stream_close(stream[i], stoptime); } return 0; }
int main(int argc, char *argv[]) { int did_explicit_auth = 0; int follow_mode = 0; int whole_file_mode = 1; const char *hostname, *source_file, *target_file; time_t stoptime; FILE *file; int c; char *tickets = NULL; debug_config(argv[0]); static struct option long_options[] = { {"auth", required_argument, 0, 'a'}, {"block-size", required_argument, 0, 'b'}, {"debug", required_argument, 0, 'd'}, {"follow", no_argument, 0, 'f'}, {"tickets", required_argument, 0, 'i'}, {"timeout", required_argument, 0, 't'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; while((c = getopt_long(argc, argv, "a:b:d:fi:t:vh", long_options, NULL)) > -1) { switch (c) { case 'a': auth_register_byname(optarg); did_explicit_auth = 1; break; case 'b': buffer_size = (size_t)strtoul(optarg, NULL, 0); break; case 'd': debug_flags_set(optarg); break; case 'f': follow_mode = 1; break; case 'i': tickets = strdup(optarg); break; case 't': timeout = string_time_parse(optarg); break; case 'v': cctools_version_print(stdout, argv[0]); exit(0); break; case 'h': show_help(argv[0]); exit(0); break; } } cctools_version_debug(D_DEBUG, argv[0]); if(!did_explicit_auth) auth_register_all(); if(tickets) { auth_ticket_load(tickets); free(tickets); } else if(getenv(CHIRP_CLIENT_TICKETS)) { auth_ticket_load(getenv(CHIRP_CLIENT_TICKETS)); } else { auth_ticket_load(NULL); } if((argc - optind) < 3) { show_help(argv[0]); exit(0); } source_file = argv[optind]; hostname = argv[optind + 1]; target_file = argv[optind + 2]; stoptime = time(0) + timeout; if(!strcmp(source_file, "-")) { file = stdin; source_file = "/dev/stdin"; } else { file = fopen(source_file, "r"); if(!file) { fprintf(stderr, "chirp_put: couldn't open %s: %s\n", source_file, strerror(errno)); return 1; } } if(follow_mode) whole_file_mode = 0; if(whole_file_mode) { INT64_T result = chirp_recursive_put(hostname, source_file, target_file, stoptime); if(result < 0) { fprintf(stderr, "chirp_put: couldn't put %s to host %s: %s\n", source_file, hostname, strerror(errno)); return 1; } else { return 0; } } else { struct chirp_stream *stream; char *buffer = xxmalloc(buffer_size); INT64_T ractual, wactual; stream = chirp_stream_open(hostname, target_file, CHIRP_STREAM_WRITE, stoptime); if(!stream) { fprintf(stderr, "chirp_put: couldn't open %s for writing: %s\n", target_file, strerror(errno)); return 1; } while(1) { ractual = full_fread(file, buffer, buffer_size); if(ractual == 0) { if(follow_mode) { debug(D_DEBUG, "waiting for more data..."); sleep(1); continue; } else { break; } } wactual = chirp_stream_write(stream, buffer, (int)ractual, stoptime); if(wactual != ractual) { fprintf(stderr, "chirp_put: couldn't write to %s: %s\n", target_file, strerror(errno)); return 1; } } chirp_stream_close(stream, stoptime); return 0; } }
int main(int argc, char *argv[]) { char c; int did_explicit_auth = 0; char *tickets = NULL; struct fuse_args fa; fa.argc = 0; fa.argv = string_array_new(); fa.allocated = 1; debug_config(argv[0]); while((c = getopt(argc, argv, "a:b:d:Dfhi:m:o:t:v")) != -1) { switch (c) { case 'd': debug_flags_set(optarg); break; case 'D': enable_small_file_optimizations = 0; break; case 'b': chirp_reli_blocksize_set(atoi(optarg)); break; case 'i': tickets = xxstrdup(optarg); break; case 'm': fa.argc += 1; fa.argv = string_array_append(fa.argv, optarg); break; case 'o': debug_config_file(optarg); break; case 'a': auth_register_byname(optarg); did_explicit_auth = 1; break; case 't': chirp_fuse_timeout = string_time_parse(optarg); break; case 'f': run_in_foreground = 1; break; case 'v': cctools_version_print(stdout, argv[0]); return 0; break; case 'h': default: show_help(argv[0]); return 1; break; } } cctools_version_debug(D_DEBUG, argv[0]); if((argc - optind) != 1) { show_help(argv[0]); return 1; } fuse_mountpoint = argv[optind]; if(!did_explicit_auth) auth_register_all(); if(tickets) { auth_ticket_load(tickets); free(tickets); } else if(getenv(CHIRP_CLIENT_TICKETS)) { auth_ticket_load(getenv(CHIRP_CLIENT_TICKETS)); } else { auth_ticket_load(NULL); } file_table = itable_create(0); signal(SIGHUP, exit_handler); signal(SIGINT, exit_handler); signal(SIGTERM, exit_handler); fuse_chan = fuse_mount(fuse_mountpoint, &fa); if(!fuse_chan) { fprintf(stderr, "chirp_fuse: couldn't access %s\n", fuse_mountpoint); return 1; } fuse_instance = fuse_new(fuse_chan, &fa, &chirp_fuse_operations, sizeof(chirp_fuse_operations), 0); if(!fuse_instance) { fuse_unmount(fuse_mountpoint, fuse_chan); fprintf(stderr, "chirp_fuse: couldn't access %s\n", fuse_mountpoint); return 1; } printf("chirp_fuse: mounted chirp on %s\n", fuse_mountpoint); #ifdef CCTOOLS_OPSYS_DARWIN printf("chirp_fuse: to unmount: umount %s\n", fuse_mountpoint); #else printf("chirp_fuse: to unmount: fusermount -u %s\n", fuse_mountpoint); #endif fflush(0); if(!run_in_foreground) daemon(0, 0); fuse_loop(fuse_instance); fuse_unmount(fuse_mountpoint, fuse_chan); fuse_destroy(fuse_instance); free(fa.argv); return 0; }
int main(int argc, char *argv[]) { long fd; int i, j, k; int bwloops; char *fname; char data[8192]; int runtime; struct stat buf; struct timeval start, stop; stoptime = time(0) + 3600; int filesize = 16 * 1024 * 1024; if(argc != 6) { printf("use: %s <host> <file> <loops> <cycles> <bwloops>\n", argv[0]); return -1; } auth_register_all(); host = argv[1]; fname = argv[2]; loops = atoi(argv[3]); cycles = atoi(argv[4]); bwloops = atoi(argv[5]); if(!strcmp(host, "unix")) { do_chirp = 0; } else { do_chirp = 1; } #ifdef SYS_getpid RUN_LOOP("getpid", syscall(SYS_getpid)); #else RUN_LOOP("getpid", getpid()); #endif fd = do_open(fname, O_WRONLY | O_CREAT | O_TRUNC | do_sync, 0777); if(fd < 0 || fd == 0) { perror(fname); return -1; } RUN_LOOP("write1", do_pwrite(fd, data, 1, 0)); RUN_LOOP("write8", do_pwrite(fd, data, 8192, 0)); do_close(fd); fd = do_open(fname, O_RDONLY | do_sync, 0777); if(fd < 0) { perror(fname); return -1; } RUN_LOOP("read1", do_pread(fd, data, 1, 0)); RUN_LOOP("read8", do_pread(fd, data, 8192, 0)); do_close(fd); RUN_LOOP("stat", do_stat(fname, &buf)); RUN_LOOP("open", fd = do_open(fname, O_RDONLY | do_sync, 0777); do_close(fd); );
int main(int argc, char *argv[]) { int did_explicit_auth = 0; int follow_mode = 0; time_t stoptime; signed char c; int setAindex, setBindex; // funcindex; FILE *setA = NULL; FILE *setB = NULL; char setApath[CHIRP_PATH_MAX]; char setBpath[CHIRP_PATH_MAX]; char *LIST_FILE_NAME = "set.list"; char setAfilename[CHIRP_PATH_MAX]; char setBfilename[CHIRP_PATH_MAX]; int len = CHIRP_PATH_MAX; struct chirp_matrix *mat = NULL; int mathost, matpath; double *resbuff = NULL; int numels; int cntr; // Variables defined by Li int i; // for multiprocess calculation int numOfMovingElements, numOfStableElements; //int setACount, setBCount; int setAPos, setBPos; long setAStartPos; //long setBStartPos; int x1, y1, x2, y2, topLeftX, topLeftY; // [x1,y1]-start position, [x2,y2]-end position, the sub matrix we compute in a round int x_rel, y_rel; double threshold; double threshold_min = 0; double threshold_max = 1; double threshold_interval = 0.2; int count_thresholds; int count_genuine = 0; int count_impostar = 0; //int count_fa = 0; //int count_fr = 0; double (*roc_data)[3]; int subject_equal; // ~Variables defined by Li int w, h, e, n; w = 10; h = 10; e = 8; n = 1; x1 = y1 = x2 = y2 = -1; topLeftX = topLeftY = 0; debug_config(argv[0]); while((c = getopt(argc, argv, "a:b:d:ft:vhw:i:e:n:x:y:p:q:r:s:X:Y:c:")) > -1) { switch (c) { case 'a': auth_register_byname(optarg); did_explicit_auth = 1; break; case 'b': buffer_size = atoi(optarg); break; case 'd': debug_flags_set(optarg); break; case 'f': follow_mode = 1; break; case 't': timeout = string_time_parse(optarg); break; case 'w': w = atoi(optarg); break; case 'i': h = atoi(optarg); break; case 'e': e = atoi(optarg); break; case 'n': n = atoi(optarg); break; case 'v': cctools_version_print(stdout, argv[0]); exit(0); break; case 'h': show_help(argv[0]); exit(0); break; case 'x': numOfStableElements = atoi(optarg); break; case 'y': numOfMovingElements = atoi(optarg); break; case 'p': x1 = atoi(optarg); break; case 'q': y1 = atoi(optarg); break; case 'r': x2 = atoi(optarg); break; case 's': y2 = atoi(optarg); break; case 'X': topLeftX = atoi(optarg); break; case 'Y': topLeftY = atoi(optarg); break; case 'c': //numOfCores = atoi(optarg); break; } } cctools_version_debug(D_DEBUG, argv[0]); if(!did_explicit_auth) auth_register_all(); if((argc - optind) < 4) { fprintf(stderr, "after all options, you must have: setA setB function mathost matpath\n"); exit(0); } stoptime = time(0) + timeout; setAindex = optind; setBindex = optind + 1; mathost = optind + 2; matpath = optind + 3; // Set threshhold min, max and interval threshold_min = 0; threshold_max = 1; threshold_interval = 0.01; // Initialize result array - roc_data count_thresholds = (threshold_max - threshold_min) / threshold_interval + 1; roc_data = malloc(count_thresholds * 3 * sizeof(double)); if(!roc_data) { fprintf(stderr, "Cannot initialize result buffer!\n"); exit(1); } for(i = 0, threshold = threshold_min; i < count_thresholds; i++, threshold += threshold_interval) { roc_data[i][0] = threshold; } // Load matrix to be verified printf("X1,X2,Y1,Y2: %i,%i,%i,%i\n", x1, x2, y1, y2); mat = chirp_matrix_open(argv[mathost], argv[matpath], stoptime); if(mat == NULL) { fprintf(stderr, "No such matrix. Fail.\n"); exit(1); } printf("Start loading matrix ... \n"); printf("Width, height: %d, %d\n\n", chirp_matrix_width(mat), chirp_matrix_height(mat)); numels = (x2 - x1 + 1) * (y2 - y1 + 1); resbuff = (double *) malloc(numels * sizeof(double)); double *pilot_resbuff; pilot_resbuff = resbuff; // TODO get_range function can get at most 10*10 matrix a time (actually it can get more) /** for(j=0; j<y2-y1+1; j++) { for(i=0; i<x2-x1+1; i++) { int matrtn = chirp_matrix_get_range( mat, x1+i, y1+j, 1, 1, pilot_resbuff, stoptime); //(x2-x1+1), (y2-y1+1), resbuff, stoptime ); printf("%.2f\t", (*pilot_resbuff)); if(matrtn == -1) printf("return mat error @ [%d, %d]!!\n", x1+i, y1+j); pilot_resbuff++; } printf("\n"); }*/ int matrtn = chirp_matrix_get_range(mat, x1, y1, x2 - x1 + 1, y2 - y1 + 1, resbuff, stoptime); //(x2-x1+1), (y2-y1+1), resbuff, stoptime ); if(matrtn == -1) { fprintf(stderr, "return mat error @ [%d, %d], width: %d; height: %d!\n", x1, y1, x2 - x1 + 1, y2 - y1 + 1); exit(1); } printf("*******end of loading matrix********\n\n"); // Get local path for data sets directories if(get_local_path(setApath, argv[setAindex], stoptime) != 0 || get_local_path(setBpath, argv[setBindex], stoptime) != 0) { fprintf(stderr, "Paths to data sets are invalid!\n"); exit(1); } // setA and setB each contains a list of file names that points to the data files char setAlistfile[CHIRP_PATH_MAX]; char setBlistfile[CHIRP_PATH_MAX]; strcpy(setAlistfile, setApath); strcat(setAlistfile, LIST_FILE_NAME); if((setA = fopen(setAlistfile, "r")) == NULL) { fprintf(stderr, "Cannot open data set A list file - %s!\n", setAlistfile); exit(1); } strcpy(setBlistfile, setBpath); strcat(setBlistfile, LIST_FILE_NAME); if((setB = fopen(setBlistfile, "r")) == NULL) { fprintf(stderr, "Cannot open data set B list file - %s!\n", setBlistfile); exit(1); } // Initialize position parameters and allocate memory for storing results of a block (sub matrix) x_rel = y_rel = 0; // relative to the sub-matrix we are actually working on // Go forward until line x1 in Set A list file for(i = 0; i < x1 && !feof(setA); i++) { fgets(setAfilename, len, setA); } if(i < x1) { fprintf(stderr, "Set A has less then x1 elements!\n"); exit(1); } setAStartPos = ftell(setA); // Go forward until line y1 in Set B list file for(i = 0; i < y1 && !feof(setB); i++) { fgets(setBfilename, len, setB); } if(i < y1) { fprintf(stderr, "Set B has less then x1 elements!\n"); exit(1); } //setBStartPos = ftell(setB); debug(D_CHIRP, "Matrix data:\n"); // start loop fgets(setBfilename, len, setB); if(setBfilename != NULL) { size_t last = strlen(setBfilename) - 1; if(setBfilename[last] == '\n') setBfilename[last] = '\0'; } for(setBPos = y1; !feof(setB) && setBPos <= y2; setBPos++) { // Set B - column of matrix // Go directly to line y1 in Set B list file fseek(setA, setAStartPos, SEEK_SET); fgets(setAfilename, len, setA); if(setAfilename != NULL) { size_t last = strlen(setAfilename) - 1; if(setAfilename[last] == '\n') setAfilename[last] = '\0'; } setAPos = x1; for(setAPos = x1; !feof(setA) && setAPos <= x2; setAPos++) { // Set A- row of matrix // Threshhold comparison cntr = ((setBPos - y1) * (x2 - x1 + 1)) + (setAPos - x1); subject_equal = isSubjectIdEqual(setAfilename, setBfilename); if(subject_equal == 1) { // A genuine match for(threshold = threshold_max, i = count_thresholds - 1; 1 - resbuff[cntr] < threshold; threshold -= threshold_interval, i--) { // False reject roc_data[i][1] += 1; } count_genuine++; } else if(subject_equal == 0) { // A impostar match for(threshold = threshold_min, i = 0; 1 - resbuff[cntr] >= threshold; threshold += threshold_interval, i++) { // False accept roc_data[i][2] += 1; } count_impostar++; } else { fprintf(stderr, "Cannot resolve filename in either %s or %s!\n", setAfilename, setBfilename); exit(1); } debug(D_CHIRP, "%.2f\t", resbuff[cntr]); fgets(setAfilename, len, setA); if(setAfilename != NULL) { size_t last = strlen(setAfilename) - 1; if(setAfilename[last] == '\n') setAfilename[last] = '\0'; } } debug(D_CHIRP, "\n"); fgets(setBfilename, len, setB); if(setBfilename != NULL) { size_t last = strlen(setBfilename) - 1; if(setBfilename[last] == '\n') setBfilename[last] = '\0'; } } printf("\n**********************************************************************\n"); // Printf roc_data debug(D_CHIRP, "ROC raw data format: Threshold | False reject count | False accept count\n"); for(i = 0; i < count_thresholds; i++) { debug(D_CHIRP, "%.2f\t%.2f\t%.2f;\t", roc_data[i][0], roc_data[i][1], roc_data[i][2]); } debug(D_CHIRP, "\n"); // Transform roc_data to ROC curve data for(i = 0; i < count_thresholds; i++) { roc_data[i][1] = 1 - (roc_data[i][1] / count_genuine); // 1 - FRR roc_data[i][2] = roc_data[i][2] / count_impostar; // FAR } // Printf roc_data debug(D_CHIRP, "ROC curve data format: Threshold | 1 - False reject rate | False accept rate\n"); for(i = 0; i < count_thresholds; i++) { debug(D_CHIRP, "%.2f\t%.2f\t%.2f;\t", roc_data[i][0], roc_data[i][1], roc_data[i][2]); } debug(D_CHIRP, "\n"); // Write to dat file for gnuplot's use FILE *roc_data_fp; //char roc_line[20]; roc_data_fp = fopen("roc.dat", "w"); for(i = 0; i < count_thresholds; i++) { fprintf(roc_data_fp, "%.2f\t%.2f\n", roc_data[i][1], roc_data[i][2]); // 1 - FRR, FAR } fclose(roc_data_fp); free(resbuff); debug(D_CHIRP, "%d comparisons in the matrix are tested! Genuine matches: %d\t Impostar matches: %d\n\n", cntr + 1, count_genuine, count_impostar); printf("\nROC curve data generation completed successfully!\n%d comparisons in the matrix are tested!\n", cntr + 1); return 0; }
int main(int argc, char *argv[]) { int did_explicit_auth = 0; int stdout_mode = 0; const char *hostname, *source_file, *target_file; time_t stoptime; FILE *file; INT64_T result; char c; char *tickets = NULL; debug_config(argv[0]); while((c = getopt(argc, argv, "a:d:i:t:vh")) != (char) -1) { switch (c) { case 'a': auth_register_byname(optarg); did_explicit_auth = 1; break; case 'd': debug_flags_set(optarg); break; case 'i': tickets = strdup(optarg); break; case 't': timeout = string_time_parse(optarg); break; case 'v': show_version(argv[0]); exit(0); break; case 'h': show_help(argv[0]); exit(0); break; } } if(!did_explicit_auth) auth_register_all(); if(tickets) { auth_ticket_load(tickets); free(tickets); } else if(getenv(CHIRP_CLIENT_TICKETS)) { auth_ticket_load(getenv(CHIRP_CLIENT_TICKETS)); } else { auth_ticket_load(NULL); } if((argc - optind) < 3) { show_help(argv[0]); exit(0); } hostname = argv[optind]; source_file = argv[optind + 1]; target_file = argv[optind + 2]; stoptime = time(0) + timeout; if(!strcmp(target_file, "-")) { stdout_mode = 1; file = stdout; } if(stdout_mode) { result = chirp_reli_getfile(hostname, source_file, file, stoptime); } else { result = chirp_recursive_get(hostname, source_file, target_file, stoptime); } if(result < 0) { fprintf(stderr, "couldn't get %s:%s: %s\n", hostname, source_file, strerror(errno)); return 1; } else { return 0; } }
int main(int argc, char *argv[]) { char *temp; int did_explicit_auth = 0; char *tickets = NULL; char prompt[CHIRP_LINE_MAX]; char line[CHIRP_LINE_MAX]; char **user_argv = 0; int user_argc; signed char c; int result = 0; debug_config(argv[0]); static struct option long_options[] = { {"auth", required_argument, 0, 'a'}, {"debug", required_argument, 0, 'd'}, {"tickets", required_argument, 0, 'i'}, {"verbose", no_argument, 0, 'l'}, {"timeout", required_argument, 0, 't'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; while((c = getopt_long(argc, argv, "+a:d:hi:lt:v", long_options, NULL)) > -1) { switch (c) { case 'a': auth_register_byname(optarg); did_explicit_auth = 1; break; case 'd': debug_flags_set(optarg); break; case 'h': show_help(argv[0]); exit(0); break; case 'i': tickets = strdup(optarg); break; case 'l': long_information = 1; break; case 't': timeout = string_time_parse(optarg); break; case 'v': cctools_version_print(stdout, argv[0]); exit(0); break; } } cctools_version_debug(D_DEBUG, argv[0]); if(!did_explicit_auth) auth_register_all(); if(tickets) { auth_ticket_load(tickets); free(tickets); } else if(getenv(CHIRP_CLIENT_TICKETS)) { auth_ticket_load(getenv(CHIRP_CLIENT_TICKETS)); } else { auth_ticket_load(NULL); } getcwd(current_local_dir, CHIRP_PATH_MAX); /* interactive mode if input is a TTY but we are not simply executing a * command from argv */ interactive_mode = isatty(0) && !((argc - optind) > 1); if(optind < argc) { stoptime = time(0) + timeout; if(do_open(1, &argv[optind - 1])) { fprintf(stderr, "couldn't open %s: %s\n", argv[optind], strerror(errno)); return 1; } } if((argc - optind) > 1) { return !process_command(argc - optind - 1, &argv[optind + 1]); } while(1) { if(interactive_mode) { sprintf(prompt, " chirp:%s:%s> ", current_host, current_remote_dir); } else { prompt[0] = 0; } #ifdef HAS_LIBREADLINE temp = readline(prompt); if(!temp) break; strcpy(line, temp); free(temp); #else printf("%s", prompt); fflush(stdout); if(!fgets(line, CHIRP_LINE_MAX, stdin)) break; #endif if(!line[0]) continue; if(!interactive_mode && (temp = strchr(line, '#'))) { /* comment? */ for(temp--; temp > line && isspace((int) *temp); temp--); /* preceding space? */ if(temp <= line) continue; /* else not comment */ } #ifdef HAS_LIBREADLINE add_history(line); #endif { char *start = line, *last = strlen(line) + line; while(*start != '\0') { /* process compound commands */ char *end = strchr(start, ';'); while(end != NULL && end != start && *(end - 1) == '\\') end = strchr(end + 1, ';'); if(end == NULL) end = start + strlen(start); *end = '\0'; if(user_argv) free(user_argv); string_split(start, &user_argc, &user_argv); if(user_argc == 0) { start++; continue; } result = process_command(user_argc, user_argv); start = end == last ? last : end + 1; } } if(!interactive_mode && !result) break; } if(result) { return 0; } else { return 1; } }
int main(int argc, char** argv) { signed char cl; int did_explicit_auth = 0; int download,rm_local,rm_remote,rm_mat,file_provided; int rm_remote_error = 0; char matrix_target[CHIRP_PATH_MAX]; char finalize_file[CHIRP_PATH_MAX]; time_t stoptime = time(0)+3600; download=rm_local=rm_remote=rm_mat=file_provided=0; while((cl=getopt(argc,argv,"+a:d:hD:LRMF:")) > -1) { switch(cl) { case 'a': auth_register_byname(optarg); did_explicit_auth = 1; break; case 'd': debug_flags_set(optarg); break; case 'h': printUsage(argv[0]); exit(0); break; case 'D': // download matrix data to local disk download=1; strcpy(matrix_target,optarg); break; case 'L': // force LOCAL state removal rm_local=1; break; case 'R': // force REMOTE state removal (chirp_distribute -X) rm_remote=1; break; case 'M': // force REMOTE MATRIX state removal rm_mat=1; break; case 'F': file_provided=1; strcpy(finalize_file,optarg); break; } } if(!file_provided) { fprintf(stderr,"Please provide argument -F [finalize file]\n"); printUsage(argv[0]); exit(1); } if(!did_explicit_auth) auth_register_all(); // if an authentication mechanism wasn't chosen, default register all. debug_config(argv[0]); // indicate what string to use as the executable name when printing debugging information // first, parse finalize file to get information. char* cmd; char* wID; char* local_dir; char* mat_host; char* mat_path; char* remote_dir; char* node_list; char* hn; char* fun_path; int strlentmp; FILE* fp = fopen(finalize_file,"r"); if(!fp) { fprintf(stderr,"Finalize file not readable.\n"); exit(1); } // 0th item is workload id if(fscanf(fp, " wID=%i ",&strlentmp) == 1) { wID = malloc((strlentmp+1)*sizeof(char)); if(!wID) { fprintf(stderr,"Could not allocate %i bytes for workload ID\n",strlentmp); exit(1); } if(fscanf(fp, " %s ", wID) != 1) { fprintf(stderr,"Could not read in workload ID\n"); exit(2); } } // first item is local prefix -- remove everything. if(fscanf(fp, " local_dir=%i ",&strlentmp) == 1) { local_dir = (char*) malloc((strlentmp+1)*sizeof(char)); if(!local_dir) { fprintf(stderr,"Could not allocate %i bytes for local directory\n",strlentmp); exit(1); } if(fscanf(fp," %s ", local_dir) != 1) { fprintf(stderr,"Could not read in local directory\n"); exit(2); } } // second item is matrix host -\ remove // third item is matrix path -/ matrix if(fscanf(fp, " mat_host=%i ",&strlentmp) == 1) { mat_host = (char *) malloc((strlentmp+1)*sizeof(char)); if(!mat_host) { fprintf(stderr,"Could not allocate %i bytes for matrix host\n",strlentmp); exit(1); } if(fscanf(fp," %s ", mat_host) != 1) { fprintf(stderr,"Could not read in matrix host\n"); exit(2); } } if(fscanf(fp, " mat_path=%i ",&strlentmp) == 1) { mat_path = (char *) malloc((strlentmp+1)*sizeof(char)); if(!mat_path) { fprintf(stderr,"Could not allocate %i bytes for matrix path\n",strlentmp); exit(1); } if(fscanf(fp," %s ", mat_path) != 1) { fprintf(stderr,"Could not read in matrix path\n"); exit(2); } } // 4th item is chirp_dirname if(fscanf(fp, " remote_dir=%i ",&strlentmp) == 1) { remote_dir = (char *) malloc((strlentmp+1)*sizeof(char)); if(!remote_dir) { fprintf(stderr,"Could not allocate %i bytes for remote path\n",strlentmp); exit(1); } if(fscanf(fp," %s ", remote_dir) != 1) { fprintf(stderr,"Could not read in remote path\n"); exit(2); } } if(rm_remote==1) { fprintf(stderr,"Asked to remove remote state, but there is no remote state specified.\n"); rm_remote_error = 1; } // 7th item is full goodstring if(fscanf(fp, " node_list=%i ",&strlentmp) == 1) { node_list = (char *) malloc((strlentmp+1)*sizeof(char)); if(!node_list) { fprintf(stderr,"Could not allocate %i bytes for remote hosts\n",strlentmp); exit(1); } if(fread(node_list,1,strlentmp,fp) != strlentmp) { fprintf(stderr,"Could not read in remote hosts\n"); exit(2); } } if(rm_remote==1 && rm_remote_error == 0) { fprintf(stderr,"Asked to remove remote state, but there is no remote state specified.\n"); rm_remote_error = 1; } // 9th item is hostname if(fscanf(fp, " host=%i ",&strlentmp) == 1) { hn = malloc((strlentmp+1)*sizeof(char)); if(!hn) { fprintf(stderr,"Could not allocate %i bytes for hostname\n",strlentmp); exit(1); } if(fscanf(fp, " %s ", hn) != 1) { fprintf(stderr,"Could not read in hostname\n"); exit(2); } } if(rm_remote==1 && rm_remote_error == 0) { fprintf(stderr,"Asked to remove remote state, but there is no remote state specified.\n"); rm_remote_error = 1; } // 10th item is full function directory -- remove tarball, exception list if(fscanf(fp, " fun_path=%i ",&strlentmp) == 1) { fun_path = (char *) malloc((strlentmp+1)*sizeof(char)); if(!fun_path) { fprintf(stderr,"Could not allocate %i bytes for function directory\n",strlentmp); exit(1); } if(fscanf(fp," %s ", fun_path) != 1) { fprintf(stderr,"Could not read in function directory\n"); exit(2); } cmd = (char *) malloc((strlen(fun_path)+strlen("rm -f ")+strlen(wID)+strlen(".func.tar")+12)*sizeof(char)); if(!cmd) { fprintf(stderr,"Could not allocate memory for command\n"); exit(1); } sprintf(cmd,"rm -f %s/%s.func.tar",fun_path,wID); if(system(cmd)) { fprintf(stderr,"Could not remove %s/%s.func.tar\n",fun_path,wID); exit(1);} sprintf(cmd,"rm -f %s/exclude.list",fun_path); if(system(cmd)) { fprintf(stderr,"Could not remove %s/exclude.list\n",fun_path); exit(1);} free(cmd); cmd=NULL; } else { // internal function fun_path = NULL; } // end parsing finalize file // next, download if desired. if(download) { fprintf(stderr,"Download Matrix Mode\n"); FILE* mt = fopen(matrix_target, "w"); struct chirp_matrix* m = chirp_matrix_open( mat_host, mat_path, stoptime); if(m) { int w = chirp_matrix_width( m ); int h = chirp_matrix_height( m ); //int e = chirp_matrix_element_size( m ); double* buf = malloc(w*sizeof(double)); int x,y; for(y=0; y < h; y++) { chirp_matrix_get_row( m , y, buf, stoptime ); for(x=0; x<w; x++) { fprintf(mt,"%i %i %.2lf\n",y,x,buf[x]); } } } else { printf("Could not open matrix %s %s\n",mat_host,mat_path); return 1; } } // next, delete remote state if desired. if(rm_remote && !rm_remote_error) { fprintf(stderr,"Remove Remote State Mode\n"); cmd = (char *) malloc(strlen("chirp_distribute -a hostname -X ")+10+(2*strlen(hn))+1+strlen(remote_dir)+1+strlen(node_list)+1); if(cmd == NULL) { fprintf(stderr,"Allocating distribute command string memory failed!\n"); return 1; } sprintf(cmd,"chirp_distribute -a hostname -X %s %s %s",hn,remote_dir,node_list); debug(D_CHIRP,"%s\n",cmd); system(cmd); sprintf(cmd,"chirp_distribute -a hostname -X %s %s %s",hn,remote_dir,hn); debug(D_CHIRP,"%s\n",cmd); system(cmd); free(cmd); cmd=NULL; } // next, delete matrix if desired. if(rm_mat) { fprintf(stderr,"Remove Matrix State Mode\n"); chirp_matrix_delete( mat_host, mat_path, time(0)+600 ); } // next, delete local if desired. if(rm_local) { fprintf(stderr,"Remove Local State Mode\n"); cmd = (char *) malloc(strlen("rm -rf ")+1+strlen(local_dir)+1); if(cmd == NULL) { fprintf(stderr,"Allocating distribute command string memory failed!\n"); return 1; } sprintf(cmd,"rm -rf %s",local_dir); system(cmd); free(cmd); cmd=NULL; } return 0; }
int main(int argc, char *argv[]) { int did_explicit_auth = 0; time_t stoptime; signed char c; int i, srcindex, nstreams; FILE *localfile; struct chirp_stream *stream[argc - 2]; const char *localmode; int remotemode; char *tickets = NULL; debug_config(argv[0]); static struct option long_options[] = { {"auth", required_argument, 0, 'a'}, {"block-size", required_argument, 0, 'b'}, {"debug", required_argument, 0, 'd'}, {"tickets", required_argument, 0, 'i'}, {"timeout", required_argument, 0, 't'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; while((c = getopt_long(argc, argv, "a:b:d:i:t:vh", long_options, NULL)) > -1) { switch (c) { case 'a': auth_register_byname(optarg); did_explicit_auth = 1; break; case 'b': buffer_size = atoi(optarg); break; case 'd': debug_flags_set(optarg); break; case 'i': tickets = strdup(optarg); break; case 't': timeout = string_time_parse(optarg); break; case 'v': cctools_version_print(stdout, argv[0]); exit(0); break; case 'h': show_help(argv[0]); exit(0); break; } } cctools_version_debug(D_DEBUG, argv[0]); if(!did_explicit_auth) auth_register_all(); if(tickets) { auth_ticket_load(tickets); free(tickets); } else if(getenv(CHIRP_CLIENT_TICKETS)) { auth_ticket_load(getenv(CHIRP_CLIENT_TICKETS)); } else { auth_ticket_load(NULL); } if((argc - optind) < 4) { show_help(argv[0]); return 1; } if(!strcmp(argv[optind], "split")) { stream_mode = MODE_SPLIT; localmode = "r"; remotemode = CHIRP_STREAM_WRITE; } else if(!strcmp(argv[optind], "copy")) { stream_mode = MODE_COPY; localmode = "r"; remotemode = CHIRP_STREAM_WRITE; } else if(!strcmp(argv[optind], "join")) { stream_mode = MODE_JOIN; localmode = "w"; remotemode = CHIRP_STREAM_READ; } else { fprintf(stderr, "unknown operation: %s\n", argv[0]); show_help(argv[0]); return 1; } char *buffer = malloc(buffer_size); srcindex = optind + 1; nstreams = (argc - optind - 2) / 2; stoptime = time(0) + timeout; localfile = fopen(argv[srcindex], localmode); if(!localfile) { fprintf(stderr, "couldn't open %s: %s\n", argv[srcindex], strerror(errno)); return 1; } char **hostname = malloc(sizeof(*hostname) * nstreams); char **filename = malloc(sizeof(*filename) * nstreams); for(i = 0; i < nstreams; i++) { hostname[i] = argv[srcindex + (2 * i) + 1]; filename[i] = argv[srcindex + (2 * i) + 2]; stream[i] = chirp_stream_open(hostname[i], filename[i], remotemode, stoptime); if(!stream[i]) { fprintf(stderr, "couldn't open %s:%s: %s\n", hostname[i], filename[i], strerror(errno)); return 1; } } if(stream_mode == MODE_SPLIT) { i = 0; while(fgets(buffer, buffer_size, localfile)) { int length = strlen(buffer); int actual = chirp_stream_write(stream[i], buffer, length, stoptime); if(actual != length) { fprintf(stderr, "couldn't write to %s:%s: %s\n", hostname[i], filename[i], strerror(errno)); return 1; } i = (i + 1) % nstreams; } } else if(stream_mode == MODE_COPY) { while(fgets(buffer, buffer_size, localfile)) { int length = strlen(buffer); for(i = 0; i < nstreams; i++) { int actual = chirp_stream_write(stream[i], buffer, length, stoptime); if(actual != length) { fprintf(stderr, "couldn't write to %s:%s: %s\n", hostname[i], filename[i], strerror(errno)); return 1; } } } } else { int streams_left = nstreams; while(streams_left > 0) { for(i = 0; i < nstreams; i++) { if(!stream[i]) continue; int length = chirp_stream_readline(stream[i], buffer, buffer_size, stoptime); if(length > 0) { length = strlen(buffer); fprintf(localfile, "%s\n", buffer); } else { streams_left--; } } } } for(i = 0; i < nstreams; i++) { chirp_stream_flush(stream[i], stoptime); chirp_stream_close(stream[i], stoptime); } return 0; }