/**
 * @brief Dequeues a command element.
 *
 * @retval    NRF_SUCCESS    on success, else an error code indicating reason for failure.
 */
static uint32_t cmd_queue_dequeue(void)
{
    uint32_t retval;
    retval = NRF_SUCCESS;

    // If any flash operation is enqueued, schedule.
    if (m_cmd_queue.count > 0)
    {
        retval = cmd_process();
        if (retval != NRF_SUCCESS)
        {
            // Flash could be accessed by modules other than Bond Manager, hence a busy error is
            // acceptable, but any other error needs to be indicated to the bond manager.
            if (retval != NRF_ERROR_BUSY)
            {
                app_notify(retval);
            }
            else
            {
                // In case of busy next trigger will be a success or a failure event.
            }
        }
    }
    else
    {
        // No flash access request pending.
    }

    return retval;
}
Example #2
0
static int cmd_video_start(struct re_printf *pf, void *arg)
{
	char *video_path;
	char *preview_path;

	struct re_printf pf_preview;

	(void)arg;

	if (!pf || !pf->arg) {
		return EINVAL;
	}

	/* Parse incoming arguments. */
	video_path = strtok((char *)pf->arg, " \r\n");
	preview_path = strtok(NULL, " \r\n");

	if (!video_path) {
		video_path = (char *)pf->arg;
	}

	pf_preview.arg = preview_path;

	/* Make preview. */
	cmd_process(NULL, 'o', &pf_preview);

	/* Start video recording. */
	internal_video_start(video_path);

	debug("Start video recording: %s\n", video_path);
	debug("Video preview: %s\n", preview_path);

	return 0;
}
Example #3
0
/**
 * @brief Dequeues a command element.
 *
 * @retval    NRF_SUCCESS    on success, else an error code indicating reason for failure.
 */
static uint32_t cmd_queue_dequeue(void)
{
    uint32_t retval;
    retval = NRF_SUCCESS;

    // If any flash operation is enqueued, schedule.
    if ((m_cmd_queue.count > 0) && (m_cmd_queue.flash_access == false))
    {
        retval = cmd_process();
        if (retval != NRF_SUCCESS)
        {
            // Flash could be accessed by modules other than Bond Manager, hence a busy error is
            // acceptable, but any other error needs to be indicated to the bond manager.
            if (retval == NRF_ERROR_BUSY)
            {
                // In case of busy error code, it is possible to attempt to access flash.
                retval = NRF_SUCCESS;
            }
        }
    }
    else
    {
        // No flash access request pending.
    }

    return retval;
}
Example #4
0
void cmd_receive_byte(uint8_t character)
{
	static uint8_t lineIdx;

	uart_write( &character, sizeof(character) );

	if (character == 0x8 )
	{
		if(lineIdx>0)
			lineIdx--;
	}
	else if (character == '\n')
	{
	}
	else if (character == '\r')
	{
		// Line completed
		DEBUG("\r\n");
		cmd_line[lineIdx] = '\0';
		cmd_process((char*)cmd_line);
		strcpy_P(cmd_line, PSTR("\r\nroot@plc:~> "));
		cmd_flush();
		lineIdx=0;
		cmd_line[lineIdx] = '\0';
	}
	else if (character == '\0')
	{
		io_toggle_red_led();
	}
	else
	{
		cmd_line[lineIdx] = character;
		lineIdx++;
	}
}
int main(int argc, char *argv[])
{
    HTEST *hTest = NULL;
    OMX_STRING component = NULL;
    OMX_STRING dump_file = NULL;

    if(argc < 2) {
        printf("Usage: ./bin <dump_file>\n");
        return 0;
    }
    
    OMX_Init();
    component = "OMX.Freescale.std.video_source.v4l.sw-based";
    dump_file = argv[1];
    hTest = create_test(component, dump_file);
    hTest->media_name = argv[1];
    if(hTest == NULL) {
        printf("Create test failed.\n");
        return 0;
    }
            
    load_component(hTest);
    StateTrans(hTest, (OMX_STATETYPE)2);
    StateTrans(hTest, (OMX_STATETYPE)3);
    cmd_process(hTest);
    delete_test(hTest);
    OMX_Deinit();

    return 1;
}
Example #6
0
File: ui.c Project: QXIP/baresip
int ui_input_pl(struct re_printf *pf, const struct pl *pl)
{
	struct cmd_ctx *ctx = NULL;
	size_t i;
	int err = 0;

	if (!pf || !pl)
		return EINVAL;

	for (i=0; i<pl->l; i++) {
		err |= cmd_process(&ctx, pl->p[i], pf);
	}

	if (pl->l > 1 && ctx)
		err |= cmd_process(&ctx, '\n', pf);

	return err;
}
Example #7
0
static void console_task(void *p)
{
	char buf[100];

	kprintf("dooloo# ");

	while(1)
	{
		if(getline(buf, 100))
			cmd_process(buf);
		kprintf("dooloo# ");
	}
}
Example #8
0
static int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	ulong cycles = 0;
	int retval = 0;
	int repeatable;

	if (argc == 1)
		return CMD_RET_USAGE;

	retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles);
	report_time(cycles);

	return retval;
}
Example #9
0
/**
 * Read
 */
void CommandsSession::do_read()
{
    auto self(shared_from_this());
    boost::asio::async_read_until(*m_connection->socket, m_read_buffer, END_SYMBOLS,
        [this, self](boost::system::error_code ec, std::size_t length) {
            if (!ec) {
                m_read_msg = std::string(
                        boost::asio::buffers_begin(m_read_buffer.data()),
                        boost::asio::buffers_end(m_read_buffer.data()) - strlen(END_SYMBOLS));

                m_read_buffer.consume(length);
                cmd_process();
            }
        });
}
int main(int argc, char *argv[])
{
	HTEST *hTest = NULL;
	OMX_STRING component = NULL;
	OMX_STRING in_file = NULL, out_file = NULL;
	FORMAT fmt;

	if(argc < 4)
	{
		printf("Unit test of vpu component.\n");
		printf("This test read data from in_file then store the decoded data to out_file.\n");
		printf("Usage: ./bin <in_file> <out_file> <format>\n");
		printf("format: 0 -- mpeg4\n");
		printf("        1 -- h264\n");
		return 0;
	}

	OMX_Init();
	component = "OMX.Freescale.std.video_decoder.avc.v3.hw-based";
	in_file = argv[1];
	out_file = argv[2];
	fmt = (FORMAT) atoi(argv[3]);
	hTest = create_test(component, in_file, out_file, fmt);
	if(hTest == NULL)
	{
		printf("Create test failed.\n");
		return 0;
	}

#if 1
	load_component(hTest);
	StateTrans(hTest, OMX_StateIdle);
	StateTrans(hTest, OMX_StateExecuting);
	wait_eos(hTest);
	StateTrans(hTest, OMX_StateIdle);
	StateTrans(hTest, OMX_StateLoaded);
	unload_component(hTest);
#else
	cmd_process(hTest);
#endif

	delete_test(hTest);
	OMX_Deinit();

	printf("Vpu component test is done.\n");

	return 1;
}
Example #11
0
/* Called when a command is invoked */
TEE_Result TA_InvokeCommandEntryPoint(void *pSessionContext,
				      uint32_t nCommandID, uint32_t nParamTypes,
				      TEE_Param pParams[4])
{
	(void)pSessionContext;

	switch (nCommandID) {
	case TA_SHA_PERF_CMD_PREPARE_OP:
		return cmd_prepare_op(nParamTypes, pParams);

	case TA_SHA_PERF_CMD_PROCESS:
		return cmd_process(nParamTypes, pParams);

	default:
		return TEE_ERROR_BAD_PARAMETERS;
	}
}
Example #12
0
/**
 * @brief Routine to enqueue a flash access operation.
 *
 * @param[in] opcode         Identifies operation requested to be enqueued.
 * @param[in] p_storage_addr Identiifes module and flash address on which operation is requested.
 * @param[in] p_data_addr    Identifies data address for flash access.
 * @param[in] size           Size in bytes of data requested for the access operation.
 * @param[in] offset         Offset within the flash memory block at which operation is requested.
 *
 * @retval    NRF_SUCCESS    on success, else an error code indicating reason for failure.
 *
 * @note All paramater check should be performed before requesting in an enqueue.
 */
