示例#1
0
int main (int argc, char *argv[])
{
  int listener;

  setup_signals();
  listener = open_listener(SOCK_PATH);

  /* Turn ourselves into a daemon, but do not redirect stdout/stderr
   * to /dev/null.
   */
  if (daemon(0, 1) != 0)
    {
      perror("daemon");
      exit(1);
    }

  /* Save our PID. */
  save_pid(PID_PATH);

  /* Clean up any stale lock file. */
  unlink(LOCK_PATH);

  /* Wait for clients. */
  wait_for_events(listener);

  /* Work is done.  Clean up our socket for next time. */
  close(listener);
  unlink(SOCK_PATH);
  unlink(PID_PATH);

  return 0;
}
uint32_t bootloader_dfu_start(void)
{
    uint32_t                err_code = NRF_SUCCESS;
    pstorage_module_param_t storage_params;

    storage_params.cb          = pstorage_callback_handler;
    storage_params.block_size  = sizeof(bootloader_settings_t);
    storage_params.block_count = 1;
    
    err_code = pstorage_init();
    if (err_code != NRF_SUCCESS)    
    {
        return err_code;
    }

    err_code = pstorage_register(&storage_params, &m_bootsettings_handle);
    if (err_code != NRF_SUCCESS)    
    {
        return err_code;
    }

    // Clear swap if banked update is used.    
    err_code = dfu_init(); 
    if (err_code != NRF_SUCCESS)    
    {
        return err_code;
    }
		  
    err_code = dfu_transport_update_start();

    wait_for_events();
    
    return err_code;
}
示例#3
0
文件: bootloader.c 项目: IOIOI/nRF51
uint32_t bootloader_dfu_ap_update_continue(void)
{
    uint32_t err_code = NRF_SUCCESS;
    const bootloader_settings_t * p_bootloader_settings;

    bootloader_util_settings_get(&p_bootloader_settings);

    /* Ignore update attempts on invalid src_image_address */
    if( (p_bootloader_settings->src_image_address == SRC_IMAGE_ADDRESS_EMPTY)   ||
        (p_bootloader_settings->src_image_address == SRC_IMAGE_ADDRESS_INVALID))
    {
        return NRF_SUCCESS;
    }

    if( (p_bootloader_settings->ap_image.st.bank == NEW_IMAGE_BANK_0)           ||
        (p_bootloader_settings->ap_image.st.bank == NEW_IMAGE_BANK_1))
    {
        /* If updating application only, we can start the copy right now*/
        if ((p_bootloader_settings->sd_image.st.size == NEW_IMAGE_SIZE_EMPTY)   &&
            (p_bootloader_settings->bl_image.st.size == NEW_IMAGE_SIZE_EMPTY))
        {
            err_code = dfu_ap_image_swap();

            dfu_update_status_t update_status = {DFU_UPDATE_AP_SWAPPED, };

            bootloader_dfu_update_process(update_status);

            wait_for_events();
        }
    }
   return err_code;
}
示例#4
0
文件: init.c 项目: WattTech/rtems
static void sync_with_helper(test_context *ctx)
{
  rtems_event_set events;

  send_event(ctx, H, REQ_WAKE_UP_HELPER);
  events = wait_for_events();
  rtems_test_assert(events == REQ_WAKE_UP_MASTER);
}
示例#5
0
  void kqueue_monitor::run()
  {
    initialize_kqueue();

    for(;;)
    {
#ifdef HAVE_CXX_MUTEX
      unique_lock<mutex> run_guard(run_mutex);
      if (should_stop) break;
      run_guard.unlock();
#endif

      // remove the deleted descriptors
      remove_deleted();

      // rescan the pending descriptors
      rescan_pending();

      // scan the root paths to check whether someone is missing
      scan_root_paths();

      vector<struct kevent> changes;
      vector<struct kevent> event_list;

      for (const pair<int, string>& fd_path : load->file_names_by_descriptor)
      {
        struct kevent change;

        EV_SET(&change,
               fd_path.first,
               EVFILT_VNODE,
               EV_ADD | EV_ENABLE | EV_CLEAR,
               NOTE_DELETE | NOTE_EXTEND | NOTE_RENAME | NOTE_WRITE | NOTE_ATTRIB | NOTE_LINK | NOTE_REVOKE,
               0,
               0);

        changes.push_back(change);
        struct kevent event;
        event_list.push_back(event);
      }

      /*
       * If no files can be observed yet, then wait and repeat the loop.
       */
      if (!changes.size())
      {
        sleep(latency);
        continue;
      }

      const int event_num = wait_for_events(changes, event_list);
      process_events(changes, event_list, event_num);
    }

    terminate_kqueue();
  }
