int game_init() { srand(get_ms()); screen = set_videomode(); init_res(); game_start(); /* Should not reach here! */ assert(0); return 0; }
static void function_toggle_videomode(int x, int y) { videomode_e newmode; ki_printf("g_videomode was %d\n",get_videomode()); switch(get_videomode()) { case KEGS_FULL: newmode = KEGS_640X480; break; case KEGS_640X480: newmode = KEGS_640X400; break; case KEGS_640X400: newmode = KEGS_FULL; break; } set_videomode(newmode); }
static int init(const char* target) { init_early(); set_hostname(); set_kblayout(); set_videomode(); prepare_block_devices(); load_fstab(); if ( atexit(mountpoints_unmount) != 0 ) fatal("atexit: %m"); mountpoints_mount(false); sigset_t oldset, sigttou; sigemptyset(&sigttou); sigaddset(&sigttou, SIGTTOU); int result; while ( true ) { struct termios tio; if ( tcgetattr(0, &tio) ) fatal("tcgetattr: %m"); pid_t child_pid = fork(); if ( child_pid < 0 ) fatal("fork: %m"); if ( !child_pid ) { uid_t uid = getuid(); pid_t pid = getpid(); pid_t ppid = getppid(); if ( setpgid(0, 0) < 0 ) fatal("setpgid: %m"); sigprocmask(SIG_BLOCK, &sigttou, &oldset); if ( tcsetpgrp(0, pid) < 0 ) fatal("tcsetpgrp: %m"); sigprocmask(SIG_SETMASK, &oldset, NULL); struct passwd* pwd = getpwuid(uid); if ( !pwd ) fatal("looking up user by uid %" PRIuUID ": %m", uid); const char* home = pwd->pw_dir[0] ? pwd->pw_dir : "/"; const char* shell = pwd->pw_shell[0] ? pwd->pw_shell : "sh"; char ppid_str[sizeof(pid_t) * 3]; snprintf(ppid_str, sizeof(ppid_str), "%" PRIiPID, ppid); if ( setenv("INIT_PID", ppid_str, 1) < 0 || setenv("LOGNAME", pwd->pw_name, 1) < 0 || setenv("USER", pwd->pw_name, 1) < 0 || setenv("HOME", home, 1) < 0 || setenv("SHELL", shell, 1) < 0 ) fatal("setenv: %m"); if ( chdir(home) < 0 ) warning("chdir: %s: %m", home); const char* program = "login"; bool activate_terminal = false; if ( !strcmp(target, "single-user") ) { activate_terminal = true; program = shell; } if ( !strcmp(target, "sysinstall") ) { activate_terminal = true; program = "sysinstall"; } if ( !strcmp(target, "sysupgrade") ) { program = "sysupgrade"; activate_terminal = true; } if ( activate_terminal ) { tio.c_cflag |= CREAD; if ( tcsetattr(0, TCSANOW, &tio) ) fatal("tcgetattr: %m"); } const char* argv[] = { program, NULL }; execvp(program, (char* const*) argv); fatal("%s: %m", program); } int status; if ( waitpid(child_pid, &status, 0) < 0 ) fatal("waitpid"); sigprocmask(SIG_BLOCK, &sigttou, &oldset); if ( tcsetattr(0, TCSAFLUSH, &tio) ) fatal("tcgetattr: %m"); if ( tcsetpgrp(0, getpgid(0)) < 0 ) fatal("tcsetpgrp: %m"); sigprocmask(SIG_SETMASK, &oldset, NULL); const char* back = ": Trying to bring it back up again"; if ( WIFEXITED(status) ) { result = WEXITSTATUS(status); break; } else if ( WIFSIGNALED(status) ) note("session: %s%s", strsignal(WTERMSIG(status)), back); else note("session: Unexpected unusual termination%s", back); } mountpoints_unmount(); return result; }