static uint32_t cmd_queue_enqueue(uint8_t             opcode,
                                  pstorage_handle_t * p_storage_addr,
                                  uint8_t           * p_data_addr,
                                  pstorage_size_t     size,
                                  pstorage_size_t     offset)
{
    uint32_t retval;
    uint8_t  write_index = 0;

    if (m_cmd_queue.count != PSTORAGE_CMD_QUEUE_SIZE)
    {
        // Enqueue the command if it is queue is not full.
        write_index = m_cmd_queue.rp + m_cmd_queue.count;

        if (write_index >= PSTORAGE_CMD_QUEUE_SIZE)
        {
            write_index -= PSTORAGE_CMD_QUEUE_SIZE;
        }

        m_cmd_queue.cmd[write_index].op_code      = opcode;
        m_cmd_queue.cmd[write_index].n_tries      = 0;
        m_cmd_queue.cmd[write_index].p_data_addr  = p_data_addr;
        m_cmd_queue.cmd[write_index].storage_addr = (*p_storage_addr);
        m_cmd_queue.cmd[write_index].size         = size;
        m_cmd_queue.cmd[write_index].offset       = offset;
        retval                                    = NRF_SUCCESS;
        if (m_cmd_queue.flash_access == false)
        {
            retval = cmd_process();
            if (retval == NRF_ERROR_BUSY)
            {
                // In case of busy error code, it is possible to attempt to access flash.
                retval = NRF_SUCCESS;
            }
        }
        m_cmd_queue.count++;
    }
    else
    {
        retval = NRF_ERROR_NO_MEM;
    }

    return retval;
}
Example #13
0
int main(int argc, char **argv)
{
	char buff[MAX_BUFF], result_buff[SEND_BUFF]; // array for 'converted command(input)', 'result (output)'
	int n;				
	int server_fd, conn_fd;						 // socket discriptor for server and client
	int clilen;									// client struct's size
	struct sockaddr_in srvaddr, cliaddr;		// socket address struct
	

	if(argc != 2)  // if wrong input case
	{
		write(STDOUT_FILENO, "Server error : Check Port Numver\n", strlen("Server error : Check Port Numver\n"));
		return -1;
	}

	/* open socket */
	if((server_fd = socket(PF_INET, SOCK_STREAM,0)) < 0)
	{	
		write(STDERR_FILENO, "Server : socket() err!!\n", strlen("Server : socket() err!!\n"));
		return -1;
	}		
	
	/* initialize server socket struct */
	memset(&srvaddr, 0, sizeof(srvaddr));
	srvaddr.sin_family= PF_INET;
	srvaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
	srvaddr.sin_port = htons(atoi(argv[1]));
	
	//bind socket with address
	if(bind(server_fd, (struct sockaddr*)&srvaddr, sizeof(srvaddr)) < 0)
	{
		write(STDERR_FILENO, "Server : bind() err!!\n", strlen("Server : bind() err!!\n"));
		return -1;//exit(1);
	}



	// listen	(5 time)
	if(listen(server_fd, 5) < 0)
	{
		write(STDERR_FILENO, "Server : listen() err!!\n", strlen("Server : listen() err!!\n"));
		return -1;

	}



	for(;;)
	{

		clilen = sizeof(cliaddr);
		/* accept client's connection */
		conn_fd = accept(server_fd, (struct sockaddr* ) &cliaddr, &clilen);
		if(conn_fd < 0)  // connection falied case
		{
			write(STDERR_FILENO, "Server : accept() err!!\n", strlen("Server : accept() err!!\n"));
			return -1;
		}
		/*display client ip and port*/
		if(client_info(&cliaddr) < 0)
		{
			write(STDERR_FILENO,"Server : client_info() err!!\n", strlen("Server : client_info() err!!\n"));
			return -1;
		}

		while(1)
		{
			n = read(conn_fd, buff, MAX_BUFF);
			buff[n] = '\0';
			
			if(cmd_process(buff, result_buff) < 0)
			/*command execute and result*/
			{
				write(STDERR_FILENO, "Server : cmd_process() err!!\n", strlen("Server : cmd_process() err!!\n"));
				break;
			}
			/* send result to client */
			write(conn_fd, result_buff, strlen(result_buff));
			
			/* if converted command is QUIT*/
			if(!strcmp(result_buff, "QUIT"))
			{
				write(STDOUT_FILENO, "Server Quit!!\n", strlen("Server Quit!!\n"));
				break;
			}
		}
		if(!strcmp(result_buff, "QUIT")) // break loop
			break;

	}
	close(server_fd); // close server socket
	return 0;
}
int main(int argc, char *argv[])
{
	HTEST *hTest = NULL;

	if(argc < 3)
	{
		printf("Usage: ./bin <in_file> <out_file>\n");
		return 0;
	}

	hTest = (HTEST*)fsl_osal_malloc_new(sizeof(HTEST));
	if(hTest == NULL)
	{
		printf("Failed to allocate memory for test handle.\n");
		return 0;
	}
	fsl_osal_memset(hTest, 0, sizeof(HTEST));

	hTest->nComponents = 2;

	hTest->lib_name[0] = "../lib/lib_omx_template_arm11_elinux.so";
	hTest->itf_name[0] = "TemplateInit";
	hTest->component[0].nPorts = 2;
	hTest->component[0].PortDir[0] = OMX_DirInput;
	hTest->component[0].bAllocater[0] = OMX_TRUE;
	hTest->component[0].PortDir[1] = OMX_DirOutput;
	hTest->component[0].bAllocater[1] = OMX_TRUE;

	hTest->lib_name[1] = "../lib/lib_omx_template_arm11_elinux.so";
	hTest->itf_name[1] = "TemplateInit";
	hTest->component[1].nPorts = 2;
	hTest->component[1].PortDir[0] = OMX_DirInput;
	hTest->component[1].bAllocater[0] = OMX_TRUE;
	hTest->component[1].PortDir[1] = OMX_DirOutput;
	hTest->component[1].bAllocater[1] = OMX_TRUE;

	hTest->pMsgQ = FSL_NEW(Queue, ());
	if(hTest->pMsgQ == NULL)
	{
		printf("Create message queue failed.\n");
		return 0;
	}
	hTest->pMsgQ->Create(128, sizeof(MSG), E_FSL_OSAL_TRUE);

	hTest->pInFile = fopen(argv[1], "rb");
	if(hTest->pInFile == NULL)
	{
		printf("Failed to open file: %s\n", argv[1]);
		return 0;
	}

	hTest->pOutFile = fopen(argv[2], "wb");
	if(hTest->pOutFile == NULL)
	{
		printf("Failed to open file: %s\n", argv[2]);
		return 0;
	}

	cmd_process(hTest);

	return 1;
}
Example #15
0
/****************************************************************************
 * returns:
 *	1  - command executed, repeatable
 *	0  - command executed but not repeatable, interrupted commands are
 *	     always considered not repeatable
 *	-1 - not executed (unrecognized, bootd recursion or too many args)
 *           (If cmd is NULL or "" or longer than CONFIG_SYS_CBSIZE-1 it is
 *           considered unrecognized)
 *
 * WARNING:
 *
 * We must create a temporary copy of the command since the command we get
 * may be the result from getenv(), which returns a pointer directly to
 * the environment data, which may change magicly when the command we run
 * creates or modifies environment variables (like "bootp" does).
 */
static int builtin_run_command(const char *cmd, int flag)
{
	char cmdbuf[CONFIG_SYS_CBSIZE];	/* working copy of cmd		*/
	char *token;			/* start of token in cmdbuf	*/
	char *sep;			/* end of token (separator) in cmdbuf */
	char finaltoken[CONFIG_SYS_CBSIZE];
	char *str = cmdbuf;
	char *argv[CONFIG_SYS_MAXARGS + 1];	/* NULL terminated	*/
	int argc, inquotes;
	int repeatable = 1;
	int rc = 0;

	debug_parser("[RUN_COMMAND] cmd[%p]=\"", cmd);
	if (DEBUG_PARSER) {
		/* use printf - string may be loooong */
		printf(cmd ? cmd : "NULL");
		printf("\"\n");
	}
	//clear_ctrlc();		/* forget any previous Control C */

	if (!cmd || !*cmd) {
		return -1;	/* empty command */
	}

	if (strlen(cmd) >= CONFIG_SYS_CBSIZE) {
		printf ("## Command too long!\n");
		return -1;
	}

	strcpy (cmdbuf, cmd);

	/* Process separators and check for invalid
	 * repeatable commands
	 */

	debug_parser("[PROCESS_SEPARATORS] %s\n", cmd);
	while (*str) {

		/*
		 * Find separator, or string end
		 * Allow simple escape of ';' by writing "\;"
		 */
		for (inquotes = 0, sep = str; *sep; sep++) {
			if ((*sep=='\'') &&
			    (*(sep-1) != '\\'))
				inquotes=!inquotes;

			if (!inquotes &&
			    (*sep == ';') &&	/* separator		*/
			    ( sep != str) &&	/* past string start	*/
			    (*(sep-1) != '\\'))	/* and NOT escaped	*/
				break;
		}

		/*
		 * Limit the token to data between separators
		 */
		token = str;
		if (*sep) {
			str = sep + 1;	/* start of command for next pass */
			*sep = '\0';
		}
		else
			str = sep;	/* no more commands for next pass */
		debug_parser("token: \"%s\"\n", token);

		/* find macros in this token and replace them */
		process_macros (token, finaltoken);

		/* Extract arguments */
		if ((argc = parse_line (finaltoken, argv)) == 0) {
			rc = -1;	/* no command at all */
			continue;
		}

		if (cmd_process(flag, argc, argv, &repeatable, NULL))
			rc = -1;

		/* Did the user stop this? */
		//if (had_ctrlc ())
		//	return -1;	/* if stopped then not repeatable */
	}

	return rc ? rc : repeatable;
}
Example #16
0
/**
 * @brief Handles Flash Access Result Events declared in pstorage_platform.h.
 *
 * @param[in] sys_evt System event to be handled.
 */
