Example #1
0
int server_init(void)
{
	int fd = -1;

	signal(SIGPIPE, SIG_IGN);
	signal(SIGTERM, cleanup_all);
	
	FD_ZERO(&rfds);

	sock_map_init();

	
	/* initialize the rcp message handle */
	init_msg_pack_handle();
	init_msg_header();
	init_cmd_process_handle();

	

	fd = tcp_server_socket_create();
	add_fd(TCP_SERVER, fd, NULL); 


	if(pow_init() < 0)
	{
		printf("pow init failed\n");
		exit(1);
	}
	

	return 0;
}
Example #2
0
/*
 * Main routine for power server.
 */
int
main(int argc, char *argv[])
{
    static struct msg msg;
    const struct msg_map *map;
    object_t obj;
    struct bind_msg bm;
    object_t execobj, procobj;
    int error;

    sys_log("Starting power server\n");

    /* Boost thread priority. */
    thread_setpri(thread_self(), PRI_POW);

    /*
     * Wait until all required system servers
     * become available.
     */
    wait_server("!proc", &procobj);
    wait_server("!exec", &execobj);

    /*
     * Request to bind a new capabilities for us.
     */
    bm.hdr.code = EXEC_BINDCAP;
    strlcpy(bm.path, "/boot/pow", sizeof(bm.path));
    msg_send(execobj, &bm, sizeof(bm));

    /*
     * Register to process server
     */
    register_process();

    /*
     * Initialize power service.
     */
    pow_init();

    /*
     * Create an object to expose our service.
     */
    error = object_create("!pow", &obj);
    if (error)
        sys_panic("fail to create object");

    /*
     * Message loop
     */
    for (;;) {
        /*
         * Wait for an incoming request.
         */
        error = msg_receive(obj, &msg, sizeof(msg));
        if (error)
            continue;

        DPRINTF(("pow: msg code=%x task=%x\n",
                 msg.hdr.code, msg.hdr.task));


        /* Check client's capability. */
        if (task_chkcap(msg.hdr.task, CAP_POWERMGMT) != 0) {
            map = NULL;
            error = EPERM;
        } else {
            error = EINVAL;
            map = &powermsg_map[0];
            while (map->code != 0) {
                if (map->code == msg.hdr.code) {
                    error = (*map->func)(&msg);
                    break;
                }
                map++;
            }
        }
        /*
         * Reply to the client.
         */
        msg.hdr.status = error;
        msg_reply(obj, &msg, sizeof(msg));
#ifdef DEBUG_POWER
        if (map != NULL && error != 0)
            DPRINTF(("pow: msg code=%x error=%d\n",
                     map->code, error));
#endif
    }
}