static int hostapd_cli_reconnect(const char *ifname)
{
	char *next_ctrl_ifname;

	hostapd_cli_close_connection();

	if (!ifname)
		return -1;

	next_ctrl_ifname = os_strdup(ifname);
	os_free(ctrl_ifname);
	ctrl_ifname = next_ctrl_ifname;
	if (!ctrl_ifname)
		return -1;

	ctrl_conn = hostapd_cli_open_connection(ctrl_ifname);
	if (!ctrl_conn)
		return -1;
	if (!interactive && !action_file)
		return 0;
	if (wpa_ctrl_attach(ctrl_conn) == 0) {
		hostapd_cli_attached = 1;
		register_event_handler(ctrl_conn);
		update_stations(ctrl_conn);
	} else {
		printf("Warning: Failed to attach to hostapd.\n");
	}
	return 0;
}
Exemple #2
0
static int hostapd_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc,
				     char *argv[])
{
	if (argc < 1) {
		hostapd_cli_list_interfaces(ctrl);
		return 0;
	}

	hostapd_cli_close_connection();
	os_free(ctrl_ifname);
	ctrl_ifname = os_strdup(argv[0]);
	if (ctrl_ifname == NULL)
		return -1;

	if (hostapd_cli_open_connection(ctrl_ifname)) {
		printf("Connected to interface '%s.\n", ctrl_ifname);
		if (wpa_ctrl_attach(ctrl_conn) == 0) {
			hostapd_cli_attached = 1;
			register_event_handler(ctrl_conn);
		} else {
			printf("Warning: Failed to attach to "
			       "hostapd.\n");
		}
	} else {
		printf("Could not connect to interface '%s' - re-trying\n",
			ctrl_ifname);
	}
	return 0;
}
Exemple #3
0
void init_logic()
{
    srand(time(NULL));
    type = rand()%7;
    next_type = rand()%7;
    int types[2];
    types[0] = type;
    types[1] = next_type;
    register_event_handler("AttemptMoveLeft", logic_AttemptMoveLeft);
    register_event_handler("AttemptMoveRight", logic_AttemptMoveRight);
    register_event_handler("AttemptMoveDown", logic_AttemptMoveDown);
    register_event_handler("BlockDrop", logic_BlockDrop);
    register_event_handler("AttemptBlockRotate", logic_AttemptBlockRotate);
    trigger_event("LogicReady", (void*)types);
    trigger_event("NewScore", 0);
    trigger_event("NewLevel", 1);
}
AegisubVersionCheckerThread::AegisubVersionCheckerThread(bool interactive)
: wxThread(wxTHREAD_DETACHED)
, interactive(interactive)
{
	register_event_handler();

#ifndef __APPLE__
	if (!wxSocketBase::IsInitialized())
		wxSocketBase::Initialize();
#endif

	Create();
	Run();
}
Exemple #5
0
int rbac_adm_perm_init( void )
{ struct event_handler_s *eh;
    struct event_names_s *event;

    if( (eh=malloc(6*sizeof(struct event_handler_s)))==NULL )
    {	init_error(Out_of_memory);
        return(-1);
    }
    /* create_role */
    event=event_type_find_name("create_role");
    strncpy(eh[0].op_name,"rbac_h_create_role",MEDUSA_OPNAME_MAX);
    eh[0].handler=rbac_h_create_role;
    eh[0].local_vars=NULL;
    if( register_event_handler(&(eh[0]),event,&(event->handlers_hash[EHH_VS_ALLOW]),ALL_OBJ,ALL_OBJ)<0 )
        return(init_error("rbac: Can't register handler for create_role"));
    /* delete_role */
    event=event_type_find_name("delete_role");
    strncpy(eh[1].op_name,"rbac_h_delete_role",MEDUSA_OPNAME_MAX);
    eh[1].handler=rbac_h_delete_role;
    eh[1].local_vars=NULL;
    if( register_event_handler(&(eh[1]),event,&(event->handlers_hash[EHH_VS_ALLOW]),ALL_OBJ,ALL_OBJ)<0 )
        return(init_error("rbac: Can't register handler for delete_role"));
    /* role_hierarchy */
    event=event_type_find_name("role_hierarchy");
    strncpy(eh[2].op_name,"rbac_h_role_hierarchy",MEDUSA_OPNAME_MAX);
    eh[2].handler=rbac_h_role_hierarchy;
    eh[2].local_vars=NULL;
    if( register_event_handler(&(eh[2]),event,&(event->handlers_hash[EHH_VS_ALLOW]),ALL_OBJ,ALL_OBJ)<0 )
        return(init_error("rbac: Can't register handler for role_hierarchy"));
    /* uses_assign */
    event=event_type_find_name("uses_assign");
    strncpy(eh[3].op_name,"rbac_h_user_assign",MEDUSA_OPNAME_MAX);
    eh[3].handler=rbac_h_user_assign;
    eh[3].local_vars=NULL;
    if( register_event_handler(&(eh[3]),event,&(event->handlers_hash[EHH_VS_ALLOW]),ALL_OBJ,ALL_OBJ)<0 )
        return(init_error("rbac: Can't register handler for uses_assign"));
    /* role_assign */
    event=event_type_find_name("role_assign");
    strncpy(eh[4].op_name,"rbac_h_role_assign",MEDUSA_OPNAME_MAX);
    eh[4].handler=rbac_h_role_assign;
    eh[4].local_vars=NULL;
    if( register_event_handler(&(eh[4]),event,&(event->handlers_hash[EHH_VS_ALLOW]),ALL_OBJ,ALL_OBJ)<0 )
        return(init_error("rbac: Can't register handler for role_assign"));
    /* permission_assign */
    event=event_type_find_name("permission_assign");
    strncpy(eh[5].op_name,"rbac_h_perm_assign",MEDUSA_OPNAME_MAX);
    eh[5].handler=rbac_h_perm_assign;
    eh[5].local_vars=NULL;
    if( register_event_handler(&(eh[5]),event,&(event->handlers_hash[EHH_VS_ALLOW]),ALL_OBJ,ALL_OBJ)<0 )
        return(init_error("rbac: Can't register handler for permission_assign"));
    return(0);
}
Exemple #6
0
static void hostapd_cli_ping(void *eloop_ctx, void *timeout_ctx)
{
	if (ctrl_conn && _wpa_ctrl_command(ctrl_conn, "PING", 0)) {
		printf("Connection to hostapd lost - trying to reconnect\n");
		hostapd_cli_close_connection();
	}
	if (!ctrl_conn) {
		ctrl_conn = hostapd_cli_open_connection(ctrl_ifname);
		if (ctrl_conn) {
			printf("Connection to hostapd re-established\n");
			if (wpa_ctrl_attach(ctrl_conn) == 0) {
				hostapd_cli_attached = 1;
				register_event_handler(ctrl_conn);
			} else {
				printf("Warning: Failed to attach to "
				       "hostapd.\n");
			}
		}
	}
	if (ctrl_conn)
		hostapd_cli_recv_pending(ctrl_conn, 1, 0);
	eloop_register_timeout(ping_interval, 0, hostapd_cli_ping, NULL, NULL);
}
int main(int argc, char *argv[])
{
    int res = 0;

    /* Parse command line parameters */
    if (0 != (res = parse_peer_params(argc, argv, &proc_id, &fname))) {
        dbg_err("parse_args() returned nonzero status:%d", res);
        goto end;
    }

    /*
     * Parse the DME simulation config file.
     */
    if (0 != (res = parse_file(fname, proc_id, &nodes, &nodes_count))) {
        dbg_err("parse_file() returned nonzero status:%d", res);
        goto end;
    }

    /* Initialize and allocate any structures/vars used by the generic algorithm */

    /* struct genericstruct = calloc(...) */

    /*
     * Init connections (open listening socket)
     */
    if (0 != (res = open_listen_socket(proc_id, nodes, nodes_count))) {
        dbg_err("open_listen_socket() returned nonzero status:%d", res);
        goto end;
    }

    /*
     * Register signals (for I/O, alarms, etc.)
     */
    if (0 != (res = init_handlers(nodes[proc_id].sock_fd))) {
        dbg_err("init_handlers() returned nonzero status");
        goto end;
    }

    /* Register event handlers that will be called automatically on event occurrence */
    register_event_handler(DME_EV_SUP_MSG_IN, handle_supervisor_msg);
    register_event_handler(DME_EV_PEER_MSG_IN, handle_peer_msg);
    register_event_handler(DME_EV_WANT_CRITICAL_REG, process_ev_want_cr);
    register_event_handler(DME_EV_ENTERED_CRITICAL_REG, process_ev_entered_cr);
    register_event_handler(DME_EV_EXITED_CRITICAL_REG, process_ev_exited_cr);

    /*
     * Main loop: just sit here and wait for events (triggered by the supervisor).
     * All work is done in interrupt handlers mapped to registered functions.
     */
    wait_events();

end:
    /*
     * Do cleanup (deallocating dynamic structures)
     */
    deinit_handlers();

    /* Close our listening socket */
    if (nodes && nodes[proc_id].sock_fd > 0) {
        close(nodes[proc_id].sock_fd);
    }

    /* Free allocated structures */
    safe_free(nodes);

    return res;
}
Exemple #8
0
static int
init_daemon(void)
{
	int sock, i;
	struct sockaddr_un name;
	iscsid_request_t req;

	if ((driver = open(DEVICE, O_RDONLY)) < 0) {
		perror("opening " DEVICE);
		return -1;
	}

	sock = socket(AF_UNIX, SOCK_DGRAM, 0);
	if (sock < 0) {
		perror("opening datagram socket");
		return -1;
	}

	name.sun_family = AF_UNIX;
	strlcpy(name.sun_path, ISCSID_SOCK_NAME, sizeof(name.sun_path));

	req.request = ISCSID_DAEMON_TEST;
	req.parameter_length = 0;

	i = sendto(sock, &req, sizeof(req), 0, (struct sockaddr *)(void *)&name,
				(socklen_t)sizeof(struct sockaddr_un));
	if (i == sizeof(req)) {
		printf("Daemon already loaded!\n");
		close(sock);
		return -1;
	}

	unlink(ISCSID_SOCK_NAME);
	if (bind(sock, (struct sockaddr *)(void *)&name, (socklen_t)sizeof(struct sockaddr_un))) {
		perror("binding name to socket");
		return -1;
	}

	for (i = 0; i < NUM_DAEMON_LISTS; i++) {
		TAILQ_INIT(&list[i].list);
		list[i].num_entries = 0;
	}

	if (!nothreads && (i = pthread_mutex_init(&sesslist_lock, NULL)) != 0) {
		printf("Mutex init failed (%d)\n", i);
		close(sock);
		return -1;
	}

	if (!register_event_handler()) {
		printf("Couldn't register event handler\n");
		close(sock);
		unlink(ISCSID_SOCK_NAME);
		if (!nothreads)
			pthread_mutex_destroy(&sesslist_lock);
		return -1;
	}

	create_node_name();

	return sock;
}
int main(int argc, char *argv[])
{
    int res = 0;
    
    if (0 != (res = parse_sup_params(argc, argv, &fname, &logfname,
                                     &concurency_ratio, &max_concurrent_proc,
                                     &election_interval, &number_of_runs))) {
        dbg_err("parse_args() returned nonzero status:%d", res);
        goto end;
    }

    /*
     * Parse the file fname
     */
    if (0 != (res = parse_file(fname, proc_id, &nodes, &nodes_count))) {
        dbg_err("parse_file() returned nonzero status:%d", res);
        goto end;
    }
    dbg_msg("nodes has %d elements", nodes_count);

    /* compute the number of maximum concurrent processes (nearest integer) */
    if (max_concurrent_proc != 0) {
        /* The '-c' option was specified on the command line */
        fixed_concurent_num = TRUE;
    } else {
        /* Compute based on concurrency ratio */
        max_concurrent_proc = (nodes_count * concurency_ratio + 50) / 100;
        fixed_concurent_num = FALSE;
    }

    if (max_concurrent_proc < 2) {
        dbg_err("concurrency ratio or number set too low. At least 2 processes must be concurrent.");
        goto end;
    } else if (max_concurrent_proc > nodes_count) {
        dbg_err("concurrency number is greater than total number of processes. Setting it to maximum.");
        max_concurrent_proc = nodes_count;
    }

    dbg_msg("max_concurrent_proc=%d", max_concurrent_proc);

    randomizer_init();
    
    /* Allocate the statistics collection storage and open the log file */
    synchro_delays = calloc(nodes_count, sizeof(timespec_t));
    response_times = calloc(nodes_count, sizeof(timespec_t));

    if (NULL == (log_fh = fopen(logfname, "w"))) {
        dbg_err("Could not open log file %s for writing", logfname);
        res = ERR_BADFILE;
        goto end;
    }


    /*
     * Init connections (open listening socket)
     */
    if (0 != (res = open_listen_socket(proc_id, nodes, nodes_count))) {
        dbg_err("open_listen_socket() returned nonzero status:%d", res);
        goto end;
    }

    /*
     * Register signals (for I/O, alarms, etc.)
     */
    if (0 != (res = init_handlers(nodes[proc_id].sock_fd))) {
        dbg_err("init_handlers() returned nonzero status");
        goto end;
    }
    
    register_event_handler(DME_SEV_PERIODIC_WORK, do_work);
    register_event_handler(DME_SEV_SYNCRO, syncro);
    register_event_handler(DME_SEV_ENDSIMULATION, end_simulation);
    register_event_handler(DME_SEV_MSG_IN, process_messages);

    /* wait for peers processes to init, then kick start the supervisor */
    sleep(1);
    
    /* Start working; mark time */
    clock_gettime(CLOCK_REALTIME, &tstamp_supervisor_start);

    handle_event(DME_SEV_SYNCRO, &tstamp_supervisor_start);
    sleep(1);

    handle_event(DME_SEV_PERIODIC_WORK, NULL);

    /*
     * Main loop: just sit here and wait for interrupts.
     * All work is done in interrupt handlers mapped to registered functions.
     */
    wait_events();
    
end:
    /*
     * Do cleanup (deallocating dynamic structures)
     */
    deinit_handlers();

    /* Close our listening socket */
    if (nodes && nodes[proc_id].sock_fd > 0) {
        close(nodes[proc_id].sock_fd);
    }

    if (log_fh) {
        fclose(log_fh);
    }

    safe_free(nodes);
    safe_free(synchro_delays);
    safe_free(response_times);
    
    return res;
}
Exemple #10
0
int main(int argc, char *argv[])
{
	int warning_displayed = 0;
	int c;
	int daemonize = 0;

	if (os_program_init())
		return -1;

	for (;;) {
		c = getopt(argc, argv, "a:BhG:i:p:P:s:v");
		if (c < 0)
			break;
		switch (c) {
		case 'a':
			action_file = optarg;
			break;
		case 'B':
			daemonize = 1;
			break;
		case 'G':
			ping_interval = atoi(optarg);
			break;
		case 'h':
			usage();
			return 0;
		case 'v':
			printf("%s\n", hostapd_cli_version);
			return 0;
		case 'i':
			os_free(ctrl_ifname);
			ctrl_ifname = os_strdup(optarg);
			break;
		case 'p':
			ctrl_iface_dir = optarg;
			break;
		case 'P':
			pid_file = optarg;
			break;
		case 's':
			client_socket_dir = optarg;
			break;
		default:
			usage();
			return -1;
		}
	}

	interactive = (argc == optind) && (action_file == NULL);

	if (interactive) {
		printf("%s\n\n%s\n\n", hostapd_cli_version, cli_license);
	}

	if (eloop_init())
		return -1;

	for (;;) {
		if (ctrl_ifname == NULL) {
			struct dirent *dent;
			DIR *dir = opendir(ctrl_iface_dir);
			if (dir) {
				while ((dent = readdir(dir))) {
					if (os_strcmp(dent->d_name, ".") == 0
					    ||
					    os_strcmp(dent->d_name, "..") == 0)
						continue;
					printf("Selected interface '%s'\n",
					       dent->d_name);
					ctrl_ifname = os_strdup(dent->d_name);
					break;
				}
				closedir(dir);
			}
		}
		ctrl_conn = hostapd_cli_open_connection(ctrl_ifname);
		if (ctrl_conn) {
			if (warning_displayed)
				printf("Connection established.\n");
			break;
		}

		if (!interactive) {
			perror("Failed to connect to hostapd - "
			       "wpa_ctrl_open");
			return -1;
		}

		if (!warning_displayed) {
			printf("Could not connect to hostapd - re-trying\n");
			warning_displayed = 1;
		}
		os_sleep(1, 0);
		continue;
	}

	if (interactive || action_file) {
		if (wpa_ctrl_attach(ctrl_conn) == 0) {
			hostapd_cli_attached = 1;
			register_event_handler(ctrl_conn);
		} else {
			printf("Warning: Failed to attach to hostapd.\n");
			if (action_file)
				return -1;
		}
	}

	if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue())
		return -1;

	if (interactive)
		hostapd_cli_interactive();
	else if (action_file)
		hostapd_cli_action(ctrl_conn);
	else
		wpa_request(ctrl_conn, argc - optind, &argv[optind]);

	unregister_event_handler(ctrl_conn);
	os_free(ctrl_ifname);
	eloop_destroy();
	hostapd_cli_cleanup();
	return 0;
}