void pstorage_sys_event_handler(uint32_t sys_evt)
{
    uint32_t retval = NRF_SUCCESS;

    // Its possible the flash access was not initiated by bond manager, hence
    // event is processed only if the event triggered was for an operation requested by the
    // bond manager.
    if (m_cmd_queue.flash_access == true)
    {
        cmd_queue_element_t * p_cmd;

        m_cmd_queue.flash_access = false;

        if (m_swap_state == STATE_SWAP_DIRTY)
        {
            if (sys_evt == NRF_EVT_FLASH_OPERATION_SUCCESS)
            {
                m_swap_state = STATE_INIT;
            }
            else
            {
                // If clearing the swap fails, set the application back to un-initialized, to give
                // the application a chance for a retry.
                m_module_initialized = false;
            }

            // Schedule any queued flash access operations.
            retval = cmd_queue_dequeue();
            if (retval != NRF_SUCCESS)
            {
                app_notify(retval, &m_cmd_queue.cmd[m_cmd_queue.rp]);
            }
            return;
        }

        switch (sys_evt)
        {
            case NRF_EVT_FLASH_OPERATION_SUCCESS:
            {
                p_cmd = &m_cmd_queue.cmd[m_cmd_queue.rp];
                m_round_val++;

                const bool store_finished =
                    ((p_cmd->op_code == PSTORAGE_STORE_OP_CODE) &&
                     ((m_round_val * SOC_MAX_WRITE_SIZE) >= p_cmd->size));

                const bool update_finished =
                    ((p_cmd->op_code == PSTORAGE_UPDATE_OP_CODE) &&
                     (m_swap_state == STATE_COMPLETE));

                const bool clear_block_finished =
                    ((p_cmd->op_code == PSTORAGE_CLEAR_OP_CODE) &&
                     (m_swap_state == STATE_COMPLETE));

                const bool clear_all_finished =
                    ((p_cmd->op_code == PSTORAGE_CLEAR_OP_CODE) &&
                     ((m_round_val * SOC_MAX_WRITE_SIZE) >= p_cmd->size) &&
                     (m_swap_state == STATE_INIT));

                if (update_finished ||
                    clear_block_finished ||
                    clear_all_finished ||
                    store_finished)
                {
                    uint8_t queue_rp = m_cmd_queue.rp;

                    m_swap_state = STATE_INIT;

                    m_round_val = 0;
                    m_cmd_queue.count--;
                    m_cmd_queue.rp++;

                    if (m_cmd_queue.rp >= PSTORAGE_CMD_QUEUE_SIZE)
                    {
                        m_cmd_queue.rp -= PSTORAGE_CMD_QUEUE_SIZE;
                    }

                    app_notify(retval, &m_cmd_queue.cmd[queue_rp]);

                    // Initialize/free the element as it is now processed.
                    cmd_queue_element_init(queue_rp);
                }
                // Schedule any queued flash access operations.
                retval = cmd_queue_dequeue();

                if (retval != NRF_SUCCESS)
                {
                    app_notify(retval, &m_cmd_queue.cmd[m_cmd_queue.rp]);
                }
            }
            break;

            case NRF_EVT_FLASH_OPERATION_ERROR:
                // Current command timed out and was not started in SoftDevice.
                p_cmd = &m_cmd_queue.cmd[m_cmd_queue.rp];

                ASSERT(p_cmd->n_tries < SD_CMD_MAX_TRIES);
                if (++p_cmd->n_tries == SD_CMD_MAX_TRIES)
                {
                    // If we have already attempted SD_CMD_MAX_TRIES times, give up.
                    app_notify(NRF_ERROR_TIMEOUT, &m_cmd_queue.cmd[m_cmd_queue.rp]);
                }
                else
                {
                    // Retry operation
                    retval = cmd_process();
                    if (retval != NRF_SUCCESS && retval != NRF_ERROR_BUSY)
                    {
                        app_notify(retval, p_cmd);
                    }
                }
                break;

            default:
                // No implementation needed.
                break;

        }
    }
}
Example #17
0
File: ui.c Project: QXIP/baresip
static void ui_handler(char key, struct re_printf *pf)
{
	(void)cmd_process(&uictx, key, pf);
}
Example #18
0
int main(int argc, char *argv[])
{
	int timeout = 0;
	sp_error error;
	int notify_cmdline = 0;
	int notify_events = 0;
	struct timespec ts;
	
	(void)argc;
	(void)argv;

	pthread_mutex_init(&g_notify_mutex, NULL);
	pthread_cond_init(&g_notify_cond, NULL);
	session_init();
	cmd_init(cmd_notify);
	
	do {
		clock_gettime(CLOCK_REALTIME, &ts);
		ts.tv_sec += timeout / 1000;
		ts.tv_nsec += (timeout % 1000) * 1E6;
		if (ts.tv_nsec > 1E9) {
			ts.tv_sec++;
			ts.tv_nsec -= 1E9;
		}

		pthread_mutex_lock(&g_notify_mutex);
		pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts);
		notify_cmdline = g_notify_cmdline;
		notify_events = g_notify_events;
		g_notify_cmdline = 0;
		g_notify_events = 0;
		pthread_mutex_unlock(&g_notify_mutex);
		if (notify_cmdline) {
			cmd_process();
		}

		if (notify_events) {
			do {
				error = sp_session_process_events(g_session, &timeout);
				if (error != SP_ERROR_OK)
					fprintf(stderr, "error processing events: %s\n",
							sp_error_message(error));
			} while (timeout == 0);
		}

	} while (!is_program_finished());

	session_logout();
	while (session_is_logged_in()) {
       		clock_gettime(CLOCK_REALTIME, &ts);
		ts.tv_sec += 1;

		pthread_mutex_lock(&g_notify_mutex);
		pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts);
		notify_events = g_notify_events;
		g_notify_events = 0;
		pthread_mutex_unlock(&g_notify_mutex);
		if (notify_events) {
			do {
				error = sp_session_process_events(g_session, &timeout);
				if (error != SP_ERROR_OK)
					fprintf(stderr, "error processing events: %s\n",
							sp_error_message(error));
			} while (timeout == 0);
		}
	}

	session_release();
	cmd_destroy();

	pthread_mutex_destroy(&g_notify_mutex);
	pthread_cond_destroy(&g_notify_cond);

	return 0;

}
Example #19
0
void CLI_Process(void) {
	key_get_command(str);
	str_upper_to_lower(str);
	cmd_process(str);

}
Example #20
0
int
silly_socket_poll()
{
        int err;
        sp_event_t *e;
        struct socket *s;
        struct silly_socket *ss = SSOCKET;
        eventwait(ss);
        err = cmd_process(ss);
        if (err < 0)
                return -1;
        if (err >= 1)
                clear_socket_event(ss);
        while (ss->eventindex < ss->eventcount) {
                int ei = ss->eventindex++;
                e = &ss->eventbuff[ei];
                s = (struct socket *)SP_UD(e);
                if (s == NULL)                  //the socket event has be cleared
                        continue;
                switch (s->type) {
                case STYPE_LISTEN:
                        assert(SP_READ(e));
                        report_accept(ss, s);
                        continue;
                case STYPE_CONNECTING:
                        s->type = STYPE_SOCKET;
                        report_connected(ss, s);
                        continue;
                case STYPE_RESERVE:
                        fprintf(stderr, "[socket] poll reserve socket\n");
                        continue;
                case STYPE_HALFCLOSE:
                case STYPE_SOCKET:
                case STYPE_UDPBIND:
                        break;
                case STYPE_CTRL:
                        continue;
                default:
                        fprintf(stderr, "[socket] poll: unkonw socket type:%d\n", s->type);
                        continue;
                }

                if (SP_ERR(e)) {
                        report_close(ss, s, 0);
                        delsocket(ss, s);
                        continue;
                }
                if (SP_READ(e)) {
                        switch (s->protocol) {
                        case PROTOCOL_TCP:
                                err = forward_msg_tcp(ss, s);
                                break;
                        case PROTOCOL_UDP:
                                err = forward_msg_udp(ss, s);
                                break;
                        default:
                                fprintf(stderr, "[socket] poll: unsupport protocol:%d\n", s->protocol);
                                continue;
                        }
                        //this socket have already occurs error, so ignore the write event
                        if (err < 0)
                                continue;
                }
                if (SP_WRITE(e)) {
                        if (s->protocol == PROTOCOL_TCP)
                                send_msg_tcp(ss, s);
                        else
                                send_msg_udp(ss, s);
                }
        }
        return 0;
}
Example #21
0
/* run_pipe_real() starts all the jobs, but doesn't wait for anything
 * to finish.  See checkjobs().
 *
 * return code is normally -1, when the caller has to wait for children
 * to finish to determine the exit status of the pipe.  If the pipe
 * is a simple builtin command, however, the action is done by the
 * time run_pipe_real returns, and the exit code is provided as the
 * return value.
 *
 * The input of the pipe is always stdin, the output is always
 * stdout.  The outpipe[] mechanism in BusyBox-0.48 lash is bogus,
 * because it tries to avoid running the command substitution in
 * subshell, when that is in fact necessary.  The subshell process
 * now has its stdout directed to the input of the appropriate pipe,
 * so this routine is noticeably simpler.
 */
