/* * init PC tty * this function must run after tty_init() */ void tty_pc_init() { bsp_isr_attach(KEYB_IRQ, isr_keyboard); bsp_irq_unmask(KEYB_IRQ); if(tty_register("ttypc", &sys_tty_ldisc_default, &tty_pc_driver) == 0) kprintf("tty 'ttypc' register failed\n"); if(tty_fw_open("ttypc", 0) == NULL) { kprintf("open tty 'ttypc' failed\n"); kprintf("tty 0 name: %s\n", systty[0].name); } }
int conf_parse_config(void) { int result; username = strdup(DEFUSER); hostname = strdup(DEFHOST); result = parse_conf(FINIT_CONF); if (!tty_num()) { char *fallback = FALLBACK_SHELL; if (console) fallback = console; tty_register(fallback); } return result; }
void parse_finit_conf(char *file) { FILE *fp; char line[LINE_SIZE]; char cmd[CMD_SIZE]; username = strdup(DEFUSER); hostname = strdup(DEFHOST); rcsd = strdup(FINIT_RCSD); if ((fp = fopen(file, "r")) != NULL) { char *x; const char *err = NULL; _d("Parse %s ...", file); while (!feof(fp)) { if (!fgets(line, sizeof(line), fp)) continue; chomp(line); _d("conf: %s", line); /* Skip comments. */ if (MATCH_CMD(line, "#", x)) continue; /* Do this before mounting / read-write * XXX: Move to plugin which checks /etc/fstab instead */ if (MATCH_CMD(line, "check ", x)) { char *dev = strip_line(x); strcpy(cmd, "/sbin/fsck -C -a "); strlcat(cmd, dev, sizeof(cmd)); run_interactive(cmd, "Checking file system %s", dev); continue; } if (MATCH_CMD(line, "user ", x)) { if (username) free(username); username = strdup(strip_line(x)); continue; } if (MATCH_CMD(line, "host ", x)) { if (hostname) free(hostname); hostname = strdup(strip_line(x)); continue; } if (MATCH_CMD(line, "module ", x)) { char *mod = strip_line(x); strcpy(cmd, "/sbin/modprobe "); strlcat(cmd, mod, sizeof(cmd)); run_interactive(cmd, "Loading kernel module %s", mod); continue; } if (MATCH_CMD(line, "mknod ", x)) { char *dev = strip_line(x); strcpy(cmd, "/bin/mknod "); strlcat(cmd, dev, sizeof(cmd)); run_interactive(cmd, "Creating device node %s", dev); continue; } if (MATCH_CMD(line, "network ", x)) { if (network) free(network); network = strdup(strip_line(x)); continue; } if (MATCH_CMD(line, "runparts ", x)) { if (rcsd) free(rcsd); rcsd = strdup(strip_line(x)); continue; } if (MATCH_CMD(line, "startx ", x)) { svc_register(SVC_CMD_SERVICE, strip_line(x), username); continue; } if (MATCH_CMD(line, "shutdown ", x)) { if (sdown) free(sdown); sdown = strdup(strip_line(x)); continue; } /* The desired runlevel to start when leaving * bootstrap (S). Finit supports 1-9, but most * systems only use 1-6, where 6 is reserved for * reboot */ if (MATCH_CMD(line, "runlevel ", x)) { char *token = strip_line(x); cfglevel = strtonum(token, 1, 9, &err); if (err) cfglevel = RUNLEVEL; if (cfglevel < 1 || cfglevel > 9 || cfglevel == 6) cfglevel = 2; /* Fallback */ continue; } /* Monitored daemon, will be respawned on exit, as * long as the (optional) service callback returns * non-zero */ if (MATCH_CMD(line, "service ", x)) { svc_register(SVC_CMD_SERVICE, x, NULL); continue; } /* One-shot task, will not be respawned. Only runs if * the (optional) service callback returns true */ if (MATCH_CMD(line, "task ", x)) { svc_register(SVC_CMD_TASK, x, NULL); continue; } /* Like task but waits for completion, useful w/ [S] */ if (MATCH_CMD(line, "run ", x)) { svc_register(SVC_CMD_RUN, x, NULL); continue; } if (MATCH_CMD(line, "console ", x)) { if (console) free(console); console = strdup(strip_line(x)); continue; } if (MATCH_CMD(line, "tty ", x)) { tty_register(strip_line(x)); continue; } } fclose(fp); } }
static void parse_static(char *line) { char *x; char cmd[CMD_SIZE]; /* Do this before mounting / read-write * XXX: Move to plugin which checks /etc/fstab instead */ if (MATCH_CMD(line, "check ", x)) { char *dev = strip_line(x); strcpy(cmd, "/sbin/fsck -C -a "); strlcat(cmd, dev, sizeof(cmd)); run_interactive(cmd, "Checking file system %s", dev); return; } if (MATCH_CMD(line, "user ", x)) { if (username) free(username); username = strdup(strip_line(x)); return; } if (MATCH_CMD(line, "host ", x)) { if (hostname) free(hostname); hostname = strdup(strip_line(x)); return; } if (MATCH_CMD(line, "module ", x)) { char *mod = strip_line(x); strcpy(cmd, "/sbin/modprobe "); strlcat(cmd, mod, sizeof(cmd)); run_interactive(cmd, "Loading kernel module %s", mod); return; } if (MATCH_CMD(line, "mknod ", x)) { char *dev = strip_line(x); strcpy(cmd, "/bin/mknod "); strlcat(cmd, dev, sizeof(cmd)); run_interactive(cmd, "Creating device node %s", dev); return; } if (MATCH_CMD(line, "network ", x)) { if (network) free(network); network = strdup(strip_line(x)); return; } if (MATCH_CMD(line, "runparts ", x)) { if (runparts) free(runparts); runparts = strdup(strip_line(x)); return; } if (MATCH_CMD(line, "include ", x)) { char *file = strip_line(x); strlcpy(cmd, file, sizeof(cmd)); if (!fexist(cmd)) { _e("Cannot find include file %s, absolute path required!", x); return; } parse_conf(cmd); return; } if (MATCH_CMD(line, "startx ", x)) { service_register(SVC_TYPE_SERVICE, strip_line(x), 0, username); return; } if (MATCH_CMD(line, "shutdown ", x)) { if (sdown) free(sdown); sdown = strdup(strip_line(x)); return; } /* The desired runlevel to start when leaving bootstrap (S). * Finit supports 1-9, but most systems only use 1-6, where * 6 is reserved for reboot */ if (MATCH_CMD(line, "runlevel ", x)) { char *token = strip_line(x); const char *err = NULL; cfglevel = strtonum(token, 1, 9, &err); if (err) cfglevel = RUNLEVEL; if (cfglevel < 1 || cfglevel > 9 || cfglevel == 6) cfglevel = 2; /* Fallback */ return; } /* TODO: Make console & tty dynamically loadable from /etc/finit.d */ if (MATCH_CMD(line, "console ", x)) { if (console) free(console); console = strdup(strip_line(x)); return; } /* TODO: Make console & tty dynamically loadable from /etc/finit.d */ if (MATCH_CMD(line, "tty ", x)) { tty_register(strip_line(x)); return; } }