コード例 #1
0
ファイル: ntpd.c プロジェクト: tunneleffekt/openntpd-openbsd
int
main(int argc, char *argv[])
{
	struct ntpd_conf	 lconf;
	struct pollfd		 pfd[POLL_MAX];
	pid_t			 chld_pid = 0, pid;
	const char		*conffile;
	int			 fd_ctl, ch, nfds;
	int			 pipe_chld[2];
	struct passwd		*pw;
	extern char		*__progname;

	if (strcmp(__progname, "ntpctl") == 0) {
		ctl_main(argc, argv);
		/* NOTREACHED */
	}

	conffile = CONFFILE;

	bzero(&lconf, sizeof(lconf));

	log_init(1);		/* log to stderr until daemonized */

	while ((ch = getopt(argc, argv, "df:nsSv")) != -1) {
		switch (ch) {
		case 'd':
			lconf.debug = 1;
			log_verbose(1);
			break;
		case 'f':
			conffile = optarg;
			break;
		case 'n':
			lconf.noaction = 1;
			break;
		case 's':
			lconf.settime = 1;
			break;
		case 'S':
			lconf.settime = 0;
			break;
		case 'v':
			log_verbose(1);
			break;
		default:
			usage();
			/* NOTREACHED */
		}
	}

	argc -= optind;
	argv += optind;
	if (argc > 0)
		usage();

	if (parse_config(conffile, &lconf))
		exit(1);

	if (lconf.noaction) {
		fprintf(stderr, "configuration OK\n");
		exit(0);
	}

	if (geteuid())
		errx(1, "need root privileges");

	if ((pw = getpwnam(NTPD_USER)) == NULL)
		errx(1, "unknown user %s", NTPD_USER);

	if (setpriority(PRIO_PROCESS, 0, -20) == -1)
		warn("can't set priority");

	reset_adjtime();
	if (!lconf.settime) {
		log_init(lconf.debug);
		if (!lconf.debug)
			if (daemon(1, 0))
				fatal("daemon");
	} else
		timeout = SETTIME_TIMEOUT * 1000;

	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_chld) == -1)
		fatal("socketpair");

	if ((fd_ctl = control_init(CTLSOCKET)) == -1)
		fatalx("control socket init failed");
	if (control_listen(fd_ctl) == -1)
		fatalx("control socket listen failed");

	signal(SIGCHLD, sighdlr);
	/* fork child process */
	chld_pid = ntp_main(pipe_chld, fd_ctl, &lconf, pw);

	setproctitle("[priv]");
	readfreq();

	signal(SIGTERM, sighdlr);
	signal(SIGINT, sighdlr);
	signal(SIGHUP, sighdlr);

	close(pipe_chld[1]);

	if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL)
		fatal(NULL);
	imsg_init(ibuf, pipe_chld[0]);

	while (quit == 0) {
		pfd[PFD_PIPE].fd = ibuf->fd;
		pfd[PFD_PIPE].events = POLLIN;
		if (ibuf->w.queued)
			pfd[PFD_PIPE].events |= POLLOUT;

		if ((nfds = poll(pfd, 1, timeout)) == -1)
			if (errno != EINTR) {
				log_warn("poll error");
				quit = 1;
			}

		if (nfds == 0 && lconf.settime) {
			lconf.settime = 0;
			timeout = INFTIM;
			log_init(lconf.debug);
			log_warnx("no reply received in time, skipping initial "
			    "time setting");
			if (!lconf.debug)
				if (daemon(1, 0))
					fatal("daemon");
		}

		if (nfds > 0 && (pfd[PFD_PIPE].revents & POLLOUT))
			if (msgbuf_write(&ibuf->w) <= 0 && errno != EAGAIN) {
				log_warn("pipe write error (to child)");
				quit = 1;
			}

		if (nfds > 0 && pfd[PFD_PIPE].revents & POLLIN) {
			nfds--;
			if (dispatch_imsg(&lconf) == -1)
				quit = 1;
		}

		if (sigchld) {
			if (check_child(chld_pid, "child")) {
				quit = 1;
				chld_pid = 0;
			}
			sigchld = 0;
		}

	}

	signal(SIGCHLD, SIG_DFL);

	if (chld_pid)
		kill(chld_pid, SIGTERM);

	do {
		if ((pid = wait(NULL)) == -1 &&
		    errno != EINTR && errno != ECHILD)
			fatal("wait");
	} while (pid != -1 || (pid == -1 && errno == EINTR));

	msgbuf_clear(&ibuf->w);
	free(ibuf);
	log_info("Terminating");
	return (0);
}
コード例 #2
0
ファイル: cSploitd.c プロジェクト: Monkey-Media/daemon
/**
 * @brief initialize lists controls
 * @returns 0 on success, -1 on error.
 */
