/* * getout() * * Quit the program * * Precondition: input is not null * Postcondition: Program exits * * @param char* input The input character */ void getout(char* input) { int count; if(input != NULL) { if(!my_strcmp(input, "\n")) { restore_terminal(); for(count = 0; count < gl_env.nbelems; count++) { if(gl_env.elements[count].mode) { my_str(gl_env.elements[count].elem); my_str(" "); } } my_char('\n'); exit(0); } else if(!my_strcmp(input, "\E")) { restore_terminal(); exit(0); } } }
void abort_handler(int signal) { static char crashed = FALSE; if (crashed) { exit(-1); } crashed = TRUE; restore_terminal(); clean_screen(gtd->ses); dump_stack(); fflush(NULL); exit(-1); if (gtd->ses->connect_retry > utime()) { gtd->ses->connect_retry = 0; } else if (HAS_BIT(gtd->ses->telopts, TELOPT_FLAG_SGA) && !HAS_BIT(gtd->ses->telopts, TELOPT_FLAG_ECHO)) { socket_printf(gtd->ses, 1, "%c", 3); } else { do_zap(gtd->ses, ""); } }
void pipe_handler(int signal) { restore_terminal(); clean_screen(gtd->ses); tintin_printf(NULL, "broken_pipe: dumping stack"); dump_stack(); }
/* * Exit from window mode */ void to_exit(int last) { if (in_screen) { if (last) { clearmsg(); refresh(); } cookterm(); endwin(); restore_terminal(); /* some curses are buggy */ } }
void check_char(char *c) { if(!my_strcmp(c, (char *) SPACE)) doselect(); else if(!my_strcmp(c, gl_env.left)) moveleft(); else if(!my_strcmp(c, gl_env.right)) moveright(); else if(!my_strcmp(c, gl_env.up)) moveup(); else if(!my_strcmp(c, gl_env.down)) movedown(); else if(!my_strcmp(c, gl_env.esc) || !my_strcmp(c, (char *)ESC)) { restore_terminal(); getout(0); exit(1); } else if(!my_strcmp(c, (char *) ENTER)) { restore_terminal(); getout(1); } }
void suspend_handler(int signal) { printf("\033[r\033[%d;%dH", gtd->ses->rows, 1); fflush(stdout); restore_terminal(); kill(0, SIGSTOP); dirty_screen(gtd->ses); init_terminal(); tintin_puts(NULL, "#RETURNING BACK TO TINTIN++."); }
int main(int argc, char *argv[]) { char ch; signal(SIGINT, sigint); ctrl_c_hit = 0; setup_raw_input(); debug_init(); while (!ctrl_c_hit) { if (read(STDIN_FILENO, &ch, 1) == 1) process_debug_char(ch); } restore_terminal(); return 0; }
void quitmsg(char *message) { struct session *ses; SET_BIT(gtd->flags, TINTIN_FLAG_TERMINATE); while ((ses = gts->next) != NULL) { cleanup_session(ses); } if (gtd->chat) { close(gtd->chat->fd); } check_all_events(gts, SUB_ARG|SUB_SEC, 0, 0, "PROGRAM TERMINATION"); /* if (gtd->history_size) { char filename[BUFFER_SIZE]; sprintf(filename, "%s/%s", getenv("HOME"), HISTORY_FILE); history_write(gts, filename); } */ restore_terminal(); clean_screen(gts); if (message) { printf("\n%s\n", message); } printf("\nGoodbye from TinTin++\n\n"); fflush(NULL); exit(0); }
void trap_handler(int signal) { static char crashed = FALSE; if (crashed) { exit(-1); } crashed = TRUE; restore_terminal(); clean_screen(gtd->ses); dump_stack(); fflush(NULL); exit(-1); }
char* term_get_cap(char* termcap){ static char area[2048]; char* result = tgetstr(termcap, (char**) &area); if(!result){ if(!my_strcmp(termcap, CURSOROFF) || !my_strcmp(termcap, CURSORON)){ if(!my_strcmp(termcap, CURSOROFF)){ result = VICAP; }else{ result = VECAP; } }else{ my_str("Termcap "); my_str(termcap); my_str(" was not found\n"); restore_terminal(); exit(1); } } return result; }
static size_t read_into_buffer(struct terminal_input *inp, size_t len) { char *buf = inp->next.s + len; size_t nbytes = sizeof(inp->next.s) - len; int ret = check_stdin_ready(); memset(buf, '\0', nbytes); if (ret > 0) { ret = read(STDIN_FILENO, buf, nbytes - 1); if (ret == 0) { buf[0] = EOT; return 1; } } else if (ret == 0 && len > 0) { /* read even if stdin isn't ready if there's an incomplete * escape sequence in the buffer */ ret = read(STDIN_FILENO, buf, nbytes - 1); if (ret == 0) { /* append a null byte to the input buffer */ return 1; } } if (ret >= 0) { return ret; } if (errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK) { print_error("Error reading from stdin"); restore_terminal(); exit(EXIT_FAILURE); } return 0; }
int no_files() { my_str("No files matched input"); restore_terminal(); exit(1); }
int vlock_main(int argc, char **argv) { sigset_t sig; struct sigaction sa; struct vt_mode vtm; struct termios term; uid_t uid = getuid(); pw = getpwuid(uid); if (pw == NULL) bb_error_msg_and_die("unknown uid %d", uid); if (argc > 2) { bb_show_usage(); } o_lock_all = getopt32(argc, argv, "a"); vfd = xopen(CURRENT_TTY, O_RDWR); if (ioctl(vfd, VT_GETMODE, &vtm) < 0) { bb_perror_msg_and_die("VT_GETMODE"); } /* mask a bunch of signals */ sigprocmask(SIG_SETMASK, NULL, &sig); sigdelset(&sig, SIGUSR1); sigdelset(&sig, SIGUSR2); sigaddset(&sig, SIGTSTP); sigaddset(&sig, SIGTTIN); sigaddset(&sig, SIGTTOU); sigaddset(&sig, SIGHUP); sigaddset(&sig, SIGCHLD); sigaddset(&sig, SIGQUIT); sigaddset(&sig, SIGINT); sigemptyset(&(sa.sa_mask)); sa.sa_flags = SA_RESTART; sa.sa_handler = release_vt; sigaction(SIGUSR1, &sa, NULL); sa.sa_handler = acquire_vt; sigaction(SIGUSR2, &sa, NULL); /* need to handle some signals so that we don't get killed by them */ sa.sa_handler = SIG_IGN; sigaction(SIGHUP, &sa, NULL); sigaction(SIGQUIT, &sa, NULL); sigaction(SIGINT, &sa, NULL); sigaction(SIGTSTP, &sa, NULL); ovtm = vtm; vtm.mode = VT_PROCESS; vtm.relsig = SIGUSR1; vtm.acqsig = SIGUSR2; ioctl(vfd, VT_SETMODE, &vtm); tcgetattr(STDIN_FILENO, &oterm); term = oterm; term.c_iflag &= ~BRKINT; term.c_iflag |= IGNBRK; term.c_lflag &= ~ISIG; term.c_lflag &= ~(ECHO | ECHOCTL); tcsetattr(STDIN_FILENO, TCSANOW, &term); do { printf("Virtual Console%s locked by %s.\n", (o_lock_all) ? "s" : "", pw->pw_name); if (correct_password(pw)) { break; } bb_do_delay(FAIL_DELAY); puts("Password incorrect"); } while (1); restore_terminal(); fflush_stdout_and_exit(0); }
extern int vlock_main(int argc, char **argv) { sigset_t sig; struct sigaction sa; struct vt_mode vtm; int times = 0; struct termios term; if (argc > 2) { bb_show_usage(); } if (argc == 2) { if (strncmp(argv[1], "-a", 2)) { bb_show_usage(); } else { o_lock_all = 1; } } if ((pw = getpwuid(getuid())) == NULL) { bb_error_msg_and_die("no password for uid %d\n", getuid()); } #ifdef CONFIG_FEATURE_SHADOWPASSWDS if ((strcmp(pw->pw_passwd, "x") == 0) || (strcmp(pw->pw_passwd, "*") == 0)) { if ((spw = getspuid(getuid())) == NULL) { bb_error_msg_and_die("could not read shadow password for uid %d: %s\n", getuid(), strerror(errno)); } if (spw->sp_pwdp) { pw->pw_passwd = spw->sp_pwdp; } } #endif /* CONFIG_FEATURE_SHADOWPASSWDS */ if (pw->pw_passwd[0] == '!' || pw->pw_passwd[0] == '*') { bb_error_msg_and_die("Account disabled for uid %d\n", getuid()); } /* we no longer need root privs */ setuid(getuid()); setgid(getgid()); if ((vfd = open("/dev/tty", O_RDWR)) < 0) { bb_error_msg_and_die("/dev/tty"); }; if (ioctl(vfd, VT_GETMODE, &vtm) < 0) { bb_error_msg_and_die("/dev/tty"); }; /* mask a bunch of signals */ sigprocmask(SIG_SETMASK, NULL, &sig); sigdelset(&sig, SIGUSR1); sigdelset(&sig, SIGUSR2); sigaddset(&sig, SIGTSTP); sigaddset(&sig, SIGTTIN); sigaddset(&sig, SIGTTOU); sigaddset(&sig, SIGHUP); sigaddset(&sig, SIGCHLD); sigaddset(&sig, SIGQUIT); sigaddset(&sig, SIGINT); sigemptyset(&(sa.sa_mask)); sa.sa_flags = SA_RESTART; sa.sa_handler = release_vt; sigaction(SIGUSR1, &sa, NULL); sa.sa_handler = acquire_vt; sigaction(SIGUSR2, &sa, NULL); /* need to handle some signals so that we don't get killed by them */ sa.sa_handler = SIG_IGN; sigaction(SIGHUP, &sa, NULL); sigaction(SIGQUIT, &sa, NULL); sigaction(SIGINT, &sa, NULL); sigaction(SIGTSTP, &sa, NULL); ovtm = vtm; vtm.mode = VT_PROCESS; vtm.relsig = SIGUSR1; vtm.acqsig = SIGUSR2; ioctl(vfd, VT_SETMODE, &vtm); tcgetattr(STDIN_FILENO, &oterm); term = oterm; term.c_iflag &= ~BRKINT; term.c_iflag |= IGNBRK; term.c_lflag &= ~ISIG; term.c_lflag &= ~(ECHO | ECHOCTL); tcsetattr(STDIN_FILENO, TCSANOW, &term); do { char *pass, *crypt_pass; char prompt[100]; if (o_lock_all) { printf("All Virtual Consoles locked.\n"); } else { printf("This Virtual Console locked.\n"); } fflush(stdout); snprintf(prompt, 100, "%s's password: "******"getpass"); restore_terminal(); exit(1); } crypt_pass = pw_encrypt(pass, pw->pw_passwd); if (strncmp(crypt_pass, pw->pw_passwd, sizeof(crypt_pass)) == 0) { memset(pass, 0, strlen(pass)); memset(crypt_pass, 0, strlen(crypt_pass)); restore_terminal(); return 0; } memset(pass, 0, strlen(pass)); memset(crypt_pass, 0, strlen(crypt_pass)); if (isatty(STDIN_FILENO) == 0) { perror("isatty"); restore_terminal(); exit(1); } sleep(++times); printf("Password incorrect.\n"); if (times >= 3) { sleep(15); times = 2; } } while (1); }
int main(int argc, char **argv) { int greeting = TRUE; #ifdef SOCKS SOCKSinit(argv[0]); #endif if (signal(SIGTERM, trap_handler) == BADSIG) { syserr("signal SIGTERM"); } if (signal(SIGSEGV, trap_handler) == BADSIG) { syserr("signal SIGSEGV"); } if (signal(SIGHUP, trap_handler) == BADSIG) { syserr("signal SIGHUP"); } if (signal(SIGABRT, abort_handler) == BADSIG) { syserr("signal SIGTERM"); } if (signal(SIGINT, abort_handler) == BADSIG) { syserr("signal SIGINT"); } if (signal(SIGTSTP, suspend_handler) == BADSIG) { syserr("signal SIGSTOP"); } if (signal(SIGPIPE, pipe_handler) == BADSIG) { syserr("signal SIGPIPE"); } if (signal(SIGWINCH, winch_handler) == BADSIG) { syserr("signal SIGWINCH"); } /* if (getenv("HOME") != NULL) { char filename[256]; sprintf(filename, "%s/%s", getenv("HOME"), HISTORY_FILE); read_history(gts, filename); } */ srand(time(NULL)); if (argc > 1) { int c; while ((c = getopt(argc, argv, "e: G h r: s: t: v")) != EOF) { if (c == 'G') { greeting = FALSE; } } optind = 1; } init_tintin(greeting); if (argc > 1) { int c; optind = 1; while ((c = getopt(argc, argv, "e: G h r: s: t: v")) != EOF) { switch (c) { case 'e': gtd->ses = script_driver(gtd->ses, -1, optarg); break; case 'G': break; case 'h': tintin_printf(NULL, "Usage: %s [OPTION]... [FILE]...", argv[0]); tintin_printf(NULL, ""); tintin_printf(NULL, " -e Execute given command."); tintin_printf(NULL, " -G Don't show the greeting screen."); tintin_printf(NULL, " -h This help section."); tintin_printf(NULL, " -r Read given file."); tintin_printf(NULL, " -t Set given title."); tintin_printf(NULL, " -v Enable verbose mode."); restore_terminal(); exit(1); break; case 'r': gtd->ses = do_read(gtd->ses, optarg); break; case 't': printf("\033]0;%s\007", optarg); break; case 's': srand((unsigned int) atoll(optarg)); break; case 'v': do_configure(gtd->ses, "{VERBOSE} {ON}"); break; default: tintin_printf(NULL, "Unknown option '%c'.", c); break; } } if (argv[optind] != NULL) { gtd->ses = do_read(gtd->ses, argv[optind]); } } check_all_events(gts, SUB_ARG|SUB_SEC, 0, 2, "PROGRAM START", CLIENT_NAME, CLIENT_VERSION); check_all_events(gts, SUB_ARG|SUB_SEC, 0, 2, "SCREEN RESIZE", ntos(gts->cols), ntos(gts->rows)); mainloop(); return 0; }
static void cleanup_routines() { continue_register_notify(false); restore_terminal(); }