uint32_t bootloader_dfu_sd_update_finalize(void)
{
    dfu_update_status_t update_status = {DFU_UPDATE_SD_SWAPPED, };

    bootloader_dfu_update_process(update_status);

    wait_for_events();

    return NRF_SUCCESS;
}
示例#7
0
文件: init.c 项目: WattTech/rtems
static void helper(rtems_task_argument arg)
{
  test_context *ctx = &test_instance;

  while (true) {
    rtems_event_set events = wait_for_events();
    rtems_test_assert(events == REQ_WAKE_UP_HELPER);
    send_event(ctx, M, REQ_WAKE_UP_MASTER);
  }
}
示例#8
0
文件: powerd.c 项目: ryo/netbsd-src
static struct kevent *
allocchange(void)
{

    if (nchanges == __arraycount(changebuf)) {
        (void)wait_for_events(NULL, 0);
        nchanges = 0;
    }

    return &changebuf[nchanges++];
}
示例#9
0
uint32_t bootloader_dfu_start(void)
{
    uint32_t err_code;

    // Clear swap if banked update is used.
    err_code = dfu_init(); 
    VERIFY_SUCCESS(err_code);

    err_code = dfu_transport_update_start();

    wait_for_events();

    return err_code;
}
示例#10
0
文件: bootloader.c 项目: IOIOI/nRF51
uint32_t bootloader_dfu_start(void)
{
    uint32_t                err_code = NRF_SUCCESS;

    err_code = dfu_init();
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    err_code = dfu_transport_update_start();

    wait_for_events();

    err_code = dfu_transport_close();

    return err_code;
}
示例#11
0
文件: init.c 项目: WattTech/rtems
static void worker(rtems_task_argument arg)
{
  test_context *ctx = &test_instance;
  task_id id = arg;

  while (true) {
    rtems_event_set events = wait_for_events();

    if ((events & REQ_MTX_OBTAIN) != 0) {
      obtain(ctx);
      ++ctx->generation[id];
    }

    if ((events & REQ_MTX_RELEASE) != 0) {
      release(ctx);
      ++ctx->generation[id];
    }
  }
}
示例#12
0
uint32_t dfu_transport_update_start()
{
    m_pkt_type = PKT_TYPE_INVALID;

    leds_init();
    // Initialize the S110 Stack.
    ble_stack_init();
    scheduler_init();
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();
    sec_params_init();
    radio_notification_init();
    advertising_start();
    
    wait_for_events();
    
    return NRF_SUCCESS;
}
示例#13
0
uint32_t bootloader_dfu_start(void)
{
    uint32_t err_code;

    // Clear swap if banked update is used.
    NRF_WDT->RR[0] = NRF_WDT_RR_VALUE;//kevin add 151225
#if DEBUG_BOOTLOADER_EN
  DbgPrintf_str("feed WDT\r\n"); 
#endif
    err_code = dfu_init(); 
    if (err_code != NRF_SUCCESS)    
    {
        return err_code;
    }
    err_code = dfu_transport_update_start();

    wait_for_events();

    return err_code;
}
示例#14
0
/*
 ****************************************************************
 *	Programa principal					*
 ****************************************************************
 */