int init_structs() {
  if( control_init(&(connections.control)) ||
      control_init(&(graveyard.control)) )
    return -1;
  return 0;
}
コード例 #3
0
ファイル: connection.c プロジェクト: Katarzynasrom/daemon
/**
 * @brief start a @connection_handler for a new client.
 * @param fd file descriptor of the new client
 * @returns 0 on success, -1 on error.
 */
int serve_new_client(int fd) {
  conn_node *c;
  pthread_t dummy;
  int writer_created, worker_created;
  
  
  pthread_mutex_lock(&(connections.control.mutex));
  writer_created = connections.control.active; // OPTIMIZATION
  pthread_mutex_unlock(&(connections.control.mutex));
  
  if(!writer_created) {
    print( ERROR, "connections disabled" );
    return -1;
  }
  
  writer_created = worker_created = 0;
  
  c = malloc(sizeof(conn_node));
  
  if(!c) {
    print( ERROR, "malloc: %s", strerror(errno) );
    return -1;
  }

  memset(c, 0, sizeof(conn_node));
  
  if(control_init(&(c->control)) || control_init(&(c->incoming.control)) ||
    control_init(&(c->outcoming.control))) {
    print( ERROR, "cannot init cotnrols" );
    free_connection(c);
    return -1;
  }

  c->fd = fd;
  
  pthread_mutex_lock(&(connections.control.mutex));
  
  if( (writer_created = pthread_create(&dummy, NULL, &connection_writer, (void *)c)) ||
      (worker_created = pthread_create(&dummy, NULL, &connection_worker, (void *)c)) ||
      pthread_create(&dummy, NULL, &connection_reader, (void *)c)) {
    pthread_mutex_unlock(&(connections.control.mutex));
    print( ERROR, "pthread_create: %s", strerror(errno) );
    goto create_error;
  }
  
  list_add(&(connections.list), (node *) c);
  
  pthread_mutex_unlock(&(connections.control.mutex));

  pthread_cond_broadcast(&(connections.control.cond));
  
  return 0;
  
  create_error:
  
  if(writer_created || worker_created) {
    stop_connection(c);
    pthread_mutex_lock(&(c->control.mutex));
    while((writer_created && !c->writer_done) || (worker_created && !c->worker_done)) {
      pthread_cond_wait(&(c->control.cond), &(c->control.mutex));
    }
    pthread_mutex_unlock(&(c->control.mutex));
  }
  
  free_connection(c);
  
  return -1;
}
コード例 #4
0
ファイル: threads_linux.c プロジェクト: lara-unb/rleg-overo
int threads_linux_init(void)
{
    int status = 0;
    int n = 0;
    int return_value = THREADS_LINUX_SUCCESS;

    // Init data
    status = sensors_init(&battery_data, &gps_data, &imu_data, &pitot_data, &pwm_read_data, &pwm_write_data, &scp1000_data, &sonar_data);
    if(status != SENSORS_SUCCESS)
    {
        return_value = THREADS_LINUX_FAILURE;
    }

    if(return_value != THREADS_LINUX_FAILURE)
    {
        status = calibration_init(&calibration_local_coordinate_system_data, &calibration_local_fields_data, &calibration_altimeter_data);
        if(status != CALIBRATION_SUCCESS)
        {
            return_value = THREADS_LINUX_FAILURE;
        }
    }

    if(return_value != THREADS_LINUX_FAILURE)
    {
        status = gps_init(&gps_measure);
        if(status != 1)
        {
            return_value = THREADS_LINUX_FAILURE;
        }
    }

    if(return_value != THREADS_LINUX_FAILURE)
    {
        status = imu_init(&imu_measure);
        if(status != 1)
        {
            return_value = THREADS_LINUX_FAILURE;
        }
    }

    if(return_value != THREADS_LINUX_FAILURE)
    {
        status = magnetometer_init(&magnetometer_measure);
        if(status != 1)
        {
            return_value = THREADS_LINUX_FAILURE;
        }
    }

    if(return_value != THREADS_LINUX_FAILURE)
    {
    	status = sonar_init(&sonar_measure);
    	if(status != 1)
    	{
    		return_value = THREADS_LINUX_FAILURE;
    	}
    }

    if(return_value != THREADS_LINUX_FAILURE)
    {
        status = estimation_init(ESTIMATION_DO_NOT_ESTIMATE_ACCEL_BIAS, &estimation_data);
        if(status != ESTIMATION_SUCCESS)
        {
            return_value = THREADS_LINUX_FAILURE;
        }
    }

    if(return_value != THREADS_LINUX_FAILURE)
    {
        status = control_init(&control_data);
        if(status != CONTROL_SUCCESS)
        {
            return_value = THREADS_LINUX_FAILURE;
        }
    }

    if(return_value != THREADS_LINUX_FAILURE)
    {
        status = protocol_init();
        if(status != PROTOCOL_SUCCESS)
        {
            return_value = THREADS_LINUX_FAILURE;
        }
    }

    if(return_value != THREADS_LINUX_FAILURE)
    {
        status = ui_init();
        if(status != UI_SUCCESS)
        {
            return_value = THREADS_LINUX_FAILURE;
        }
    }

    if(return_value != THREADS_LINUX_FAILURE)
    {
        status = datalogger_init();
        if(status != DATALOGGER_SUCCESS)
        {
            return_value = THREADS_LINUX_FAILURE;
        }
    }

    // Main Loop
    if(return_value != THREADS_LINUX_FAILURE)
    {
        threads_linux_timer_start_task_1();
        usleep(0.5*task_1_period_us);
        threads_linux_timer_start_task_2();
        usleep(5*task_1_period_us);

        while(quittask == 0)
        {
            #if ANU_COMPILE_FOR_OVERO
            #else
            if(datalogger_status() == DATALOGGER_RUNNING) datalogger_update_IPC();
            #endif
            if(++n>100)
            {
                if(datalogger_status() == DATALOGGER_RUNNING) datalogger_write_file();
                n = 0;
            }
            usleep(5*task_1_period_us);
        }

        threads_linux_timer_stop_task_1();
        usleep(TASK1_PERIOD_US);
        threads_linux_timer_stop_task_2();
        usleep(TASK2_PERIOD_US);
    }

    status = datalogger_close();
    if(status != DATALOGGER_SUCCESS)
    {
        return_value = THREADS_LINUX_FAILURE;
    }

    status = ui_close();
    if(status != UI_SUCCESS)
    {
        return_value = THREADS_LINUX_FAILURE;
    }

    status = protocol_close();
    if(status != PROTOCOL_SUCCESS)
    {
        return_value = THREADS_LINUX_FAILURE;
    }

    status = control_close();
    if(status != CONTROL_SUCCESS)
    {
        return_value = THREADS_LINUX_FAILURE;
    }

    status = estimation_close(&estimation_data);
    if(status != ESTIMATION_SUCCESS)
    {
        return_value = THREADS_LINUX_FAILURE;
    }

    status = magnetometer_close(&magnetometer_measure);
    if(status != 1)
    {
        return_value = THREADS_LINUX_FAILURE;
    }

    status = imu_close(&imu_measure);
    if(status != 1)
    {
        return_value = THREADS_LINUX_FAILURE;
    }
    status = gps_close(&gps_measure);
    if(status != 1)
    {
        return_value = THREADS_LINUX_FAILURE;
    }

    status = calibration_close(&calibration_local_coordinate_system_data, &calibration_local_fields_data, &calibration_altimeter_data);
    if(status != CALIBRATION_SUCCESS)
    {
        return_value = THREADS_LINUX_FAILURE;
    }

    status = sensors_close();
    if(status != SENSORS_SUCCESS)
    {
        return_value = THREADS_LINUX_FAILURE;
    }

    return return_value;
}
コード例 #5
0
ファイル: proc.c プロジェクト: ajinkya93/OpenBSD
pid_t
proc_run(struct privsep *ps, struct privsep_proc *p,
    struct privsep_proc *procs, unsigned int nproc,
    void (*run)(struct privsep *, struct privsep_proc *, void *), void *arg)
{
	pid_t			 pid;
	struct passwd		*pw;
	const char		*root;
	struct control_sock	*rcs;
	unsigned int		 n;

	if (ps->ps_noaction)
		return (0);

	proc_open(ps, p, procs, nproc);

	/* Fork child handlers */
	switch (pid = fork()) {
	case -1:
		fatal("proc_run: cannot fork");
	case 0:
		log_procinit(p->p_title);

		/* Set the process group of the current process */
		setpgid(0, 0);
		break;
	default:
		return (pid);
	}

	pw = ps->ps_pw;

	if (p->p_id == PROC_CONTROL && ps->ps_instance == 0) {
		if (control_init(ps, &ps->ps_csock) == -1)
			fatalx(__func__);
		TAILQ_FOREACH(rcs, &ps->ps_rcsocks, cs_entry)
			if (control_init(ps, rcs) == -1)
				fatalx(__func__);
	}

	/* Change root directory */
	if (p->p_chroot != NULL)
		root = p->p_chroot;
	else
		root = pw->pw_dir;

	if (chroot(root) == -1)
		fatal("proc_run: chroot");
	if (chdir("/") == -1)
		fatal("proc_run: chdir(\"/\")");

	privsep_process = p->p_id;

	setproctitle("%s", p->p_title);

	if (setgroups(1, &pw->pw_gid) ||
	    setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
	    setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
		fatal("proc_run: cannot drop privileges");

	/* Fork child handlers */
	for (n = 1; n < ps->ps_instances[p->p_id]; n++) {
		if (fork() == 0) {
			ps->ps_instance = p->p_instance = n;
			break;
		}
	}

#ifdef DEBUG
	log_debug("%s: %s %d/%d, pid %d", __func__, p->p_title,
	    ps->ps_instance + 1, ps->ps_instances[p->p_id], getpid());
#endif

	event_init();

	signal_set(&ps->ps_evsigint, SIGINT, proc_sig_handler, p);
	signal_set(&ps->ps_evsigterm, SIGTERM, proc_sig_handler, p);
	signal_set(&ps->ps_evsigchld, SIGCHLD, proc_sig_handler, p);
	signal_set(&ps->ps_evsighup, SIGHUP, proc_sig_handler, p);
	signal_set(&ps->ps_evsigpipe, SIGPIPE, proc_sig_handler, p);
	signal_set(&ps->ps_evsigusr1, SIGUSR1, proc_sig_handler, p);

	signal_add(&ps->ps_evsigint, NULL);
	signal_add(&ps->ps_evsigterm, NULL);
	signal_add(&ps->ps_evsigchld, NULL);
	signal_add(&ps->ps_evsighup, NULL);
	signal_add(&ps->ps_evsigpipe, NULL);
	signal_add(&ps->ps_evsigusr1, NULL);

	proc_listen(ps, procs, nproc);

	if (p->p_id == PROC_CONTROL && ps->ps_instance == 0) {
		TAILQ_INIT(&ctl_conns);
		if (control_listen(&ps->ps_csock) == -1)
			fatalx(__func__);
		TAILQ_FOREACH(rcs, &ps->ps_rcsocks, cs_entry)
			if (control_listen(rcs) == -1)
				fatalx(__func__);
	}
コード例 #6
0
ファイル: manager.c プロジェクト: dev-life/GT-I9300_Platform
static void handle_uuid(const char *uuidstr, struct audio_device *device)
{
	uuid_t uuid;
	uint16_t uuid16;

	if (bt_string2uuid(&uuid, uuidstr) < 0) {
		error("%s not detected as an UUID-128", uuidstr);
		return;
	}

	if (!sdp_uuid128_to_uuid(&uuid) && uuid.type != SDP_UUID16) {
		error("Could not convert %s to a UUID-16", uuidstr);
		return;
	}

	uuid16 = uuid.value.uuid16;

	if (!server_is_enabled(&device->src, uuid16)) {
		DBG("server not enabled for %s (0x%04x)", uuidstr, uuid16);
		return;
	}

	switch (uuid16) {
	case HEADSET_SVCLASS_ID:
		DBG("Found Headset record");
		if (device->headset)
			headset_update(device, uuid16, uuidstr);
		else
			device->headset = headset_init(device, uuid16,
							uuidstr);
		break;
	case HEADSET_AGW_SVCLASS_ID:
		DBG("Found Headset AG record");
		break;
	case HANDSFREE_SVCLASS_ID:
		DBG("Found Handsfree record");
		if (device->headset)
			headset_update(device, uuid16, uuidstr);
		else
			device->headset = headset_init(device, uuid16,
								uuidstr);
		break;
	case HANDSFREE_AGW_SVCLASS_ID:
		DBG("Found Handsfree AG record");
		if (enabled.gateway && (device->gateway == NULL))
			device->gateway = gateway_init(device);
		break;
	case AUDIO_SINK_SVCLASS_ID:
		DBG("Found Audio Sink");
		if (device->sink == NULL)
			device->sink = sink_init(device);
		break;
	case AUDIO_SOURCE_SVCLASS_ID:
		DBG("Found Audio Source");
		if (device->source == NULL)
			device->source = source_init(device);
		break;
	case AV_REMOTE_SVCLASS_ID:
	case AV_REMOTE_TARGET_SVCLASS_ID:
		DBG("Found AV %s", uuid16 == AV_REMOTE_SVCLASS_ID ?
							"Remote" : "Target");
		if (device->control)
			control_update(device, uuid16);
		else
			device->control = control_init(device, uuid16);
		/* SS_Bluetooth(sunjo4.kim) 2012.2.16 - add for a2dp connect fail */
		//if (device->sink && sink_is_active(device))
		//	avrcp_connect(device);
                /* SS_Bluetooth(sunjo4.kim) End */
		break;
	default:
		DBG("Unrecognized UUID: 0x%04X", uuid16);
		break;
	}
}
コード例 #7
0
ファイル: dhcpd.c プロジェクト: gduchene/dhcpd
int
main(int argc, char *argv[])
{
	struct passwd *pw;
	char *ctlpath = NULL;
	int ch, debug = 0;

	while ((ch = getopt(argc, argv, "ds:")) != -1) {
		switch (ch) {
		case 'd':
			++debug;
			break;
		case 's':
			ctlpath = optarg;
			break;
		default:
			return usage();
		}
	}

	argc -= optind;
	argv += optind;

	if ((pw = getpwnam(UNPRIVILEGED_USER)) == NULL)
		err(1, "there isn't any user called " UNPRIVILEGED_USER);

	if (control_sock == -1)
		control_sock = control_init(ctlpath, pw->pw_uid, pw->pw_gid);
	if (control_sock == -1)
		errx(1, "there isn't any control socket.");

	if ((kernel_rtsock = rtsock_init()) == -1)
		errx(1, "there isn't any routing socket.");

	log_init(debug);
	log_info("starting");

	if (!debug)
		daemon(1, 0);

	drop_privileges(pw);
	set_defaults();

	if (event_init() == NULL)
		fatal("event_init");

	if (interfaces_discover() == -1)
		fatal("discovering interfaces");

	signal_set(&sigevents[0], SIGHUP, unprivileged_signal_handler, NULL);
	signal_set(&sigevents[1], SIGINT, unprivileged_signal_handler, NULL);
	signal_set(&sigevents[2], SIGTERM, unprivileged_signal_handler, NULL);
	signal_set(&sigevents[3], SIGCHLD, unprivileged_signal_handler, NULL);
	signal_set(&sigevents[4], SIGPIPE, unprivileged_signal_handler, NULL);

	for (int i = 0; i < __SIGNAL_HANDLERS__; ++i)
		if (signal_add(&sigevents[i], NULL))
			fatal("signal_add");

	event_set(&events[CONTROL_SOCKET], control_sock, EV_READ | EV_PERSIST,
	    control_accept, NULL);
	event_set(&events[ROUTING_SOCKET], kernel_rtsock, EV_READ | EV_PERSIST,
	    rtsock_dispatch, NULL);
	event_set(&events[PRIVSEP_SOCKET], privsep_sock, EV_READ | EV_PERSIST,
	    unprivileged_dispatch, NULL);

	//for (int i = 0; i < __SOCKETS_ALWAYS_PRESENT__; ++i)
	for (int i = 0; i <= PRIVSEP_SOCKET; ++i)
		if (event_add(events + i, NULL))
			fatal("event_add");

	stats[STATS_DAEMON_STARTED] = time(NULL);
	event_dispatch();

	close(control_sock);
	unsatisfied_purge();
	interfaces_destroy();
	log_info("exitting %s", privileged_exit_code ? "badly" : "gracefully");
	return (privileged_exit_code);
}
コード例 #8
0
ファイル: proc.c プロジェクト: koue/httpd
void
proc_run(struct privsep *ps, struct privsep_proc *p,
    struct privsep_proc *procs, unsigned int nproc,
    void (*run)(struct privsep *, struct privsep_proc *, void *), void *arg)
{
	struct passwd		*pw;
	const char		*root;
	struct control_sock	*rcs;

	if (ps->ps_noaction)
		exit(0);

	log_procinit(p->p_title);

	/* Set the process group of the current process */
	setpgid(0, 0);

	if (p->p_id == PROC_CONTROL && ps->ps_instance == 0) {
		if (control_init(ps, &ps->ps_csock) == -1)
			fatalx(__func__);
		TAILQ_FOREACH(rcs, &ps->ps_rcsocks, cs_entry)
			if (control_init(ps, rcs) == -1)
				fatalx(__func__);
	}

	/* Use non-standard user */
	if (p->p_pw != NULL)
		pw = p->p_pw;
	else
		pw = ps->ps_pw;

	/* Change root directory */
	if (p->p_chroot != NULL)
		root = p->p_chroot;
	else
		root = pw->pw_dir;

	if (chroot(root) == -1)
		fatal("proc_run: chroot");
	if (chdir("/") == -1)
		fatal("proc_run: chdir(\"/\")");

	privsep_process = p->p_id;

	setproctitle("%s", p->p_title);

	if (setgroups(1, &pw->pw_gid) ||
	    setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
	    setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
		fatal("proc_run: cannot drop privileges");

	event_init();

	signal_set(&ps->ps_evsigint, SIGINT, proc_sig_handler, p);
	signal_set(&ps->ps_evsigterm, SIGTERM, proc_sig_handler, p);
	signal_set(&ps->ps_evsigchld, SIGCHLD, proc_sig_handler, p);
	signal_set(&ps->ps_evsighup, SIGHUP, proc_sig_handler, p);
	signal_set(&ps->ps_evsigpipe, SIGPIPE, proc_sig_handler, p);
	signal_set(&ps->ps_evsigusr1, SIGUSR1, proc_sig_handler, p);

	signal_add(&ps->ps_evsigint, NULL);
	signal_add(&ps->ps_evsigterm, NULL);
	signal_add(&ps->ps_evsigchld, NULL);
	signal_add(&ps->ps_evsighup, NULL);
	signal_add(&ps->ps_evsigpipe, NULL);
	signal_add(&ps->ps_evsigusr1, NULL);

	proc_setup(ps, procs, nproc);
	proc_accept(ps, PROC_PARENT_SOCK_FILENO, PROC_PARENT, 0);
	if (p->p_id == PROC_CONTROL && ps->ps_instance == 0) {
		TAILQ_INIT(&ctl_conns);
		if (control_listen(&ps->ps_csock) == -1)
			fatalx(__func__);
		TAILQ_FOREACH(rcs, &ps->ps_rcsocks, cs_entry)
			if (control_listen(rcs) == -1)
				fatalx(__func__);
	}
コード例 #9
0
int adapter_probe(struct sdio_func *func, const struct sdio_device_id *id)
{
	struct net_adapter	*adapter;
	struct net_device	*net;
	u_char			charName[32];
	int			nRes = -ENOMEM;
	u_long			idx = 0;
	struct wimax732_platform_data	*pdata;

	dump_debug("Probe!!!!!!!!!");
	pdata = (struct wimax732_platform_data *) id->driver_data;
	net = alloc_etherdev(sizeof(struct net_adapter));
	if (!net) {
		dump_debug("adapter_probe: "
				"error can't allocate device");
		goto alloceth_fail;
	}

	adapter = netdev_priv(net);
	memset(adapter, 0, sizeof(struct net_adapter));
	g_adapter = adapter;

	adapter->pdata = (struct wimax732_platform_data *) id->driver_data;
	adapter->pdata->g_cfg->card_removed = false;
	adapter->pdata->g_cfg->powerup_done = false;

	/* Initialize control */
	control_init(adapter);

	/* initialize hardware */
	nRes = hw_init(adapter);

	if (nRes) {
		dump_debug("adapter_probe: error can't"
				"allocate receive buffer");
		goto hwInit_fail;
	}

	strcpy(net->name, "uwbr%d");

	adapter->func = func;
	adapter->net = net;
	net->netdev_ops = &wimax_net_ops;
	net->watchdog_timeo = ADAPTER_TIMEOUT;
	net->mtu = WIMAX_MTU_SIZE;
	adapter->msg_enable = netif_msg_init(msg_level, NETIF_MSG_DRV
			| NETIF_MSG_PROBE | NETIF_MSG_LINK);

	ether_setup(net);
	net->flags |= IFF_NOARP;

	adapter->media_state = MEDIA_DISCONNECTED;
	adapter->ready = FALSE;
	adapter->halted = FALSE;
	adapter->downloading = TRUE;
	adapter->removed = FALSE;
	adapter->mac_ready = FALSE;
	sdio_set_drvdata(func, adapter);

	SET_NETDEV_DEV(net, &func->dev);
	nRes = register_netdev(net);
	if (nRes)
		goto regdev_fail;

	netif_carrier_off(net);
	netif_tx_stop_all_queues(net);

	sdio_claim_host(adapter->func);
	nRes = sdio_enable_func(adapter->func);
	if (nRes < 0) {
		dump_debug("sdio_enable func error = %d", nRes);
		goto sdioen_fail;
	}

	nRes = sdio_claim_irq(adapter->func, adapter_interrupt);
	if (nRes < 0) {
		dump_debug("sdio_claim_irq = %d", nRes);
		goto sdioirq_fail;
	}
	sdio_set_block_size(adapter->func, 512);
	sdio_release_host(adapter->func);

	memset(charName, 0x00, sizeof(charName));
	create_char_name(charName, idx);
	if (misc_register(&uwibro_dev) != 0) {
		dump_debug("adapter_probe: misc_register() failed");
		goto regchar_fail;
	}

	/* Dummy value for "ifconfig up" for 2.6.24 */
	random_ether_addr(node_id);
	memcpy(net->dev_addr, node_id, sizeof(node_id));

	/* sangam dbg */
	INIT_WORK(&adapter->receive_work, rx_process_data);
	INIT_WORK(&adapter->transmit_work, hw_transmit_thread);
	INIT_WORK(&adapter->wimax_reset, cmc7xx_sdio_reset);

	if (hw_start(adapter)) {
		/* Free the resources and stop the driver processing */
		misc_deregister(&uwibro_dev);
		dump_debug("hw_start failed");
		goto regchar_fail;
	}

	adapter->ready = TRUE;

	return 0;

regchar_fail:
	sdio_claim_host(adapter->func);
	sdio_release_irq(adapter->func);
sdioirq_fail:
	sdio_disable_func(adapter->func);
sdioen_fail:
	sdio_release_host(adapter->func);
	unregister_netdev(adapter->net);
regdev_fail:
	sdio_set_drvdata(func, NULL);
	hw_remove(adapter);
hwInit_fail:
	free_netdev(net);
alloceth_fail:
	pdata->g_cfg->card_removed = true;
	pdata->g_cfg->powerup_done = true;
	pdata->power(0);
	return nRes;
}
コード例 #10
0
pid_t
proc_run(struct privsep *ps, struct privsep_proc *p,
    struct privsep_proc *procs, u_int nproc,
    void (*init)(struct privsep *, void *), void *arg)
{
	pid_t		 pid;
	struct passwd	*pw;
	const char	*root;
	u_int32_t	 seed[256];

	switch (pid = fork()) {
	case -1:
		fatal("proc_run: cannot fork");
	case 0:
		break;
	default:
		return (pid);
	}

	pw = ps->ps_pw;

	if (p->p_id == PROC_CONTROL) {
		if (control_init(ps, &ps->ps_csock) == -1)
			fatalx(p->p_title);
	}

	/* Change root directory */
	if (p->p_chroot != NULL)
		root = p->p_chroot;
	else
		root = pw->pw_dir;

#ifndef DEBUG
	if (chroot(root) == -1)
		fatal("proc_run: chroot");
	if (chdir("/") == -1)
		fatal("proc_run: chdir(\"/\")");
#else
#warning disabling privilege revocation and chroot in DEBUG MODE
	if (p->p_chroot != NULL) {
		if (chroot(root) == -1)
			fatal("proc_run: chroot");
		if (chdir("/") == -1)
			fatal("proc_run: chdir(\"/\")");
	}
#endif

	privsep_process = p->p_id;

	setproctitle("%s", p->p_title);

#ifndef DEBUG
	if (setgroups(1, &pw->pw_gid) ||
	    setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
	    setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
		fatal("proc_run: cannot drop privileges");
#endif

	event_init();

	signal_set(&ps->ps_evsigint, SIGINT, proc_sig_handler, p);
	signal_set(&ps->ps_evsigterm, SIGTERM, proc_sig_handler, p);
	signal_set(&ps->ps_evsigchld, SIGCHLD, proc_sig_handler, p);
	signal_set(&ps->ps_evsighup, SIGHUP, proc_sig_handler, p);
	signal_set(&ps->ps_evsigpipe, SIGPIPE, proc_sig_handler, p);

	signal_add(&ps->ps_evsigint, NULL);
	signal_add(&ps->ps_evsigterm, NULL);
	signal_add(&ps->ps_evsigchld, NULL);
	signal_add(&ps->ps_evsighup, NULL);
	signal_add(&ps->ps_evsigpipe, NULL);

	proc_config(ps, procs, nproc);

	arc4random_buf(seed, sizeof(seed));
	RAND_seed(seed, sizeof(seed));

	if (p->p_id == PROC_CONTROL) {
		TAILQ_INIT(&ctl_conns);
		if (control_listen(&ps->ps_csock) == -1)
			fatalx(p->p_title);
	}

	if (init != NULL)
		init(ps, arg);

	event_dispatch();

	proc_shutdown(p);

	return (0);
}
コード例 #11
0
int main(int argc, void* argv[])
{
    DCMF_Configure_t config;

    config.thread_level = DCMF_THREAD_MULTIPLE;

    DCMF_Messager_initialize();

    DCMF_Messager_configure(&config, &config);

    init();

    if (nranks != (THREAD_NUM + 1))
    {
        printf("This test requires only %d processes \n", (THREAD_NUM + 1));
        fflush(stdout);
        return -1;
    }

    barrier_init(DCMF_DEFAULT_GLOBALBARRIER_PROTOCOL);

    control_init(DCMF_DEFAULT_CONTROL_PROTOCOL, DCMF_DEFAULT_NETWORK);

    memregion_init(LOCAL_MAX_BUF_SIZE * THREAD_NUM);

    get_init(DCMF_DEFAULT_PUT_PROTOCOL, DCMF_TORUS_NETWORK);

    source = (char *) malloc(LOCAL_MAX_BUF_SIZE * THREAD_NUM);
    target = (char *) malloc(LOCAL_MAX_BUF_SIZE * THREAD_NUM);

    send_init(DCMF_DEFAULT_SEND_PROTOCOL, DCMF_TORUS_NETWORK);

    int status;
    long i;

    if (myrank == 0)
    {

        pthread_t threads[THREAD_NUM];
        pthread_barrier_init(&ptbarrier, NULL, THREAD_NUM);
        pthread_barrier_init(&ptbarrier1, NULL, THREAD_NUM);

        for (i = 0; i < THREAD_NUM; i++)
        {
            pthread_create(&threads[i], NULL, mrate_test, (void *) i);
        }

        for (i = 0; i < THREAD_NUM; i++)
        {
            pthread_join(threads[i], (void *) &status);
        }
    }
    else
    {

        snd_rcv_active += LOCAL_ITERATIONS;
        while (snd_rcv_active > 0)
            DCMF_Messager_advance();

    }

    barrier();

    DCMF_Messager_finalize();

    if (myrank == 0)
    {
        printf("Benchmark Complete \n");
        fflush(stdout);
    }

    return (0);
}
コード例 #12
0
ファイル: control_test.c プロジェクト: ingmanuelalfonso/uquad
int main(int argc, char *argv[])
{
    // Catch signals
    signal(SIGINT, uquad_sig_handler);
    signal(SIGQUIT, uquad_sig_handler);

    int
	i,
	retval;
    FILE *file;
    uquad_mat_t *x, *w;
    uquad_bool_t ctrl_outdated = false;
    double w_hover;

    if(argc < 2)
    {
	err_log_str("Invalid arguments!",USAGE)
	quit();
    }
    else
    {
	file = fopen(argv[1],"r");
	if(file == NULL)
	{
	    err_log_stderr("Failed to open log!");
	    quit();
	}
    }
    x = uquad_mat_alloc(STATE_COUNT,1);
    w = uquad_mat_alloc(LENGTH_INPUT,1);
    if(x == NULL || w == NULL)
    {
	quit_log_if(ERROR_MALLOC,"Failed to allocate tmp mem!");
    }

    /**
     * The following should be done by calling mot_update_w_hover(), this
     * is just a test program.
     */
    retval = uquad_solve_pol2(&w_hover, NULL, F_B1, F_B2, -GRAVITY*MASA_DEFAULT/4.0);
    quit_log_if(retval, "Failed to get w_hover!");
    for(i=0; i<LENGTH_INPUT; ++i)
	w->m_full[i] = w_hover;

    retval = uquad_mat_zeros(x);
    quit_if(retval);

    ctrl = control_init();
    if(ctrl == NULL)
    {
	quit_if(ERROR_FAIL);
    }

    pp = pp_init();
    if(pp == NULL)
    {
	quit_if(ERROR_FAIL);
    }

    retval = pp_new_setpoint(pp, x, w);
    quit_if(retval);

    retval = control_update_K(ctrl, pp, MASA_DEFAULT);
    quit_log_if(retval, "Failed to update control matrix! Aborting...");

    for(;;)
    {
	retval = uquad_mat_load(x,file);
	if(retval != ERROR_OK)
	{
	    quit_log_if(retval, "End of log?");
	}
	#warning "w_hover should use mot_control.h!!"

	retval = pp_update_setpoint(pp, x, w_hover, &ctrl_outdated);
	quit_if(retval);

	if(ctrl_outdated)
	{
	    retval = control_update_K(ctrl, pp, MASA_DEFAULT);
	    quit_log_if(retval, "Failed to update control matrix! Aborting...");
	    retval = control_dump(ctrl, NULL);
	    quit_log_if(retval, "Failed to dump new control matrix! Aborting...");
	}
	retval = control(ctrl, w, x, pp->sp, TS_DEFAULT_US);
	quit_if(retval);
	ctrl_outdated = false;
    }
    // Never gets here
    quit();

}