Beispiel #1
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;
	}
}
Beispiel #2
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;
}
Beispiel #3
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[])
{
    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[])
{
	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;
}