int
main (int argc, const char *argv[])
{
	XStandardColormap stdcmap, *cmp;
	Display		*dpy = NULL;
	Window		root, win;
	XGCValues	gcv;
	int		depth;

	FILE		*fp;
	XImage		*ximage = NULL;
	IMAGE		*last_image, *ip, *old_ip;
	int		nimages, times;

	const char	*display = NOSTR;
	int		time_interval = 0;
	int		opt, exit_val = 0;
	int		Nflag = 0;

	Atom		map;
	KeySym		key;

	save_argc = argc;	save_argv = argv;

	/*
	 *	Analisa as opções de execução.
	 */
	while ((opt = getopt (argc, argv, "d:f:HMNRs:v")) != EOF)
	{
		switch (opt)
		{
		    case 'd':
			display = optarg;
			break;

		    case 'f':
			if (strchr (optarg, '/') != NOSTR)
			{
				int	num, den;

				sscanf (optarg, "%d/%d", &num, &den);

				if (num != 1 || den <= 0 || den > 8)
					msg ("$Fator redutivo inválido");

				default_factor = -den + 1;
			}
			else
			{
				sscanf (optarg, "%d", &default_factor);

				if (default_factor <= 0 || default_factor > 8)
					msg ("$Fator de ampliação inválido");

				default_factor--;
			}
			break;

		    case 'H':
			help (0);
			break;

		    case 'M':
			return (0);

		    case 'N':
			Nflag++;
			break;

		    case 'R':
			Rflag++;
			break;

		    case 's':
			time_interval = atol (optarg);

			if (time_interval < 1 || time_interval > 60)
			{
				msg ("Argumento inválido para opção '-s'");
				help (1);
			}

			break;

		    case 'v':
			vflag++;
			break;

		    default:
			putc ('\n', stderr);
			help (2);

		}	/* end switch (opt) */

	}	/* end while (analisando opções) */

	argv += optind;
	argc -= optind;

	/*
	 *	Consistência final das Opções.
	 */
	if (Nflag)
	{
		if (argc > 0 || *argv != NOSTR)
			msg ("$Com a opção '-N' NÃO podem ser dados nomes de arquivos");

		argv = read_args_from_stdin (&argc);
	}

	if (Rflag && time_interval > 0)
		msg ("$As opções '-R' e '-s' são incompatíveis");

	/*
	 *	Constrói a Tabela de Imagens.
	 */
	for (/* acima */; *argv != NULL; argv++)
	{
		if (ftw (*argv, add_image_to_table) < 0)
			msg ("$*Erro em \"ftw (%s)\"", *argv);
	}

	if ((nimages = next_image - images) <= 0)
		msg ("$Não foram encontrados arquivos contendo imagens");

	last_image = next_image - 1;

	if (Rflag && nimages > 1)
	{
		/* Escolhe aleatoriamente uma imagem */

		images += (time (NULL) % nimages); last_image = images;

		msg ("Imagem a a janela-mãe: \"%s\"", images->i_name);
	}

	/*
	 *	Abre a conexão com o servidor.
	 */
	if ((dpy = XOpenDisplay (display)) == NULL)
	{
		msg
		(	"$Não consegui conectar-me ao servidor \"%s\"",
			XDisplayName (display)
		);
	}

	screen = DefaultScreen (dpy);
	depth  = DefaultDepth (dpy, screen);
	root   = RootWindow (dpy, screen);

	/*
	 *	Obtém o mapa de cores de acordo com a profundidade.
	 */
	cmp = &stdcmap;

	map = (depth <= 8) ? XA_RGB_DEFAULT_MAP : XA_RGB_BEST_MAP;

	if (!XGetStandardColormap (dpy, root, cmp, map))
	{
		cmp = NULL;
		msg ("Mapa de cores padrão para profundidade %d não disponível", depth);
	}

	/*
	 *	Decide se cria ou não uma janela para exibir as imagens.
	 */
	win = Rflag ? root : create_window (dpy);

	gcv.foreground = WhitePixel (dpy, screen);
	gcv.background = BlackPixel (dpy, screen);

	gc = XCreateGC (dpy, win, GCForeground|GCBackground, &gcv);

	/*
	 *	Mostra as imagens.
	 */
	for (times = 0, old_ip = NOIMAGE, ip = images; ip != NOIMAGE; times++)
	{
		if (vflag && (times & 15) == 0 && nimages > 0)
		{
			printf ("\n NUM  FMT   LARG x  ALT   FATOR   CORES   TAMANHO  ARQUIVO\n");
			printf ("--------------------------------------------------------------\n");
		}

		if (old_ip != ip)
		{
			/* Abre o arquivo que contém a imagem */

			if ((fp = fdopen (inopen (ip->i_dev, ip->i_ino), "r")) == NOFILE)
			{
				msg ("*Não consegui abrir o arquivo \"%s\"", ip->i_name);
				exit_val++; break;
			}

			/* Lê a imagem para a memória */

			if ((ximage = (*ip->i_format->f_load) (fp, 1, dpy, cmp, ip)) == NULL)
			{
				msg ("Não consegui ler imagens do arquivo \"%s\"", ip->i_name);
				fclose (fp); exit_val++; break;
			}

			fclose (fp);

			/* Imprime, se necessário, algumas informações sobre a imagem */

			if (vflag)
			{
				char	factor[8];

				if (ip->i_factor >= 0)
					snprintf (factor, sizeof (factor), "%d",    ip->i_factor + 1);
				else
					snprintf (factor, sizeof (factor), "1/%d", -ip->i_factor + 1);

				printf
				(	"%4d  %s   %4d x %4d   %4s %8d  %8d  %s\n",
					ip - images + 1, ip->i_format->f_extension,
					ip->i_width,	 ip->i_height,  factor,
					ip->i_ncolors,	 ip->i_file_sz, ip->i_name
				);
			}

			/* Mostra a imagem como fundo da janela */

			if (draw_window (dpy, win, ximage, ip) < 0)
				break;

		}	/* end if (nova imagem) */

		/* Aguarda eventos e analisa o retorno */

		key = wait_for_events (dpy, win, time_interval);

		old_ip = ip;

		switch (key)
		{
		    case 'q':
		    case 'Q':
		    case XK_Escape:
			ip = NOIMAGE;		/* Fim do programa */
			break;

		    case XK_Up:
		    case XK_KP_Up:
			if (ip > images)
				ip--;		/* Retrocede uma imagem */
			break;

		    case XK_Down:
		    case XK_KP_Down:
			if (ip < last_image)
				ip++;		/* Avança uma imagem */
			elif (time_interval > 0)
				ip = images;	/* Volta ao início */
			break;

		    case XK_Home:
		    case XK_KP_Home:
			ip = images;		/* Volta ao início */
			break;

		    case XK_End:
		    case XK_KP_End:
			ip = last_image;	/* Vai para a última imagem */
			break;

		    case XK_Right:
		    case XK_KP_Right:
			ip->i_factor++;		/* Aumenta o fator */
			old_ip = NOIMAGE;
			break;

		    case XK_Left:		/* Diminui o fator */
		    case XK_KP_Left:
			ip->i_factor--;
			old_ip = NOIMAGE;
			break;

		    default:
			break;

		}	/* end switch (tecla retornada) */

		if (ip != old_ip)
			XDestroyImage (ximage);

	}	/* end for (percorrendo imagens) */

	XFreeGC (dpy, gc);

	XCloseDisplay (dpy);

	return (exit_val);

}	/* end main */
示例#15
0
文件: powerd.c 项目: ryo/netbsd-src
int
main(int argc, char *argv[])
{
    struct kevent *ev, events[16];
    struct power_type power_type;
    char *cp;
    int ch, fd;

    setprogname(*argv);

    if (prog_init && prog_init() == -1)
        err(1, "init failed");

    while ((ch = getopt(argc, argv, "dn")) != -1) {
        switch (ch) {
        case 'd':
            debug = 1;
            break;

        case 'n':
            no_scripts = 1;
            break;

        default:
            usage();
        }
    }
    argc -= optind;
    argv += optind;

    if (argc)
        usage();

    if (debug == 0) {
        (void)daemon(0, 0);

        openlog("powerd", LOG_PID | LOG_NOWAIT, LOG_DAEMON);
        (void)pidfile(NULL);
    }

    if ((kq = prog_kqueue()) == -1) {
        powerd_log(LOG_ERR, "kqueue: %s", strerror(errno));
        exit(EX_OSERR);
    }

    if ((fd = prog_open(_PATH_POWER, O_RDONLY|O_NONBLOCK, 0600)) == -1) {
        powerd_log(LOG_ERR, "open %s: %s", _PATH_POWER,
                   strerror(errno));
        exit(EX_OSERR);
    }

    if (prog_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
        powerd_log(LOG_ERR, "Cannot set close on exec in power fd: %s",
                   strerror(errno));
        exit(EX_OSERR);
    }

    if (prog_ioctl(fd, POWER_IOC_GET_TYPE, &power_type) == -1) {
        powerd_log(LOG_ERR, "POWER_IOC_GET_TYPE: %s", strerror(errno));
        exit(EX_OSERR);
    }

    (void)asprintf(&cp, "%s/%s", _PATH_POWERD_SCRIPTS,
                   power_type.power_type);
    if (cp == NULL) {
        powerd_log(LOG_ERR, "allocating script path: %s",
                   strerror(errno));
        exit(EX_OSERR);
    }
    script_paths[0] = cp;

    ev = allocchange();
    EV_SET(ev, fd, EVFILT_READ, EV_ADD | EV_ENABLE,
           0, 0, (intptr_t) dispatch_dev_power);

    for (;;) {
        void (*handler)(struct kevent *);
        int i, rv;

        rv = wait_for_events(events, __arraycount(events));
        for (i = 0; i < rv; i++) {
            handler = (void *) events[i].udata;
            (*handler)(&events[i]);
        }
    }
}