int main(int ac, char **av) { t_env envir; char read_char[5]; t_list *list; int i; tab_zero(read_char); i = 1; list = NULL; if (ac > 1) { while (i < ac) { list = list_add_end(list, list_new(av[i])); i++; } i = 1; } init_shell(&envir); print_ft_list(list); wait_key(read_char, &list, &envir); restore_term(&envir); exit(EXIT_SUCCESS); return (0); }
void run(t_params const* params) { int fd; pid_t master; pid_t ptyfk; struct termios term; fd = open(params->file, O_WRONLY | O_CREAT | (params->append == 1 ? O_APPEND : O_TRUNC), 0644); if (fd == -1) xperror(); ptyfk = my_forkpty(&master, NULL); if (ptyfk == -1) xperror(); if (ptyfk == 0) { dup2_fd(master); execl(params->shell, params->shell, NULL); exit(0); } update_win_size(master); signal(SIGWINCH, handle_resize); remove_block(master, 0); init_term(&term); printf("Script started, file is %s\n", params->file); read_input(ptyfk, master, fd); restore_term(&term); close(fd); printf("Script done, file is %s\n", params->file); }
int do_redirections(t_pipe *list_pipe, int i, char **env, int is_redi) { int ret; ret = 0; if (list_pipe->cmd[i]->is_redi_left != 0) ret += do_redi_left(list_pipe, i, env); else if (is_redi == 1) { if (list_pipe->list_in[i] != -1) if ((dup2(list_pipe->list_in[i], 0)) == -1) return (puterror("error: dup2\n")); } if (list_pipe->cmd[i]->is_redi_right != 0) ret += do_redi_right(list_pipe, i); else if (is_redi == 1) { if (list_pipe->list_out[i] != -1) if ((dup2(list_pipe->list_out[i], 1)) == -1) return (puterror("error: dup2\n")); } restore_term(&term_attr); return (ret); }
void Keyboard::Close() { restore_term(); dbus_disconnect(); if (ThreadHandle()) { StopThread(); } }
void sigtstp_handler(t_data *data) { char cp[2]; cp[0] = data->term.c_cc[VSUSP]; cp[1] = 0; restore_term(data->old_term); signal(SIGTSTP, SIG_DFL); ioctl(0, TIOCSTI, cp); }
char *git_terminal_prompt(const char *prompt, int echo) { static struct strbuf buf = STRBUF_INIT; int r; FILE *input_fh, *output_fh; #ifdef GIT_WINDOWS_NATIVE /* try shell_prompt first, fall back to CONIN/OUT if bash is missing */ char *result = shell_prompt(prompt, echo); if (result) return result; if (echo && set_echo(1)) return NULL; #endif input_fh = fopen(INPUT_PATH, "r" FORCE_TEXT); if (!input_fh) return NULL; output_fh = fopen(OUTPUT_PATH, "w" FORCE_TEXT); if (!output_fh) { fclose(input_fh); return NULL; } if (!echo && disable_echo()) { fclose(input_fh); fclose(output_fh); return NULL; } fputs(prompt, output_fh); fflush(output_fh); r = strbuf_getline_lf(&buf, input_fh); if (!echo) { putc('\n', output_fh); fflush(output_fh); } restore_term(); fclose(input_fh); fclose(output_fh); if (r == EOF) return NULL; return buf.buf; }
void sig_handler(int s) { if (s==SIGINT && !g_abort) { signal(SIGINT, SIG_DFL); g_abort = true; return; } signal(SIGABRT, SIG_DFL); signal(SIGSEGV, SIG_DFL); signal(SIGFPE, SIG_DFL); restore_term(); abort(); }
int main(int ac, char **av) { t_select params; params.list = NULL; if (ac <= 1) return (-1); ft_signal(); if (init_term(¶ms) == -1) return (-1); if (ft_select(ac, av, ¶ms) == -1) return (-1); if (restore_term(¶ms) == -1) return (-1); return (0); }
void ft_enter(t_list **list, t_env *envir) { restore_term(envir); while (*list && (*list)->rev != 1) *list = (*list)->next; if (*list) { ft_dprintf(EXIT, "%s", (*list)->arg); *list = (*list)->next; } while (*list) { if ((*list)->rev == 1) ft_dprintf(EXIT, " %s", (*list)->arg); *list = (*list)->next; } }
char *git_terminal_prompt(const char *prompt, int echo) { static struct strbuf buf = STRBUF_INIT; int r; FILE *input_fh, *output_fh; #ifdef GIT_WINDOWS_NATIVE const char *term = getenv("TERM"); if (term && starts_with(term, "xterm")) return xterm_prompt(prompt, echo); #endif input_fh = fopen(INPUT_PATH, "r" FORCE_TEXT); if (!input_fh) return NULL; output_fh = fopen(OUTPUT_PATH, "w" FORCE_TEXT); if (!output_fh) { fclose(input_fh); return NULL; } if (!echo && disable_echo()) { fclose(input_fh); fclose(output_fh); return NULL; } fputs(prompt, output_fh); fflush(output_fh); r = strbuf_getline(&buf, input_fh, '\n'); if (!echo) { putc('\n', output_fh); fflush(output_fh); } restore_term(); fclose(input_fh); fclose(output_fh); if (r == EOF) return NULL; return buf.buf; }
void ft_which_key(char *k, t_list **list, t_env *envir) { if (*(int*)k == 27) { restore_term(envir); exit(EXIT_SUCCESS); } else if (*(int*)k == 10) ft_enter(list, envir); else if (ft_strcmp(k, tgetstr("ku", NULL)) == 0) { ft_dprintf(ENT, "%s\n", k); move_curse(*list, 1); } else if (ft_strcmp(k, tgetstr("kd", NULL)) == 0) move_curse(*list, 0); else if (ft_strcmp(k, " ") == 0) select_list(*list); else if ((ft_strcmp(k, "\177") == 0) || *(int*)k == 2117294875) ft_del(list); }
static void restore_term_on_signal(int sig) { restore_term(); sigchain_pop(sig); raise(sig); }
static void restore_term_stdin(void) { restore_term(STDIN_FILENO, &stdin_old_attr); }
int main(int argc, char **argv) { struct termios attr; int domid; char *sopt = "hn:"; int ch; unsigned int num = 0; int opt_ind=0; struct option lopt[] = { { "type", 1, 0, 't' }, { "num", 1, 0, 'n' }, { "help", 0, 0, 'h' }, { 0 }, }; char *dom_path = NULL, *path = NULL; int spty, xsfd; struct xs_handle *xs; char *end; console_type type = CONSOLE_INVAL; while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { switch(ch) { case 'h': usage(argv[0]); exit(0); break; case 'n': num = atoi(optarg); break; case 't': if (!strcmp(optarg, "serial")) type = CONSOLE_SERIAL; else if (!strcmp(optarg, "pv")) type = CONSOLE_PV; else { fprintf(stderr, "Invalid type argument\n"); fprintf(stderr, "Console types supported are: serial, pv\n"); exit(EINVAL); } break; default: fprintf(stderr, "Invalid argument\n"); fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); exit(EINVAL); } } if (optind >= argc) { fprintf(stderr, "DOMID should be specified\n"); fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); exit(EINVAL); } domid = strtol(argv[optind], &end, 10); if (end && *end) { fprintf(stderr, "Invalid DOMID `%s'\n", argv[optind]); fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); exit(EINVAL); } xs = xs_daemon_open(); if (xs == NULL) { err(errno, "Could not contact XenStore"); } signal(SIGTERM, sighandler); dom_path = xs_get_domain_path(xs, domid); if (dom_path == NULL) err(errno, "xs_get_domain_path()"); if (type == CONSOLE_INVAL) { xc_dominfo_t xcinfo; xc_interface *xc_handle = xc_interface_open(0,0,0); if (xc_handle == NULL) err(errno, "Could not open xc interface"); xc_domain_getinfo(xc_handle, domid, 1, &xcinfo); /* default to pv console for pv guests and serial for hvm guests */ if (xcinfo.hvm) type = CONSOLE_SERIAL; else type = CONSOLE_PV; xc_interface_close(xc_handle); } path = malloc(strlen(dom_path) + strlen("/device/console/0/tty") + 5); if (path == NULL) err(ENOMEM, "malloc"); if (type == CONSOLE_SERIAL) snprintf(path, strlen(dom_path) + strlen("/serial/0/tty") + 5, "%s/serial/%d/tty", dom_path, num); else { if (num == 0) snprintf(path, strlen(dom_path) + strlen("/console/tty") + 1, "%s/console/tty", dom_path); else snprintf(path, strlen(dom_path) + strlen("/device/console/%d/tty") + 5, "%s/device/console/%d/tty", dom_path, num); } /* FIXME consoled currently does not assume domain-0 doesn't have a console which is good when we break domain-0 up. To keep us user friendly, we'll bail out here since no data will ever show up on domain-0. */ if (domid == 0) { fprintf(stderr, "Can't specify Domain-0\n"); exit(EINVAL); } /* Set a watch on this domain's console pty */ if (!xs_watch(xs, path, "")) err(errno, "Can't set watch for console pty"); xsfd = xs_fileno(xs); /* Wait a little bit for tty to appear. There is a race condition that occurs after xend creates a domain. This code might be running before consoled has noticed the new domain and setup a pty for it. */ spty = get_pty_fd(xs, path, 5); if (spty == -1) { err(errno, "Could not read tty from store"); } init_term(spty, &attr); init_term(STDIN_FILENO, &attr); console_loop(spty, xs, path); restore_term(STDIN_FILENO, &attr); free(path); free(dom_path); return 0; }
void do_exit(void) { restore_term(); exit(0); }
void press_enter(t_select *params) { params->returned = 1; restore_term(params); exit(0); }
void do_escape(void) { char s[80]; restore_term(); printf("v09>"); fgets(s, 80, stdin); if (s[0]) s[strlen(s) - 1] = 0; switch (toupper(s[0])) { case 'L': if (logfile) fclose(logfile); logfile = 0; if (s[1]) { logfile = fopen(s + 1, "w"); } break; case 'S': if (infile) fclose(infile); infile = 0; if (s[1]) { infile = fopen(s + 1, "r"); } break; case 'X': if (!xmstat) do_exit(); else { xmstat = 0; fclose(xfile); xfile = 0; } break; case 'U': if (xfile) fclose(xfile); xfile = 0; if (s[1]) { xfile = fopen(s + 1, "rb"); } if (xfile) xmstat = 1; else xmstat = 0; xidx = 0; acknak = 21; rcvdnak = EOF; blocknum = 1; break; case 'D': if (xfile) fclose(xfile); xfile = 0; if (s[1]) { xfile = fopen(s + 1, "wb"); } if (xfile) xmstat = 2; else xmstat = 0; xidx = 0; acknak = 21; blocknum = 1; break; case 'R': pcreg = (mem[0xfffe] << 8) + mem[0xffff]; } if (!tracing) attention = 0; escape = 0; set_term(escchar); }
int main(int argc, char **argv) { struct termios attr; int domid; char *sopt = "h"; int ch; int opt_ind=0; struct option lopt[] = { { "help", 0, 0, 'h' }, { 0 }, }; char *path; int spty, xsfd; struct xs_handle *xs; char *end; while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { switch(ch) { case 'h': usage(argv[0]); exit(0); break; } } if ((argc - optind) != 1) { fprintf(stderr, "Invalid number of arguments\n"); fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); exit(EINVAL); } domid = strtol(argv[optind], &end, 10); if (end && *end) { fprintf(stderr, "Invalid DOMID `%s'\n", argv[optind]); fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]); exit(EINVAL); } xs = xs_daemon_open(); if (xs == NULL) { err(errno, "Could not contact XenStore"); } signal(SIGTERM, sighandler); path = xs_get_domain_path(xs, domid); if (path == NULL) err(errno, "xs_get_domain_path()"); path = realloc(path, strlen(path) + strlen("/console/tty") + 1); if (path == NULL) err(ENOMEM, "realloc"); strcat(path, "/console/tty"); /* FIXME consoled currently does not assume domain-0 doesn't have a console which is good when we break domain-0 up. To keep us user friendly, we'll bail out here since no data will ever show up on domain-0. */ if (domid == 0) { fprintf(stderr, "Can't specify Domain-0\n"); exit(EINVAL); } /* Set a watch on this domain's console pty */ if (!xs_watch(xs, path, "")) err(errno, "Can't set watch for console pty"); xsfd = xs_fileno(xs); /* Wait a little bit for tty to appear. There is a race condition that occurs after xend creates a domain. This code might be running before consoled has noticed the new domain and setup a pty for it. */ spty = get_pty_fd(xs, path, 5); if (spty == -1) { err(errno, "Could not read tty from store"); } init_term(spty, &attr); init_term(STDIN_FILENO, &attr); console_loop(spty, xs, path); restore_term(STDIN_FILENO, &attr); free(path); return 0; }