📄 sundiag.c
字号:
create_control(sundiag_frame); create_console(sundiag_frame); (void)notify_set_signal_func((Notify_client)client_handle, kill_proc, SIGHUP, NOTIFY_ASYNC); (void)notify_interpose_destroy_func(sundiag_frame,stop_notifier_proc); init_control(sundiag_control); if (!no_perfmon) perfmon_main();/* initialize the perfmon subwindow */ test_items(); /* display test-related items on control window */ init_status(); /* create status message item */ } else { switch ((i=fork())) { case -1: perror("fork background"); break; case 0: break; default: execlp("./sundiagup", "./sundiagup", "sd", (char *)0); perror("execlp sundiagup"); (void)kill(i, SIGKILL); exit(1); } tty_ppid = getppid(); /* create pid file only if not in remote host mode */ if (remotehost == NULL) { fp = fopen(SUNDIAG_PID, "w"); /* write out the PID */ (void)fprintf(fp, "%d\nTTY\n", getpid()); (void)fclose(fp); } (void)notify_set_signal_func((Notify_client)client_handle, kill_proc, SIGTERM, NOTIFY_ASYNC); (void)notify_set_signal_func((Notify_client)client_handle, foreground_proc, SIGUSR1, NOTIFY_ASYNC); test_items(); /* display the control screen */ init_ttys(); /* initialize the TTY screens */ print_status(); /* display the status screen */ (void)signal(SIGHUP, (void_func)kill_proc); /* catch SIGHUP */ (void)notify_set_input_func((Notify_client)client_handle, handle_input, 0); /* call "handle_input" when needed */ (void)notify_set_input_func((Notify_client)client_handle, message_input, pfd[0]); /* call "message_input" when needed */ if (become_console) (void)notify_set_input_func((Notify_client)client_handle, console_input, pty_fd); /* call "console_input" when needed */ } create_config_dir(); /* create the config dir if it does not exist */ if (auto_start) start_proc(); /* automatically start testing */ if (batch_mode) batch(); /* start batch testing */ c_tv.tv_usec = 0; c_tv.tv_sec = 30; notify_set_signal_check(c_tv); /* -JCH- Utilize notifier hack to avoid stopped clock bug */ if (!tty_mode) window_main_loop(sundiag_frame); /* start SunView */ else while (TRUE) (void)notify_start(); /* start notifier */}static create_status(sundiag_frame)Frame sundiag_frame;{ status_bar = scrollbar_create(0); sundiag_status = window_create(sundiag_frame, PANEL, WIN_VERTICAL_SCROLLBAR, status_bar, WIN_WIDTH, (int)(frame_width*STATUS_WIDTH), WIN_HEIGHT, (int)(frame_height*PERFMON_HEIGHT), WIN_IGNORE_KBD_EVENT, WIN_NO_EVENTS, 0);}/****************************************************************************** * check_arg(), checks the command line arguments. * * Input: argc, argv. * * Output: exit if errors were encountered. * ******************************************************************************/static void check_arg(argc, argv)int argc;char *argv[];{ int i; char c, *tmp; /* check command line options */ i = 0; /* initialize the error flag */ while ((c=getopt(argc, argv, "Cmtpqvwo:b:h:a:k:")) != EOF) { switch(c) { case 'a': hostname = optarg; break; case 'C': become_console = 1; break; case 'h': /* remote host */ remotehost = optarg; break; case 'm': makedevice = 1; break; case 'o': (void)strcpy(option_fname, optarg); break; case 't': tty_mode = TRUE; /* forced into TTY mode */ break; case 'p': probe_flag = FALSE; /* don't probe the kernel */ break; case 'q': auto_quit = TRUE; /* auto quit when stopped */ break; case 'v': verbose = FALSE; /* don't print any message before sundiag screen is up */ break; case 'k': tmp = malloc((unsigned)strlen(optarg)+20); sprintf(tmp, "KERNELNAME=%s", optarg); putenv(tmp); if (strcmp(optarg, "/vmunix") != 0) no_perfmon = TRUE; break; case '?': /* illegal command line argument */ i = 1; break; case 'b': if ( (batch_fp = conf_open(optarg)) == (FILE *)0 ) i = 1; else batch_mode = TRUE; /* batch testing mode */ break; case 'w': config_file_only = TRUE; /* write sundiag.conf file */ break; } } if (i != 0) { (void)fprintf(stderr, "Usage: sundiag [-Cmpqtvw][-a|-h hostname][-o option_file][-b batch_file][-k kernel_name]\n"); exit(1); } else if (hostname == NULL) ats_nohost = TRUE;}/****************************************************************************** * check_exe(), checks whether the file is executable or not. * * Input: filename, path of the file to be check. * * Output; 0, if yes; -1, otherweise. * ******************************************************************************/static int check_exe(filename)char *filename;{ struct stat f_stat; if ((stat(filename, &f_stat) == -1) || (f_stat.st_size == 0)) return(-1); if ((f_stat.st_mode & S_IFMT) != S_IFREG || (f_stat.st_mode & S_IEXEC) != S_IEXEC) return(-1); return(0);}/****************************************************************************** * Creates and initializes the console subwindow. * ******************************************************************************/static create_console(sundiag_frame)Frame sundiag_frame;{ sundiag_console = window_create(sundiag_frame, TTY, WIN_BELOW, sundiag_status, WIN_WIDTH, (int)(frame_width*STATUS_WIDTH+ frame_width*PERFMON_WIDTH)+5, 0); tty_fd = null_fd; if (become_console) (void)window_set(sundiag_console, TTY_CONSOLE, TRUE, 0);}static create_perfmon(sundiag_frame)Frame sundiag_frame;{ sundiag_perfmon = window_create(sundiag_frame, CANVAS, WIN_WIDTH, (int)(frame_width*PERFMON_WIDTH), WIN_HEIGHT, (int)(frame_height*PERFMON_HEIGHT), CANVAS_FAST_MONO, TRUE, 0);}static create_control(sundiag_frame)Frame sundiag_frame;{ control_bar = scrollbar_create( SCROLL_PLACEMENT, SCROLL_EAST, 0); sundiag_control = window_create(sundiag_frame, PANEL, WIN_VERTICAL_SCROLLBAR, control_bar, 0);}/****************************************************************************** * Initializes misc. variables and data structures. * ******************************************************************************/static init_misc(){ char *path, *tmp; char *file_suffix = ""; int len, i, rty_fd, dummy=0; FILE *version_fp; char version_tmp[50]; static char version_buf[22]; int memfd; /* get number of processors and processsors mask */ memfd = open("/dev/null", 0); processors_mask = get_processors_mask(memfd, processors_mask); system_processors_mask = processors_mask; number_processors = get_number_processors(processors_mask); number_system_processors = number_processors; close(memfd); if ((null_fd=open("/dev/null", O_WRONLY)) < 0) { perror("/dev/null"); exit(1); } tty_fd = null_fd; if (!tty_mode) { if (verbose) tty_fd = 2; /* stderr untill console window is up */ sundiag_font = pf_default(); /* keep a copy of the font */ if (default_x != 0) /* the default font was opened */ { if (sundiag_font->pf_defaultsize.x != default_x) frame_width=(frame_width*sundiag_font->pf_defaultsize.x)/ default_x; if (sundiag_font->pf_defaultsize.y != default_y) frame_height = (frame_height*sundiag_font->pf_defaultsize.y)/ default_y; } } else /* open the message pipe */ { if (pipe(pfd) == -1) { perror("pipe"); exit(1); } if (become_console) { for( i = 0; i < NPTYS; i++) /* find an open pty */ if ((pty_fd = open(ptynames[i], O_RDWR)) >= 0) break; if (i == NPTYS) { perror("init_misc: can't get a pty"); exit(1); } if ((rty_fd = open(ttynames[i], O_RDWR)) < 0) /* open the slave */ { perror("init_misc: can't open slave tty"); exit(1); } if (ioctl(rty_fd, TIOCCONS, &dummy) != 0) /* redirect the console */ { perror("init_misc: can't redirect the console"); exit(1); } } init_tty_windows(); } path = malloc((unsigned)(strlen(LOG_DIR)+strlen(INFO_FILE)+ strlen(ERROR_FILE)+ strlen(CONF_FILE)+2)); if (access(LOG_DIR, F_OK) != 0) if (mkdir(LOG_DIR, 0755) != 0) { (void)sprintf(path, "mkdir %s", LOG_DIR); perror(path); exit(1); } if (remotehost != NULL) { file_suffix = malloc((unsigned)strlen(remotehost)+2); (void)sprintf(file_suffix, ".%s", remotehost); } (void)sprintf(path, "%s/%s%s", LOG_DIR, INFO_FILE, file_suffix); if ((info_fp=fopen(path, "a")) == NULL) { perror("Open sundiag.info"); exit(1); } info_file = malloc((unsigned)strlen(path)+2); (void)strcpy(info_file, path); /* keep a copy of it */ (void)sprintf(path, "%s/%s%s", LOG_DIR, ERROR_FILE, file_suffix); if ((error_fp=fopen(path, "a")) == NULL) { perror("Open sundiag.err"); exit(1); } error_file = malloc((unsigned)strlen(path)+2); (void)strcpy(error_file, path); /* keep a copy of it */ (void)sprintf(path, "%s/%s%s", LOG_DIR, CONF_FILE, file_suffix); conf_file = malloc((unsigned)strlen(path)+2); (void)strcpy(conf_file, path); free(path); if ((tmp=getenv("PRINTER")) != NULL) { (void)strncpy(printer_name, tmp, 50); printer_name[50] = '\0'; /* to be safe */ } else (void)strcpy(printer_name, "lp"); /* default printer name */ if ((version_fp=fopen(VERSION_FILE, "r")) != NULL) { version_buf[0] = '\0'; version = fgets(version_buf, 20, version_fp); len = strlen(version) - 1; if (len >= 0 && *(version+len) == '\n') *(version+len) = '\0'; fclose(version_fp); } strncpy(version_buf, version, 4); subtest_id = get_version_id(version_buf); sprintf(version_tmp, start_sundiag_info, version); logmsg(version_tmp, 1, START_SUNDIAG_INFO); /* *** Start sundiag *** */}/****************************************************************************** * initialize rpc server and fork probing routine. * ******************************************************************************/static int probe_object;static int *probe_handle = &probe_object;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -