static void *run(void *data) { int fd; const struct shell *sh; struct fbcon *fbcon = (struct fbcon *) data; sh = shell_lookup("tish"); if (!sh) { return NULL; } close(0); close(1); close(2); idesc_init(&fbcon->idesc, &fbcon_idesc_ops, FS_MAY_READ | FS_MAY_WRITE); fd = index_descriptor_add(&fbcon->idesc); fbcon->vterm.tty.idesc = &fbcon->idesc; assert(fd == 0); dup2(fd, 1); dup2(fd, 2); shell_exec(sh, "login"); return NULL; }
int exec_call(void) { int ecode; struct task *task = task_self(); const char *path = task_resource_argv_path(task); const char *cmd_name = exec_cmd_name(path); const struct shell *sh = shell_lookup(cmd_name); int c; char **v; if (strcmp(cmd_name, path)) task_resource_argv_insert(task, cmd_name, 0); c = task_resource_argv_argc(task); v = task_resource_argv_argv(task); /* FIXME pass argv to shell_exec */ if (sh) { ecode = shell_run(sh); } else { const struct cmd *cmd; cmd = cmd_lookup(cmd_name); if (cmd) { task_self_module_ptr_set(cmd2mod(cmd)); ecode = cmd_exec(cmd, c, v); } else { ecode = ENOENT; } } return ecode; }
static int run_script(void) { const char *command; const struct shell *shell; shell = shell_lookup(OPTION_STRING_GET(shell_name)); if (NULL == shell) { shell = shell_any(); if (NULL == shell) { return -ENOENT; } } setup_tty(OPTION_STRING_GET(tty_dev)); printf("\nStarted shell [%s] on device [%s]\n", OPTION_STRING_GET(shell_name), OPTION_STRING_GET(tty_dev)); printf("loading start script:\n"); array_foreach(command, script_commands, ARRAY_SIZE(script_commands)) { int ret; printf("> %s \n", command); ret = shell_exec(shell, command); if (OPTION_GET(BOOLEAN,stop_on_error) && ret) { return ret; } }
int main(void){ init_system_io(); /* pull-up *Res* enable */ init_sys_uart(); /* init uart for printf */ spi_raw_init(); char buffer[32]; struct cmd_argv txdata; while(1) { putchar('>'); putchar(' '); char *cmd_line = buffer; if ((txdata.argc = read_cmd_line(cmd_line, sizeof(buffer))) <= 0) continue; const struct cmd_config *val; val = shell_lookup(cmd_line, strlen(cmd_line)); if (val != NULL) { txdata.argv = cmd_line; /* point to options */ int ret = (*(val->func))(&txdata); printf_P(PSTR("[I] Exec %s: %d\n"), cmd_line, ret); } else { printf_P(PSTR("[X] invalid cmd: %s\n"), cmd_line); } } return 0; }