void vt_dev_init(void) { int i; if (VT_COUNT > 99) { kprintf("vt_dev_init(): error: too many vts requested!\n"); return; } if (!initialized) { vt_init(); } for (i = 0; i < VT_COUNT; ++i) { vt[i].std.name = vt[i].name; vt[i].std.dev_class = DEV_CLASS_OTHER; vt[i].std.dev_type = DEV_TYPE_VT; vt[i].std.devopen = (devopen_t) vt_open; vt[i].std.remove = (devrm_t) vt_remove; //kprintf("vt_init(): adding %s\n", vt[i].std.name); switch (device_insert(&vt[i].std)) { case 0: devices_not_removed_count++; break; case DEV_ERR_TOTAL_FAILURE: kprintf("vt_init(): unknown error inserting device %d\n", i); break; case DEV_ERR_BAD_NAME: kprintf("vt_init(): error inserting device %d: bad name\n", i); break; case DEV_ERR_EXISTS: kprintf("vt_init(): error inserting device %d: device exists\n", i); break; case DEV_ERR_BAD_STRUCT: kprintf("vt_init(): error inserting device %d: bad info struct\n", i); break; } } }
int main(int argc, char **argv) { int only_root, auth = 0, chpid; uid_t uid; userinfo_t *as, root, user; oldvt = oldsysrq = vt.nr = vt.fd = -1; vt.ios = NULL; root.name = "root"; parse_options(argc, argv); if (geteuid() != 0) { fprintf(stderr, "physlock: must be root!\n"); return 1; } setup_signal(SIGTERM, sa_handler_exit); setup_signal(SIGQUIT, sa_handler_exit); setup_signal(SIGHUP, SIG_IGN); setup_signal(SIGINT, SIG_IGN); setup_signal(SIGUSR1, SIG_IGN); setup_signal(SIGUSR2, SIG_IGN); vt_init(); get_current_vt(&oldvt); if (options->only_lock) { lock_vt_switch(); vt_destroy(); return 0; } else if (options->only_unlock) { unlock_vt_switch(); vt_destroy(); return 0; } if (options->disable_sysrq) { oldsysrq = get_sysrq_state(SYSRQ_PATH); if (oldsysrq > 0) set_sysrq_state(SYSRQ_PATH, 0); } if (options->user) { user.name = options->user; } else { uid = getuid(); get_uname(&user, uid); } get_pwhash(&root); only_root = strcmp(user.name, root.name) == 0; if (!only_root) { get_pwhash(&user); authenticate(&user, ""); /* test authentication */ } acquire_new_vt(&vt); lock_vt_switch(); secure_vt(&vt); if (options->detach) { chpid = fork(); if (chpid < 0) die("could not spawn background process: %s", strerror(errno)); else if (chpid > 0) return 0; else setsid(); } if (options->cmd) handle_cmd(1); while (!auth) { as = &root; flush_vt(&vt); if (!only_root) { tty_echo_on(&vt); while (1) { prompt(vt.ios, "\nUnlock as [%s/%s]: ", user.name, root.name); if (!*buf || !strcmp(buf, user.name)) { as = &user; break; } else if (!strcmp(buf, root.name)) { break; } } tty_echo_off(&vt); } else { prompt(vt.ios, "\nPress [Enter] to unlock.\n"); } prompt(vt.ios, "%s's password: "******"\nAuthentication failed\n"); sleep(AUTH_FAIL_TIMEOUT); } } if (options->crypt) add_passphrase(buf, options->fnek, vt.ios); if (options->cmd) handle_cmd(0); sleep(1); cleanup(); return 0; }
/* * Initialize screen and status line. */ void init_emul(int type, int do_init) { int x = -1, y = -1; char attr = 0; int maxy; int ypos; if (st) { mc_wclose(st, 1); tempst = 0; st = NULL; } if (us) { x = us->curx; y = us->cury; attr = us->attr; mc_wclose(us, 0); } /* See if we have space for a fixed status line */ maxy = LINES - 1; if ((use_status || LINES > 24) && P_STATLINE[0] == 'e') { if (use_status) { ypos = LINES; maxy = LINES - 1; } else { ypos = LINES - 1; maxy = LINES - 2; } st = mc_wopen(0, ypos, COLS - 1, ypos, BNONE, st_attr, sfcolor, sbcolor, 1, 0, 1); mc_wredraw(st, 1); } /* MARK updated 02/17/95 - Customizable size for history buffer */ num_hist_lines = atoi(P_HISTSIZE); if (num_hist_lines < 0) num_hist_lines = 0; if (num_hist_lines > 5000) num_hist_lines = 5000; /* Open a new main window, and define the configured history buffer size. */ us = mc_wopen(0, 0, COLS - 1, maxy, BNONE, XA_NORMAL, tfcolor, tbcolor, 1, num_hist_lines, 0); if (x >= 0) { mc_wlocate(us, x, y); mc_wsetattr(us, attr); } us->autocr = 0; us->wrap = wrapln; terminal = type; lines = LINES - (st != NULL); cols = COLS; /* Install and reset the terminal emulator. */ if (do_init) { vt_install(do_output, kb_handler, us); vt_init(type, tfcolor, tbcolor, us->wrap, addlf, addcr); } else vt_pinit(us, -1, -1); show_status(); }
/* * ESC was seen the last time. Process the next character. */ static void state1(term_t *win, int c) { short x, y, f; switch(c) { case '[': /* ESC [ */ esc_s = 2; return; case '(': /* ESC ( */ esc_s = 4; return; case ')': /* ESC ) */ esc_s = 5; return; case '#': /* ESC # */ esc_s = 6; return; case 'P': /* ESC P (DCS, Device Control String) */ esc_s = 7; return; case 'D': /* Cursor down */ case 'M': /* Cursor up */ x = win->cursor_x; if (c == 'D') { /* Down. */ y = win->cursor_y + 1; if (y == win->state.newy2 + 1) term_wscroll(win, S_UP); else if (win->cursor_y < win->H) term_wlocate(win, x, y); } if (c == 'M') { /* Up. */ y = win->cursor_y - 1; if (y == win->state.newy1 - 1) term_wscroll(win, S_DOWN); else if (y >= 0) term_wlocate(win, x, y); } break; case 'E': /* CR + NL */ term_wputs(win, (unsigned char *)"\r\n"); break; case '7': /* Save attributes and cursor position */ case 's': win->state.savex = win->cursor_x; win->state.savey = win->cursor_y; win->state.saveattr = win->attr; win->state.savecol = win->color; break; case '8': /* Restore them */ case 'u': win->color = win->state.savecol; /* HACK should use mc_wsetfgcol etc */ term_wsetattr(win, win->state.saveattr); term_wlocate(win, win->state.savex, win->state.savey); break; case '=': /* Keypad into applications mode */ win->state.vt_keypad = APPL; break; case '>': /* Keypad into numeric mode */ win->state.vt_keypad = NORMAL; break; case 'Z': /* Report terminal type */ if (win->state.vt_type == VT100) v_termout(win, "\033[?1;0c", 0); else v_termout(win, "\033[?c", 0); break; case 'c': /* Reset to initial state */ f = XA_NORMAL; term_wsetattr(win, f); win->wrap = (win->state.vt_type != VT100); if (win->state.vt_wrap != -1) win->wrap = win->state.vt_wrap; win->state.vt_crlf = win->state.vt_insert = 0; vt_init((struct term_t *)win, win->state.vt_type, win->state.vt_fg, win->state.vt_bg, win->wrap, 0); term_wlocate(win, 0, 0); break; case 'H': /* Set tab in current position */ x = win->cursor_x; if (x > 159) x = 159; win->state.vt_tabs[x / 32] |= 1 << (x % 32); break; case 'N': /* G2 character set for next character only*/ case 'O': /* G3 " " */ case '<': /* Exit vt52 mode */ default: /* ALL IGNORED */ break; } esc_s = 0; }
/* * ESC was seen the last time. Process the next character. */ static void state1(int c) { short x, y, f; switch(c) { case '[': /* ESC [ */ esc_s = 2; return; case '(': /* ESC ( */ esc_s = 4; return; case ')': /* ESC ) */ esc_s = 5; return; case '#': /* ESC # */ esc_s = 6; return; case 'P': /* ESC P (DCS, Device Control String) */ esc_s = 7; return; case 'D': /* Cursor down */ case 'M': /* Cursor up */ x = vt_win->curx; if (c == 'D') { /* Down. */ y = vt_win->cury + 1; if (y == newy2 + 1) mc_wscroll(vt_win, S_UP); else if (vt_win->cury < vt_win->ys) mc_wlocate(vt_win, x, y); } if (c == 'M') { /* Up. */ y = vt_win->cury - 1; if (y == newy1 - 1) mc_wscroll(vt_win, S_DOWN); else if (y >= 0) mc_wlocate(vt_win, x, y); } break; case 'E': /* CR + NL */ mc_wputs(vt_win, "\r\n"); break; case '7': /* Save attributes and cursor position */ case 's': savex = vt_win->curx; savey = vt_win->cury; saveattr = vt_win->attr; savecol = vt_win->color; #if TRANSLATE savecharset = vt_charset; savetrans[0] = vt_trans[0]; savetrans[1] = vt_trans[1]; #endif break; case '8': /* Restore them */ case 'u': #if TRANSLATE vt_charset = savecharset; vt_trans[0] = savetrans[0]; vt_trans[1] = savetrans[1]; #endif vt_win->color = savecol; /* HACK should use mc_wsetfgcol etc */ mc_wsetattr(vt_win, saveattr); mc_wlocate(vt_win, savex, savey); break; case '=': /* Keypad into applications mode */ vt_keypad = APPL; if (vt_keyb) (*vt_keyb)(vt_keypad, vt_cursor); break; case '>': /* Keypad into numeric mode */ vt_keypad = NORMAL; if (vt_keyb) (*vt_keyb)(vt_keypad, vt_cursor); break; case 'Z': /* Report terminal type */ if (vt_type == VT100) v_termout("\033[?1;0c", 0); else v_termout("\033[?c", 0); break; case 'c': /* Reset to initial state */ f = XA_NORMAL; mc_wsetattr(vt_win, f); vt_win->wrap = (vt_type != VT100); if (vt_wrap != -1) vt_win->wrap = vt_wrap; vt_crlf = vt_insert = 0; vt_init(vt_type, vt_fg, vt_bg, vt_win->wrap, 0, 0); mc_wlocate(vt_win, 0, 0); break; case 'H': /* Set tab in current position */ x = vt_win->curx; if (x > 159) x = 159; vt_tabs[x / 32] |= 1 << (x % 32); break; case 'N': /* G2 character set for next character only*/ case 'O': /* G3 " " */ case '<': /* Exit vt52 mode */ default: /* ALL IGNORED */ break; } esc_s = 0; }
int main(int argc, char **argv) { pthread_t sigth; sigset_t sigblock; int logflags = 0; int ret = 1; debug_init(); sigemptyset(&sigblock); sigaddset(&sigblock, SIGHUP); sigaddset(&sigblock, SIGINT); sigaddset(&sigblock, SIGTERM); #ifdef ENABLE_VT sigaddset(&sigblock, SIGPIPE); #endif pthread_sigmask(SIG_BLOCK, &sigblock, NULL); if (conf_parse(&conf, argc, argv)) return 1; if (conf.debug_level > 0) logflags = LOG_PERROR; openlog(basename(argv[0]), LOG_PID|logflags, LOG_DAEMON); syslog(LOG_INFO, "%s v%s started (%s)", PACKAGE_NAME, PACKAGE_VERSION, entity_string[conf.mip6_entity]); #ifdef ENABLE_VT if (vt_init() < 0) goto vt_failed; #endif /* if not debugging, detach from tty */ if (conf.debug_level == 0) daemon_start(1); else { /* if debugging with debug log file, detach from tty */ if (conf.debug_log_file) { daemon_start(1); ret = debug_open(conf.debug_log_file); if (ret < 0) { fprintf(stderr, "can't init debug log:%s\n", strerror(-ret)); goto debug_failed; } dbg("%s started in debug mode\n", PACKAGE_NAME); } else { dbg("%s started in debug mode, not detaching from terminal\n", PACKAGE_NAME); } conf_show(&conf); } srandom(time(NULL)); if (rr_cn_init() < 0) goto rr_cn_failed; if (policy_init() < 0) goto policy_failed; if (taskqueue_init() < 0) goto taskqueue_failed; if (bcache_init() < 0) goto bcache_failed; if (mh_init() < 0) goto mh_failed; if (icmp6_init() < 0) goto icmp6_failed; if (xfrm_init() < 0) goto xfrm_failed; cn_init(); if ((is_ha() || is_mn()) && tunnelctl_init() < 0) goto tunnelctl_failed; if (is_ha() && ha_init() < 0) goto ha_failed; if (is_mn() && mn_init() < 0) goto mn_failed; #ifdef ENABLE_VT if (vt_start(conf.vt_hostname, conf.vt_service) < 0) goto vt_start_failed; #endif if (pthread_create(&sigth, NULL, sigh, NULL)) goto sigth_failed; pthread_join(sigth, NULL); ret = 0; sigth_failed: #ifdef ENABLE_VT vt_fini(); vt_start_failed: #endif if (is_mn()) mn_cleanup(); mn_failed: if (is_ha()) ha_cleanup(); ha_failed: if (is_ha() || is_mn()) tunnelctl_cleanup(); tunnelctl_failed: cn_cleanup(); xfrm_cleanup(); xfrm_failed: icmp6_cleanup(); icmp6_failed: mh_cleanup(); mh_failed: bcache_cleanup(); bcache_failed: taskqueue_destroy(); taskqueue_failed: policy_cleanup(); policy_failed: rr_cn_failed: debug_close(); debug_failed: #ifdef ENABLE_VT vt_failed: #endif syslog(LOG_INFO, "%s v%s stopped (%s)", PACKAGE_NAME, PACKAGE_VERSION, entity_string[conf.mip6_entity]); closelog(); return ret; }
// Real entry point of the OS : void init() { unsigned int freq; interrupt_init(); earlyterm_init(); earlyterm_clear(); kbd_init(); rtc_init(); time_init(); earlyterm_write("Kernel initialization...\n"); set_kernel_print(&earlyterm_write); printk(LOG_INFO, "cmd args: '%s'\n", &cmdargs_begin); cmdline_parse(&cmdargs_begin, 1024); mmu_init(); pm_init_pages(); stimer_init(); hwkbd_start_periodic_update(); DBG_WAIT; interrupt_inhibit_all(0); // console initialisation as soon as possible dev_init(); // add TTY device (on major 4) ttydev_device.init(); dev_register_device(&ttydev_device, 4); // add virtual terminal TTYs vt_init(); // USB initialisation usb_init(); // add usb-acm TTY acm_usb_init(); DBG_WAIT; // will be the last message displayed on early console printk(LOG_INFO, "Switching screen to tty1...\n The display will be cleared.\n"); console_make_active(); // in all cases, Virtual Terminals should be made active (tty1) DBG_WAIT; vt_set_active(0); // need to be changed for "overclocking" : //freq_change(FREQ_STC_4, FREQ_DIV_1, FREQ_DIV_4); freq_time_calibrate(); freq = freq_get_internal_hz(); printk(LOG_INFO, "CPU freq : %d.%dMHz\n", freq/1000000, (freq/100000)%10); freq = freq_get_peripheral_hz(); printk(LOG_INFO, "Peripheral freq : %d.%dMHz\n", freq/1000000, (freq/100000)%10); // initialize sysctl tables ctl_init(); //test_keyboard_int(); //test_virtual_mem(); //asm volatile ("trapa #50"); //DBG_WAIT; // Initializing VFS and device sub-sytems, mount platform filesystems, // register platform devices... vfs_init(); vfs_file_init(); vfs_register_fs(&smemfs_file_system, VFS_REGISTER_STATIC); vfs_register_fs(&protofs_file_system, VFS_REGISTER_STATIC); vfs_mount("protofs", NULL, VFS_MOUNT_ROOT); vfs_create("/", "dev", INODE_TYPE_PARENT, INODE_FLAG_READ | INODE_FLAG_EXEC, 0); vfs_create("/dev", "tty1", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00040000); vfs_create("/dev", "tty2", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00040001); vfs_create("/dev", "serial", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00030000); vfs_create("/dev", "console", INODE_TYPE_DEV, INODE_FLAG_WRITE, console_get_device()); DBG_WAIT; // keyboard input for virtual terminals kbd_set_kstroke_handler(&vt_key_stroke); // mount additional filesystems vfs_create("/", "mnt", INODE_TYPE_PARENT, INODE_FLAG_WRITE, 0); vfs_create("/mnt", "smem", INODE_TYPE_PARENT, INODE_FLAG_WRITE, 0); vfs_mount("smemfs", "/mnt/smem", VFS_MOUNT_NORMAL); DBG_WAIT; // set /dev/display device _display_device.init(); dev_register_device(&_display_device, 0x20); vfs_create("/dev", "display", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00200001); // direct keyboard device on major 0x21 fxkeyboard_device.init(); dev_register_device(&fxkeyboard_device, 0x21); vfs_create("/dev", "keyboard", INODE_TYPE_DEV, INODE_FLAG_WRITE, 0x00210000); DBG_WAIT; //test_keymatrix(); // test_keyboard(); /*while(1) { char c; if(vfs_read(console, &c, 1) == 1) { vfs_write(console, &c, 1); } }*/ DBG_WAIT; //test_vfs(); //test_sdcard(); //test_sleep_funcs(); // EEPROM-related code commented to avoid useless write cycles ;) //test_eeprom(); /*char mybuf[128]; int len; len = usb_receive(USB_EP_ADDR_EP1OUT, mybuf, 10, 0); printk(LOG_DEBUG, "usb_receive ret=%d\n", len); if(len > 0) { mybuf[len] = '\0'; printk(LOG_DEBUG, "content = '%s'\n", mybuf); } while(!_magic_lock); set_kernel_print(&print_usb_ep2); test_vfs(); */ // memory area subsystem mem_area_init(); process_init(); sched_init(); test_process(); printk(LOG_WARNING, "End of init job, sleeping...\n"); while(1) printk(LOG_WARNING, "IER: 0x%x 0x%x\n", USB.IFR0.BYTE, USB.IFR1.BYTE); }