static int run_pipe_real(struct pipe *pi)
{
	int i;
	int nextin;
	int flag = do_repeat ? CMD_FLAG_REPEAT : 0;
	struct child_prog *child;
	char *p;
#if __GNUC__
	/* Avoid longjmp clobbering */
	(void) &i;
	(void) &nextin;
	(void) &child;
#endif


	nextin = 0;

	/* Check if this is a simple builtin (not part of a pipe).
	 * Builtins within pipes have to fork anyway, and are handled in
	 * pseudo_exec.  "echo foo | read bar" doesn't work on bash, either.
	 */
	if (pi->num_progs == 1) child = & (pi->progs[0]);
		if (pi->num_progs == 1 && child->group) {
		int rcode;
		debug_printf("non-subshell grouping\n");
		rcode = run_list_real(child->group);
		return rcode;
	} else if (pi->num_progs == 1 && pi->progs[0].argv != NULL) {
		for (i=0; is_assignment(child->argv[i]); i++) { /* nothing */ }
		if (i!=0 && child->argv[i]==NULL) {
			/* assignments, but no command: set the local environment */
			for (i=0; child->argv[i]!=NULL; i++) {

				/* Ok, this case is tricky.  We have to decide if this is a
				 * local variable, or an already exported variable.  If it is
				 * already exported, we have to export the new value.  If it is
				 * not exported, we need only set this as a local variable.
				 * This junk is all to decide whether or not to export this
				 * variable. */
				int export_me=0;
				char *name, *value;
				name = xstrdup(child->argv[i]);
				debug_printf("Local environment set: %s\n", name);
				value = strchr(name, '=');
				if (value)
					*value=0;
				free(name);
				p = insert_var_value(child->argv[i]);
				set_local_var(p, export_me);
				if (p != child->argv[i]) free(p);
			}
			return EXIT_SUCCESS;   /* don't worry about errors in set_local_var() yet */
		}
		for (i = 0; is_assignment(child->argv[i]); i++) {
			p = insert_var_value(child->argv[i]);

			set_local_var(p, 0);

			if (p != child->argv[i]) {
				child->sp--;
				free(p);
			}
		}
		if (child->sp) {
			char * str = NULL;

			str = make_string((child->argv + i));
			parse_string_outer(str, FLAG_EXIT_FROM_LOOP | FLAG_REPARSING);
			free(str);
			return last_return_code;
		}

		/* check ";", because ,example , argv consist from
		 * "help;flinfo" must not execute
		 */
		if (strchr(child->argv[i], ';')) {
			printf("Unknown command '%s' - try 'help' or use "
					"'run' command\n", child->argv[i]);
			return -1;
		}
		/* Process the command */
		return cmd_process(flag, child->argc, child->argv,
				   &flag_repeat, NULL);
	}
	return -1;
}
Example #22
0
int main ( int argc, char * argv [] )
{
	
	cmd_defaults(&cmd,argv[0]);
	
	init_error();
		
	if(!is_path_absolute(argv[0])) {
		wrn_print("Require execution with absolute path(%s)",argv[0]);
		terminate();
	}		
	
	cmd_process(argc,argv,&cmd);	
	
	if(!cmd.no_dump_config)
		dump_cmd(&cmd);
//	if( check_creds(&cmd.creds) == -1 )
//		wrn_print("check_creds failed, program execution compromised");
		
	if( cmd.kill_running || cmd.rexec_running) {
		// dbg_print("Sending %s signal",strsignal(cmd.rexec_running ? SIGHUP : cmd.kill_running ? SIGTERM : 0));
		KILL_FROM_PID_ERRORS(kill_from_pid_file(cmd.pid_file, cmd.rexec_running ? SIGHUP : SIGTERM));
		exit(EXIT_SUCCESS);
	}

	
	if(cmd.logs_enable)
		if(reopen_files() == -1) {
			wrn_print("reopen_files failed");
			terminate();
		}
		
	dbg_print("%s started executinon", argv[0]);
	dbg_print("Running as uid:%ld gid:%ld", (long)getuid(), (long)getgid());
	
	if(cmd.need_daemon) {
		dbg_print("Demonizing..");
		if(become_daemon()) {
			wrn_print("Can't demonize because of error");
			terminate();
		}
	} 
	if(cmd.pid_file) {	
		switch (create_pid_file(cmd.pid_file)) {
	        case -1: 
			wrn_print("creat_pid_file failed");
			terminate();
		case -2:
			wrn_print("An instance of %s is already running",cmd.path);
			exit(EXIT_SUCCESS);		

		}
	}	
	
	if(cmd.exit_after_dump) 
		exit(EXIT_SUCCESS);
		
	block_all_sigs();
	
	main_loop();
	
	wrn_print("suspicious main_loop return...");
	exit(EXIT_FAILURE);
}
Example #23
0
/***********************************************************************
 *
 * Function: boot_manager
 *
 * Purpose: Handle boot configuation and options
 *
 * Processing:
 *     See function.
 *
 * Parameters:
 *     allow_boot : TRUE to allow the system to autoboot
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void boot_manager(BOOL_32 allow_boot) {
	UNS_8 key, str[255];
	int i, idx;
	UNS_32 secsmt;
	BOOL_32 usedef = FALSE;

	/* Get runtime configuration */
	get_rt_s1lsys_cfg(&sysinfo.sysrtcfg);

	/* Query FLASH */
	sysinfo.nandgeom = flash_init();

	/* Get S1L configuration */
	if (cfg_override() != FALSE)
	{
		cfg_default(&syscfg);
		usedef = TRUE;
	}
	else if (cfg_load(&syscfg) == FALSE)
	{
		cfg_default(&syscfg);
		syscfg.scr.number_entries = 0;
		cfg_save(&syscfg);
		usedef = TRUE;
	}

	/* Initial system setup */
	sys_up();

	if (sysinfo.nandgeom == NULL)
	{
		term_dat_out_crlf(nanderr_msg);
	}

	/* Set saved baud rate */
	term_setbaud(syscfg.baudrate);

	/* Default configuration used? */
	if (usedef != FALSE)
	{
		term_dat_out_crlf(cfggdef_msg);
	}

	/* Display system header */
	term_dat_out_crlf((UNS_8 *) "");
	term_dat_out_crlf(sysinfo.sysrtcfg.system_name);
	term_dat_out(bdat_msg);
	term_dat_out((UNS_8 *) __DATE__);
	term_dat_out((UNS_8 *) " ");
	term_dat_out_crlf((UNS_8 *) __TIME__);

	/* No file currently loaded in memory */
	sysinfo.lfile.loadaddr = 0xFFFFFFFF;
	sysinfo.lfile.flt = FLT_NONE;
	sysinfo.lfile.num_bytes = 0;
	sysinfo.lfile.startaddr = (PFV) 0xFFFFFFFF;
	sysinfo.lfile.loaded = FALSE;

	/* Initialize commands */
	cmd_core_add_commands();
	cmd_image_add_commands();
	cmd_nand_add_commands();
	ucmd_init();

	/* Initialize line prompt and parser */
	key_line_init(syscfg.prmpt);

	/* Prompt usually appears */
	menuexit = FALSE;

	/* Use built in script capability? */
	if ((syscfg.scr.enabled == TRUE) && (syscfg.scr.number_entries > 0)) {
		term_dat_out_crlf((UNS_8 *) "Running built-in script...\n");

		i = idx = 0;
		while (i < syscfg.scr.number_entries) {
			/* Execute commands */
			term_dat_out((UNS_8 *) "-S>");
			term_dat_out_crlf(&syscfg.scr.script_data[idx]);
			cmd_process(&syscfg.scr.script_data[idx]);
			idx = idx + syscfg.scr.entry_size[i] + 1;
			i++;
		}
	}
	else {
		/* In prompt bypass mode? */
		if (syscfg.aboot.abootsrc != SRC_NONE)
			menuexit = allow_boot;

		if ((syscfg.prmpt_to > 0) && (menuexit == TRUE))
		{
			secsmt = get_seconds() + syscfg.prmpt_to;
			term_dat_out_crlf(kp_msg);
			while (get_seconds() < secsmt)
			{
				if (term_dat_in_ready() > 0) {
					term_dat_in(&key, 1);
					menuexit = FALSE;
					secsmt = get_seconds();
				}
			}
		}

		/* Perform autoboot if possible */
		if (menuexit == TRUE) 
		{
			menuexit = autoboot();
		}
	}

	while (menuexit == FALSE) {
		key_get_command(str);
		str_upper_to_lower(str);
		cmd_process(str);
	}

	/* Bring down some system items */
	sys_down();

	/* Execute program */
	jumptoprog(sysinfo.lfile.startaddr);
}