示例#1
0
/*
 * Quick skeleton to map up a audio/video/input
 * source to an arcan frameserver along with some helpers.
 */
int afsrv_avfeed(struct arcan_shmif_cont* con, struct arg_arr* args)
{
	if (!con){
		dump_help();
		return EXIT_FAILURE;
	}
	struct arcan_shmif_cont shms = *con;

	if (!arcan_shmif_resize(&shms, 320, 200)){
		LOG("arcan_frameserver(decode) shmpage setup, resize failed\n");
		return EXIT_FAILURE;
	}

	update_frame(&shms, RGBA(0xff, 0xff, 0xff, 0xff));
	arcan_event ev;

	while(1)
		while(arcan_shmif_wait(&shms, &ev)){
			if (ev.category == EVENT_TARGET){
			if (ev.tgt.kind == TARGET_COMMAND_EXIT){
				fprintf(stdout, "parent requested termination, leaving.\n");
				return EXIT_SUCCESS;
			}
			else {
				static int red;
				update_frame(&shms, RGBA(red++, 0x00, 0x00, 0xff));
			}
			}
		}

	return EXIT_FAILURE;
}
示例#2
0
static int
ifuse_process_opt(void *data, const char *arg, int key,
    unused struct fuse_args *args)
{
	struct fuse_core_opt *opt = data;
	struct stat st;
	int res;

	switch (key) {
		case KEY_DEBUG:
			return (0);
		case KEY_HELP:
		case KEY_HELP_WITHOUT_HEADER:
			dump_help();
			return (0);
		case KEY_VERSION:
			dump_version();
			return (1);
		case FUSE_OPT_KEY_NONOPT:
			if (opt->mp == NULL) {
				opt->mp = realpath(arg, opt->mp);
				if (opt->mp == NULL) {
					fprintf(stderr, "fuse: realpath: "
					    "%s : %s\n", arg, strerror(errno));
					return (-1);
				}

				res = stat(opt->mp, &st);
				if (res == -1) {
					fprintf(stderr, "fuse: bad mount point "
					    "%s : %s\n", arg, strerror(errno));
					return (-1);
				}

				if (!S_ISDIR(st.st_mode)) {
					fprintf(stderr, "fuse: bad mount point "
					    "%s : %s\n", arg,
					    strerror(ENOTDIR));
					return (-1);
				}
			} else {
				fprintf(stderr, "fuse: invalid argument %s\n",
				    arg);
				return (-1);
			}
			break;
		default:
			fprintf(stderr, "fuse: unknown option %s\n", arg);
			return (-1);
	}
	return (0);
}
示例#3
0
static int xemucfg_parse_commandline ( int argc, char **argv, const char *only_this )
{
	argc--;
	argv++;
	while (argc) {
		struct xemutools_config_st *o;
		if (*argv[0] != '/' && *argv[0] != '-')
			OPT_ERROR_CMDLINE("Invalid option '%s', must start with '-'", *argv);
		if (!strcasecmp(*argv + 1, "h") || !strcasecmp(*argv + 1, "help") || !strcasecmp(*argv + 1, "-help") || !strcasecmp(*argv + 1, "?")) {
			if (!only_this || (only_this && !strcasecmp(only_this, "help"))) {
				dump_help();
				return 1;
			}
			argc--;
			argv++;
			continue;
		}
		o = search_option(*argv + 1);
		if (!o)
			OPT_ERROR_CMDLINE("Unknown option '%s'", *argv);
		argc--;
		argv++;
		if (o->type == OPT_NO) {
			if (only_this && strcasecmp(only_this, o->name))
				continue;
			o->value = (void*)1;
		} else {
			const char *s;
			if (!argc)
				OPT_ERROR_CMDLINE("Option '%s' requires a parameter, but end of command line detected.", argv[-1]);
			if (only_this && strcasecmp(only_this, o->name))
				goto do_not;
			switch (o->type) {
				case OPT_STR:
					if (o->value)
						free(o->value);
					if (check_string_size(*argv))
						OPT_ERROR_CMDLINE("Option '%s' has too long value.", argv[1]);
					o->value = xemu_strdup(*argv);
					break;
				case OPT_BOOL:
					s = set_boolean_value(*argv, &o->value);
					if (s)
						OPT_ERROR_CMDLINE("Option '%s' %s, but '%s' is detected.", argv[-1], s, *argv);
					break;
				case OPT_NUM:
					o->value = (void*)(intptr_t)atoi(*argv);
					break;
				case OPT_PROC:
					s = (*(xemucfg_parser_callback_func_t)(o->value))(o, argv[-1] + 1, *argv);
					if (s)
						OPT_ERROR_CMDLINE("Option's '%s' parameter '%s' is invalid: %s", argv[-1], *argv, s);
					break;
				case OPT_NO:
					break;	// make GCC happy to handle all cases ...
			}
		do_not:
			argc--;
			argv++;
		}
	}
	return 0;
}
示例#4
0
int
main(int argc, char *argv[]) {
    struct sigaction sa;
    char c;
    int option_index = 0;
    
    // Program name
    program_name = strrchr(argv[0], '/');
    if (program_name)
        program_name ++;
    else
        program_name = argv[0];
        
    // Parse command line options
    do {
        c = getopt_long(argc, argv, short_options, long_options, &option_index);

        switch (c) {

        case -1:
            break;
            
        case 'r':
            capture_file = fopen(optarg, "r");
            if (!capture_file) {
                LOGGER(ERROR, "Cannot open file '%s': %s\n", optarg,
                        strerror(errno));
                return EXIT_FAILURE;
                
            }
            break;
            
        case 'l':
            specified_addresses = 1;
            if (parse_addresses(optarg)) {
                LOGGER(ERROR, "Error parsing local addresses\n");
                return EXIT_FAILURE;
                
            }
            
            break;
            
        case 'p':
            port = strdup(optarg);
            break;
            
        case 'f':
            if (!check_format(optarg)) {
                LOGGER(ERROR, "Bad format provided: `%s'\n", optarg);
                return EXIT_FAILURE;
            }
            
            global_options.format = optarg;
            
            break;
            
        case 't':
            global_options.interval = strtoul(optarg, NULL, 10);
            if (interval <= 0 || interval >= MAX_OUTPUT_INTERVAL) {
                LOGGER(ERROR, "Bad interval provided\n");
                return EXIT_FAILURE;
            }
            
            break;
            
        case 'n':
            global_options.iterations = strtol(optarg, NULL, 10);
            if (interval < 0) {
                LOGGER(ERROR, "Bad iterations provided\n");
                return EXIT_FAILURE;
            }
            
            break;
            
        case 'T':
            global_options.threshold = strtol(optarg, NULL, 10) * 1000;
            if (global_options.threshold < 0) {
                LOGGER(ERROR, "Bad threshold provided\n");
                return EXIT_FAILURE;
            }
            
            break;

        case 'd':
            global_options.server = strdup(optarg);
            
            break;
        case 'i':
	        global_options.interface = strdup(optarg);

            break;


        case 'c':
            global_options.is_client = 1;
            break;

        case 's':
            global_options.header = optarg;
            global_options.show_header = 1;
            break;
            
        case 'S':
            global_options.show_header = 0;
            break;
            
        case 'h':
            dump_help(stdout);
            return EXIT_SUCCESS;

        case 'V':
            dump_version(stdout);
            return EXIT_SUCCESS;

        default:
            dump_usage(stderr);
            return EXIT_FAILURE;

        }

    }
    while (c != -1);
    
	if(! global_options.interface) {
        global_options.interface = "any";
	}

    if(global_options.is_client) {
        if(!global_options.server) {
            LOGGER(ERROR, "%s -d destination server is required.\n", argv[0]);
            return 0;
        }
    }
	if(global_options.server) {
		global_options.is_client = 1;
	} 
    if(!port) {
    	LOGGER(ERROR, "%s -p port is required.\n", argv[0]);
        return 0;
   	}

    // Set up signals
    sa.sa_handler = terminate;
    sigemptyset(&sa.sa_mask);
    sigaddset(&sa.sa_mask, SIGTERM);
    sigaddset(&sa.sa_mask, SIGINT);
    sa.sa_flags = 0;
    sa.sa_restorer = NULL;
    
    sigaction(SIGTERM, &sa, NULL);
    sigaction(SIGINT, &sa, NULL);
    
    // Get local addresses
    if (!specified_addresses && get_addresses() != 0)
        return EXIT_FAILURE;
    
    // Operations timestamp
    time(&timestamp);
    
    // Stats
    init_stats();
    
    if (capture_file) {
        output_offline_start(&global_options);

        offline_capture(capture_file);
        
        fclose(capture_file);
        
    }
    else {
        // Fire up capturing thread
        pthread_create(&capture_thread_id, NULL, capture, NULL);
        
		if(!global_options.threshold) {
        // Options thread
        	pthread_create(&output_thread_id, NULL, output_thread, &global_options);
        	pthread_kill(output_thread_id, SIGINT);
		}
        
        pthread_join(capture_thread_id, NULL);
        
    }
        
    free_stats();
    free_addresses();
	
	free(global_options.server);
    
    return EXIT_SUCCESS;

}