Esempio n. 1
0
/*
 * Evaluate a command line that may contain multiple semicolon-delimited
 * commands.
 *
 * If "isargs" is set, we're doing command-line processing; print the
 * comamnds as we execute them and panic if the command is invalid or fails.
 */
static
void
menu_execute(char *line, int isargs)
{
	char *command;
	char *context;
	int result;

	for (command = strtok_r(line, ";", &context);
	     command != NULL;
	     command = strtok_r(NULL, ";", &context)) {

		if (isargs) {
			kprintf("OS/161 kernel: %s\n", command);
		}

		result = cmd_dispatch(command);
		if (result) {
			kprintf("Menu command failed: %s\n", strerror(result));
			if (isargs) {
				panic("Failure processing kernel arguments\n");
			}
		}
	}
}
Esempio n. 2
0
static void
cli_read_cb(int sd, short type, void *arg)
{
    struct cli *cli = arg;
    uint32_t cmdlen;
    uint8_t *msg = NULL;

    if (read_fully(sd, &cmdlen, sizeof(cmdlen)) != 0)
        goto error;

    msg = btpd_malloc(cmdlen);
    if (read_fully(sd, msg, cmdlen) != 0)
        goto error;

    if (!(benc_validate(msg, cmdlen) == 0 && benc_islst(msg) &&
            benc_first(msg) != NULL && benc_isstr(benc_first(msg))))
        goto error;

    if (cmd_dispatch(cli, msg) != 0)
        goto error;

    free(msg);
    return;

error:
    btpd_ev_del(&cli->read);
    close(cli->sd);
    free(cli);
    if (msg != NULL)
        free(msg);
}
Esempio n. 3
0
void *UI( void *ptr)
{
	char *buffer;
        size_t bufsize = 64;
        
        buffer = (char*) malloc(bufsize * sizeof(char));
        if (buffer == NULL) {
 		perror("malloc buffer failed");
 		exit(1);
	}
	
	printf("Welcome to AUbatch scheduler\n");
	printf("Please type h for help menu\n");
	printf("*******************************************************************\n");
	printf("HOW TO USE?\n");
	printf("Type \"run init <time> <\"1\">\"\n");
	printf("It allows user to choose how much time they need to give input arguments\n");
	printf("Choose policy and type it i.e. sjf or pri\n");
	printf("Submit jobs with \"run <Jobname><Burst_time><priority>\"\n");
	printf("Wait while the time you chose to add jobs finish\n");
	printf("Thank you, Happy scheduling>\n");
	printf("*******************************************************************\n");
      		while (1) {
		printf("> ");
		getline(&buffer, &bufsize, stdin);
		cmd_dispatch(buffer);
	}
}
Esempio n. 4
0
void k_docmd(const keyarg_u *arg, unsigned repeat, const int from_ch)
{
	const char **i;
	char **argv;
	size_t l;

	for(l = 0, i = arg->cmd.argv; i && *i; i++, l++);

	argv = umalloc((l + 1) * sizeof *argv);

	for(l = 0, i = arg->cmd.argv; i && *i; i++, l++)
		argv[l] = ustrdup(*i);

	cmd_dispatch(&arg->cmd.fn, 1, argv, arg->cmd.force, /*range:*/NULL);

	if(arg->cmd.argv[0])
		for(l = 0; argv[l]; l++)
			free(argv[l]);
	free(argv);
}
Esempio n. 5
0
void subprocess(int read_fd)
{
	//子进程
	char read_buf[512] = {0};
	int num = -1;
	int done = 1;
	do {
		memset(read_buf, 0, sizeof(read_buf));
		num = read(read_fd, read_buf, sizeof(read_buf));
		if (!strcmp(read_buf, "quit")) {
			done = 0;
		} else {
			//执行命令
			cmd_dispatch(read_buf, num);
		}

	} while(done);

	close(read_fd);//关闭读取通道

	exit(0);//关闭子进程
}
Esempio n. 6
0
/**
  Exec unparsed, first, tokenize
  then dispatch
 */
void cmd_exec_unparsed(char *l)
{
	char *vec[32];
        int c = tokenize(l, vec, 32);
        cmd_dispatch(c, vec);
}
Esempio n. 7
0
int main(int argc, char* argv[])
{
    ANSC_STATUS                     returnStatus       = ANSC_STATUS_SUCCESS;
    int                             cmdChar            = 0;
    BOOL                            bRunAsDaemon       = TRUE;
    int                             idx                = 0;
    char                            cmd[1024]          = {0};
    FILE                           *fd                 = NULL;
    DmErr_t                         err;
    char                            *subSys            = NULL;
    extern ANSC_HANDLE bus_handle;

    /*
     *  Load the start configuration
     */
    gpPnmStartCfg = (PCCSP_COMPONENT_CFG)AnscAllocateMemory(sizeof(CCSP_COMPONENT_CFG));
    
    if ( gpPnmStartCfg )
    {
        CcspComponentLoadCfg(CCSP_PNM_START_CFG_FILE, gpPnmStartCfg);
    }
    else
    {
        printf("Insufficient resources for start configuration, quit!\n");
        exit(1);
    }
    
    /* Set the global pComponentName */
    pComponentName = gpPnmStartCfg->ComponentName;

#if defined(_DEBUG) && defined(_COSA_SIM_)
    AnscSetTraceLevel(CCSP_TRACE_LEVEL_INFO);
#endif

    for (idx = 1; idx < argc; idx++)
    {
        if ( (strcmp(argv[idx], "-subsys") == 0) )
        {
            AnscCopyString(g_Subsystem, argv[idx+1]);
            CcspTraceWarning(("\nSubsystem is %s\n", g_Subsystem));
        }
        else if ( strcmp(argv[idx], "-c" ) == 0 )
        {
            bRunAsDaemon = FALSE;
        }
    }

#if  defined(_ANSC_WINDOWSNT)

    AnscStartupSocketWrapper(NULL);

    display_info();

    cmd_dispatch('e');

    while ( cmdChar != 'q' )
    {
        cmdChar = getchar();

        cmd_dispatch(cmdChar);
    }
#elif defined(_ANSC_LINUX)
    if ( bRunAsDaemon )
        daemonize();

    /*This is used for ccsp recovery manager */
    fd = fopen("/var/tmp/CcspPandMSsp.pid", "w+");
    if ( !fd )
    {
        CcspTraceWarning(("Create /var/tmp/CcspPandMSsp.pid error. \n"));
    }
    else
    {
        sprintf(cmd, "%d", getpid());
        fputs(cmd, fd);
        fclose(fd);
    }

    if (is_core_dump_opened())
    {
        signal(SIGUSR1, sig_handler);
        signal(SIGPIPE, SIG_IGN);
        CcspTraceWarning(("Core dump is opened, do not catch signal\n"));
    }
    else
    {
        CcspTraceWarning(("Core dump is NOT opened, backtrace if possible\n"));
        signal(SIGTERM, sig_handler);
        signal(SIGINT, sig_handler);
        signal(SIGUSR1, sig_handler);
        signal(SIGUSR2, sig_handler);

        signal(SIGSEGV, sig_handler);
        signal(SIGBUS, sig_handler);
        signal(SIGKILL, sig_handler);
        signal(SIGFPE, sig_handler);
        signal(SIGILL, sig_handler);
        signal(SIGQUIT, sig_handler);
        signal(SIGHUP, sig_handler);
        signal(SIGPIPE, SIG_IGN);
    }

    cmd_dispatch('e');

    // printf("Calling Docsis\n");

    // ICC_init();
    // DocsisIf_StartDocsisManager();

#ifdef _COSA_SIM_
    subSys = "";        /* PC simu use empty string as subsystem */
#else
    subSys = NULL;      /* use default sub-system */
#endif
    err = Cdm_Init(bus_handle, subSys, NULL, NULL, pComponentName);
    if (err != CCSP_SUCCESS)
    {
        fprintf(stderr, "Cdm_Init: %s\n", Cdm_StrError(err));
        exit(1);
    }

    system("touch /tmp/pam_initialized");

    printf("Entering P&M loop\n");

    if ( bRunAsDaemon )
    {
        while(1)
        {
            sleep(30);
        }
    }
    else
    {
        while ( cmdChar != 'q' )
        {
            cmdChar = getchar();

            cmd_dispatch(cmdChar);
        }
    }
#endif

    err = Cdm_Term();
    if (err != CCSP_SUCCESS)
    {
        fprintf(stderr, "Cdm_Term: %s\n", Cdm_StrError(err));
        exit(1);
    }

    if ( g_bActive )
    {
        ssp_cancel_pnm(gpPnmStartCfg);

        g_bActive = FALSE;
    }

    return 0;
}
Esempio n. 8
0
static
const motion *motion_read_or_visual(unsigned *repeat, bool apply_maps)
{
	window *win = windows_cur();
	if(win->ui_mode & UI_VISUAL_ANY){
		static motion visual = {
			.func = m_visual,
			.arg.phow = &visual.how
		};

		*repeat = 0;

		return &visual;
	}

	return motion_read(repeat, apply_maps);
}

void k_prompt_cmd(const keyarg_u *arg, unsigned repeat, const int from_ch)
{
	char *initial = NULL;
	char initial_buf[32];

	window *win = windows_cur();

	if(win->ui_mode & UI_VISUAL_ANY){
		int y1 = 1 + win->ui_pos->y;
		int y2 = 1 + window_uipos_alt(win)->y;

		if(y2 < y1){
			int tmp = y1;
			y1 = y2;
			y2 = tmp;
		}

		snprintf(initial_buf, sizeof initial_buf, "%d,%d", y1, y2);

		initial = initial_buf;
	}

	char *const cmd = prompt(from_ch, initial);

	if(!cmd)
		goto cancel_cmd;

	const cmd_t *cmd_f;
	char **argv;
	int argc;
	bool force;
	struct range rstore, *range = &rstore;

	if(parse_ranged_cmd(
			cmd,
			&cmd_f,
			&argv, &argc,
			&force, &range))
	{
		cmd_dispatch(cmd_f, argc, argv, force, range);
	}
	else
	{
		ui_err("unknown command %s", cmd);
	}

	free_argv(argv, argc);
cancel_cmd:
	free(cmd);
}