📄 ttyprocs.c
字号:
#ifndef lintstatic char sccsid[] = "@(#)ttyprocs.c 1.1 92/07/30 Copyright Sun Micro";#endif/* * Copyright (c) 1987 by Sun Microsystems, Inc. */#include <curses.h>#include "sundiag.h"#include "struct.h"#include "tty.h"#include <ctype.h>#include <signal.h>#include <fcntl.h>int option_id; /* test i.d. of the current option popup */char *com_err="Command error!"; /* command error message */char *format_err="Command format error!"; /* format error message */extern char run_time_file[];extern char **get_file_names();extern char *strcpy();extern char *sprintf();extern char *getenv();extern Panel init_opt_panel();extern Notify_value kill_proc();typedef void (*void_func)(); /* used to shut up lint */static int max_opfile=0; /* max. page # of option filename list */static int cur_opfile=0; /* current page # of displayed filename list */static char tty_logfile='e';/* current log file to be acted on */static char **name_list=NULL;static char term_type[22];static struct com_tbl option_tbl1[]={ {"default", 'f'}, {"done", 'd'}, {"corefile", 'o'}, {"singlepass", 's'}, {"quicktest", 'q'}, {"verbose", 'v'}, {"trace", 't'}, {"autostart", 'a'}, {"runerror", 'r'}, {"sendmail", 'm'}, {"help", 'h'}, {"", '\0'}};static struct com_tbl option_tbl2[]={ {"maxpasses", 'x'}, {"maxerrors", 'y'}, {"concurrent", 'c'}, {"logperiod", 'l'}, {"eaddress", 'e'}, {"printer", 'p'}, {"", '\0'}};static struct com_tbl optfile_tbl1[]={ {"done", 'd'}, {"load", 'l'}, {"store", 's'}, {"remove", 'r'}, {"next", 'n'}, {"help", 'h'}, {"", '\0'}};static struct com_tbl optfile_tbl2[]={ {"name", 'm'}, {"", '\0'}};static struct com_tbl logfile_tbl1[]={ {"done", 'd'}, {"display", 'l'}, {"remove", 'r'}, {"print", 'p'}, {"help", 'h'}, {"", '\0'}};static struct com_tbl logfile_tbl2[]={ {"name", 'm'}, {"", '\0'}};static struct com_tbl logfile_tbl3[]={ {"error", 'e'}, {"info", 'i'}, {"unix", 'u'}, {"", '\0'}};static struct com_tbl eeprom_tbl1[]={ {"default", 'f'}, {"done", 'd'}, {"help", 'h'}, {"cancel", 'c'}, {"assertscsia", 'a'}, {"assertscsib", 'b'}, {"consoletype", 'x'}, {"screensize", 'z'}, {"keyclick", 'k'}, {"watchdogreboot", 'w'}, {"unixbootpath", 'u'}, {"customlogo", 'l'}, {"", '\0'}};static struct com_tbl eeprom_tbl2[]={ {"unixbootdevice", 'o'}, {"bannerstring", 's'}, {"diagbootpath", 'p'}, {"diagbootdev", 'g'}, {"keyboardtype", 't'}, {"memorysize", 'm'}, {"memorytestsize", 'i'}, {"columns", 'n'}, {"rows", 'r'}, {"", '\0'}};static struct com_tbl processors_tbl1[] ={ {"default", 'f'}, {"done", 'd'}, {"help", 'h'}, {"", '\0'}};static struct com_tbl processors_tbl2[16];static struct com_tbl schedule_tbl1[]={ {"done", 'd'}, {"cancel", 'c'}, {"scheduler", 's'}, {"help", 'h'}, {"", '\0'}};static struct com_tbl schedule_tbl2[]={ {"startdate", 'r'}, {"starttime", 't'}, {"stopdate", 'o'}, {"stoptime", 'm'}, {"", '\0'}};/****************************************************************************** * tty_options(), display the current options on the "other window". * ******************************************************************************/#define OPTION_COL 24 tty_options(){ char *enable, *disable; char *tmp; int row; mvwaddstr(tty_other, 0, OPTION_COL, "<< System Option Menu >>"); mvwaddstr(tty_other, 2, OPTION_COL, "[DEFAULT(f)] [DONE(d)] [HELP(h)]"); enable = "Enable"; disable = "Disable"; row = 4; (void)mvwprintw(tty_other, row++, OPTION_COL, "[COREFILE(o)]: %-7s", core_file?enable:disable); (void)mvwprintw(tty_other, row++, OPTION_COL, "[SINGLEPASS(s)]: %-7s", single_pass?enable:disable); (void)mvwprintw(tty_other, row++, OPTION_COL, "[QUICKTEST(q)]: %-7s", quick_test?enable:disable); (void)mvwprintw(tty_other, row++, OPTION_COL, "[VERBOSE(v)]: %-7s", verbose?enable:disable); (void)mvwprintw(tty_other, row++, OPTION_COL, "[TRACE(t)]: %-7s", trace?enable:disable); (void)mvwprintw(tty_other, row++, OPTION_COL, "[AUTOSTART(a)]: %-7s", auto_start?enable:disable); (void)mvwprintw(tty_other, row++, OPTION_COL, "[RUNERROR(r)]: %-7s", run_error?enable:disable); switch (send_email) { case 1: tmp = "On_Error"; break; case 2: tmp = "Periodically"; break; case 3: tmp = "Both"; break; default: tmp = disable; } (void)mvwprintw(tty_other, row++, OPTION_COL, "[SENDMAIL(m)]: %-12s", tmp); (void)mvwprintw(tty_other, row++, OPTION_COL, "[MAXPASSES(x)]: %-5u", max_sys_pass); (void)mvwprintw(tty_other, row++, OPTION_COL, "[MAXERRORS(y)]: %-5u", max_errors); (void)mvwprintw(tty_other, row++, OPTION_COL, "[CONCURRENT(c)]: %-5u", max_tests); (void)mvwprintw(tty_other, row++, OPTION_COL, "[LOGPERIOD(l)]: %-10u", log_period); (void)mvwprintw(tty_other, row++, OPTION_COL, "[EADDRESS(e)]: %-20s", eaddress); (void)mvwprintw(tty_other, row++, OPTION_COL, "[PRINTER(p)]: %-20s", printer_name); touchwin(tty_other); (void)wrefresh(tty_other); (void)refresh(); /* restore the cursor */}/****************************************************************************** * tty_log_files(), display the log file menu. * ******************************************************************************/#define LOGFILE_COL 24 tty_log_files(){ char temp[82]; mvwaddstr(tty_other, 0, LOGFILE_COL, "<< Log File Menu >>"); mvwaddstr(tty_other, 2, LOGFILE_COL-6, "[DONE(d)] [HELP(h)]"); mvwaddstr(tty_other, 3, LOGFILE_COL-6, "[DISPLAY(l)] [REMOVE(r)] [PRINT(p)]"); (void)sprintf(temp, "[NAME(m)]: %s", tty_logfile=='e'? "ERROR [INFO(i)/UNIX(u)]": (tty_logfile=='i'? "INFO [UNIX(u)/ERROR(e)]":"UNIX [ERROR(e)/INFO(i)]")); mvwaddstr(tty_other, 5, LOGFILE_COL-6, temp); touchwin(tty_other); (void)wrefresh(tty_other); (void)refresh(); /* restore the cursor */}/****************************************************************************** * tty_opfiles(), display the option file menu. * ******************************************************************************/#define OPFILE_COL 24 tty_opfiles(list)int list; /* TRUE, if needs to update the available list */{ int row, col; int x, y, len; int total, index; int i, j; char **temp; mvwaddstr(tty_other, 0, OPFILE_COL, "<< Option File Menu >>"); mvwaddstr(tty_other, 2, OPFILE_COL-10, "[DONE(d)] [HELP(h)]"); mvwaddstr(tty_other, 3, OPFILE_COL-10, "[LOAD(l)] [STORE(s)] [REMOVE(r)] [NEXT(n)]"); (void)mvwprintw(tty_other, 4, OPFILE_COL-10, "[NAME(m)]: %-20s",option_fname); if (list) { if (name_list != NULL) while (*name_list != NULL) free(*name_list++); name_list = get_file_names(OPTION_DIR); temp = name_list; /* keep the head */ row = 7; /* starting row */ (void)wmove(tty_other, row, 0); (void)wclrtobot(tty_other); /* clear the rest of the window */ if (*temp == NULL) /* didn't find any */ { max_opfile = 0; cur_opfile = 0; mvwaddstr(tty_other, row, 4, "<none>"); } else { x = 0; total = 0; while (*temp != NULL) { if ((len=strlen(*temp++)) > x) x = len; /* get the longest filename */ ++total; /* increment total # of files found */ } len = x+2; /* number of columns for each filename */ x = (COLS-6)/len; /* # of filenames to be displayed in a line */ y = LINES - 14; /* available lines */ max_opfile = (total-1)/(x*y); /* max. page # */ if (cur_opfile > max_opfile) cur_opfile = max_opfile; index = cur_opfile*x*y; /* starting filename index */ for (i=0; i < y; ++i, ++row) { col = 4; for (j=0; j < x && index < total; ++j, ++index, col+=len) mvwaddstr(tty_other, row, col, *(name_list+index)); if (index == total) break; /* done */ } } } (void)mvwaddstr(tty_other, 6, 4, "Available option files:"); touchwin(tty_other); (void)wrefresh(tty_other); (void)refresh(); /* restore the cursor */}/****************************************************************************** * get_com(), search the passed command table and return a single character * * sharthand command to the caller. * * Input: the pointer to the command table, and the to-be-searched command. * * output: a single character short hand command, or NULL if no match. * ******************************************************************************/char get_com(table, command)struct com_tbl *table; /* command table */char *command; /* to-be-searched command */{ if (strlen(command) == 1) return(*command); /* already single character */ while (table->shortname != NULL) { if (strcmp(command, table->fullname) == 0) /* found it */ return(table->shortname); ++table; } return('\0');}/****************************************************************************** * attach to the specified(in ATTACH_TTY) tty(foreground it). * ******************************************************************************/#define ATTACH_TTY "/tmp/sundiag.tty"Notify_value foreground_proc(){ FILE *fp; int i, tmp_pid; char tmp[26]; if ((fp=fopen(ATTACH_TTY, "r")) == NULL) /* open the info. file */ return(NOTIFY_DONE); /* ignored if failed */ (void)fgets(tmp, 20, fp); /* get the graber's pid */ tmp_pid = atoi(tmp); /* save the pid so we can kill it later */ if (kill(tmp_pid, 0) != 0) /* check if this is a valid pid */ { (void)fclose(fp); return(NOTIFY_DONE); /* ignored if it is not a valid pid */ } term_tty(); /* safe to clean up the curses now */ if (tty_ppid != 0) /* grab it from other tty */ { (void)kill(tty_ppid, SIGKILL);/* wake up that shell */ unset_input_notify(); /* unregistered before closing */ } tty_ppid = tmp_pid; (void)setpgrp(0, tty_ppid); (void)fgets(tmp, 20, fp); /* get the tty name */ i = strlen(tmp); tmp[i-1] = '\0'; /* remove the newline */ (void)fgets(term_type, 20, fp); /* get the new terminal type */ (void)fclose(fp); /* redirect the stdin, stdout, and stderr to the new tty */ (void)close(0); /* so we can reopen it */ (void)open(tmp, O_RDWR); (void)dup2(0, 1); (void)dup2(0, 2); set_input_notify(); /* register the input notifier again */ (void)signal(SIGHUP, (void_func)kill_proc); /* catch SIGHUP */ (void)delwin(message_tty); /* free the resources */ (void)delwin(console_tty); (void)delwin(status_button); (void)delwin(control_button); (void)delwin(tty_other); (void)delwin(tty_option); for (i=0; tty_control[i] != NULL; ++i) { (void)delwin(tty_control[i]); tty_control[i] = NULL; } for (i=0; tty_status[i] != NULL; ++i) { (void)delwin(tty_status[i]); tty_status[i] = NULL; } LINES = COLS = 0; /* so that setterm() will reset it */ if (term_type[0] != '\0') { (void)sprintf(tmp, "TERM=%s", term_type); (void)putenv(tmp); } test_items(); init_ttys(); /* initialize the TTY screens */ print_status(); /* display the status screen */ return(NOTIFY_DONE);}/****************************************************************************** * tty_option_proc(), process the system options menu commands. * ******************************************************************************/tty_option_proc(){ if (arg_no == 1) /* command without arguments */ switch (get_com(option_tbl1, arg[0])) { case 'f': /* default */ core_file = 0; single_pass = 0; quick_test = 0; verbose = 0; trace = 0; auto_start = 0; run_error = 0; send_email = 0; max_errors = 1; max_sys_pass = 0; max_tests = 2; log_period = 0; (void)strcpy(eaddress, "root"); (void)strcpy(printer_name, "lp"); break; case 'd': /* done */ switch_to_control(); return; case 'o': /* core file */ core_file = !core_file; break; case 's': /* single pass */ single_pass = !single_pass; break; case 'q': /* quick test */ quick_test = !quick_test; break; case 'v': /* verbose */ verbose = !verbose; break; case 't': /* trace */ trace = !trace; break; case 'a': /* auto start */ auto_start = !auto_start; break; case 'r': /* run on error */ run_error = !run_error; break; case 'm': /* send email */ if (++send_email > 3) send_email = 0; break; case 'h': /* help */ tty_help(); break; default: tty_message(com_err); return; } else if (arg_no == 2) /* command with one argument */ switch (get_com(option_tbl2, arg[0])) { case 'x': /* max. pass # */ max_sys_pass = atoi(arg[1]); break; case 'y': /* max. errors # */ max_errors = atoi(arg[1]); break; case 'p': /* printer name */ (void)strcpy(printer_name, arg[1]); break; case 'c': /* concurrent tests # */ max_tests = atoi(arg[1]); set_max_tests(max_tests); /* set the max. # of tests per group */ break; case 'l': /* log/email period */ log_period = atoi(arg[1]); break; case 'e': /* email address */ (void)strcpy(eaddress, arg[1]); break; default: tty_message(com_err); return; } else { tty_message(com_err); return; } tty_options(); /* update the system option window */}/****************************************************************************** * tty_opfile_proc(), process the option file commands. * ******************************************************************************/tty_opfile_proc(){ if (arg_no == 1) /* command without arguments */ switch (get_com(optfile_tbl1, arg[0])) { case 'd': /* done */ cur_opfile = 0; /* reset it for the next time */ switch_to_control(); break; case 'l': /* load from option file */ load_option_files(); break; case 's': /* store to option file */ store_option_files(); tty_opfiles(TRUE); break; case 'r': /* remove the specified option file */ remove_option_files(); tty_opfiles(TRUE); break; case 'n': /* list next page of option file names */ if (max_opfile == 0) { tty_message("No next option file screen!"); return; } if (++cur_opfile > max_opfile) cur_opfile = 0; tty_opfiles(TRUE); break; case 'h': /* help */ tty_help(); break; default: tty_message(com_err); return; } else if (arg_no == 2) /* command with one argument */ switch (get_com(optfile_tbl2, arg[0])) { case 'm': /* assign option file name */ (void)strcpy(option_fname, arg[1]); tty_opfiles(FALSE); break; default: tty_message(com_err); return; } else { tty_message(format_err); return; }}/****************************************************************************** * tty_logfile_proc(), process the log file commands. * ******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -