📄 sundiag.c
字号:
#ifndef lintstatic char sccsid[] = "@(#)sundiag.c 1.1 92/07/30 Copyright Sun Micro";#endif/* * Copyright (c) 1987 by Sun Microsystems, Inc. */#include "sundiag.h"#include <signal.h>#include <sys/ioctl.h>#include <sys/file.h>#include <sun/fbio.h>#include <sys/wait.h>#include <sys/resource.h>#include <sys/types.h>#include <sys/stat.h>#include <vfork.h>#include "../../lib/include/libonline.h"#include "testnames.h"#include "sundiag_msg.h"/* * frame's origin */#define SUNDIAG_X 0 /* origin(fixed) */#define SUNDIAG_Y 80#define SUNDIAG_PID "/tmp/sundiag.pid"#define MAXHOSTNAMELEN 64/* * icon definitions */static short icon_image[] = {#include "sundiag.icon"};DEFINE_ICON_FROM_IMAGE(sundiag_icon, icon_image);Icon passed_icon=(Icon)&sundiag_icon;static short failed_image[] = {#include "failed.icon"};DEFINE_ICON_FROM_IMAGE(inverted_icon, failed_image);Icon failed_icon=(Icon)&inverted_icon;/* * window object handles */Frame sundiag_frame;Panel sundiag_control;Tty sundiag_console=(Tty)0;Canvas sundiag_perfmon;Panel sundiag_status;Scrollbar status_bar, control_bar;/* * pixfonts */struct pixfont *sundiag_font;/* * miscellaneous globals */int tty_mode=FALSE; /* will be set to 1 if running in TTY mode */int pfd[2]; /* file descriptors for error message pipe */int pty_fd; /* pseudo TTY for console in TTY mode */int sundiag_done=0; /* quiting flag */char option_fname[82];char printer_name[52]; /* to keep the printer name(for screen dump) */int tty_fd; /* the file descriptor of the terminal device */int frame_width;int frame_height;char *info_file; /* sundiag information file name */char *error_file; /* sundiag error file name */char *conf_file; /* sundiag configuration file name */FILE *info_fp; /* info_file's file pointer */FILE *error_fp; /* error_file's file pointer */int ats_nohost=FALSE; /* "standalone in ATS mode" flag */char *remotehost=NULL; /* name of remote machine to test */char *version=VERSION; /* version number of the Sundiag */int config_file_only=FALSE; /* create the sundiag.conf file only */ extern char *ttyname(); /* to get the device name of console */extern FILE *fopen();extern char *malloc();extern char *getenv();extern char *mktemp();extern char *sprintf();extern char *strcpy();extern char *strncpy();extern char *strtok();extern char *strrchr();extern char *fgets();extern time_t time();extern Notify_value foreground_proc();extern Notify_value handle_input();extern Notify_value message_input();extern Notify_value console_input();extern void sd_send_mail();extern FILE *conf_open(), *batch_fp; /* declared in batch.c */extern int batch_ready; /* declared in batch.c *//* * static variables */static int tmp_argc=2; /* to change the default font */static char *tmp_argv[]={"-Wt", NULL, NULL};static int become_console=0; /* flag for making console window UNIX console or not */static int makedevice=0; /* flag for making device file or not */static char *hostname=NULL; /* ATS hostname */static int default_x, default_y;#define USEC_INC 0 /* update once every second. */#define SEC_INC 1static struct itimerval notify_timeout = { {SEC_INC,USEC_INC}, {SEC_INC,USEC_INC} };static int client_object;static int *client_handle = &client_object;static int verbose=TRUE; /* default to verbose */static int probe_flag=TRUE; /* default to probing the kernel */static int auto_quit=FALSE; /* defualt to not auto-quitting */static int not_done=1; /* probeing's done flag */static int null_fd; /* fd of /dev/null */static int no_perfmon=FALSE;/* perfmon won't work with special kernel because rpc.rstatd is hardwired to "/vmunix" */static char *ptynames[] ={ "/dev/ptyrf", "/dev/ptyre", "/dev/ptyqf", "/dev/ptyqe", "/dev/ptypf", "/dev/ptype", "/dev/ptyp7", "/dev/ptyp6"};#define NPTYS (sizeof(ptynames)/sizeof(*ptynames))static char *ttynames[] ={ "/dev/ttyrf", "/dev/ttyre", "/dev/ttyqf", "/dev/ttyqe", "/dev/ttypf", "/dev/ttype", "/dev/ttyp7", "/dev/ttyp6"};/* * forward declarations */extern Notify_value kill_proc();static Notify_value wait_probe();static int check_exe();static void check_arg();static Notify_value stop_notifier_proc();static Notify_value notify_proc();static int check_sundiag();typedef void (*void_func)(); /* used to shut up lint *//****************************************************************************** * Main program starts here. * ******************************************************************************/main(argc, argv)int argc;char *argv[];{ char *tmpname="/tmp/sundiag.XXXXXX"; /* temporary ".suntools" file */ char cmd[122], *tmp, *tmp1; int i, cgfour=0, remote=FALSE; FILE *fp; struct fbtype fb_type; struct fbgattr fb_gattr; extern char *optarg; struct timeval c_tv; version_id = 0; test_id = get_test_id(argv[0], testname_list); option_fname[0]=NULL; if (getuid()) { (void)fprintf(stderr, "Sundiag: must be a super user to run Sundiag.\n"); exit(1); } /* check command line for remote execution */ for (i=0; i<argc; i++) if (strcmp(argv[i], "-h") == 0) { remote = TRUE; break; } /* if remote, don't check whether sundiag is already running */ if (!remote) if (check_sundiag()) { (void)fprintf(stderr, "Sundiag: Sundiag is already running.\n"); exit(1); } if (getenv("WINDOW_PARENT") == NULL) { tmp = ttyname(0); /* get the input device name */ if (tmp != NULL && strcmp(tmp+5, "console") == 0) { tmp = getenv("TERM"); if (tmp != NULL && strcmp(tmp, "sun") != 0) tty_mode = TRUE; /* should be run in TTY mode */ (void)check_arg(argc, argv); /* forced tty mode? */ if (!tty_mode) { /* sundiag was invoked from console mode */ if ((i=open("/dev/fb", O_RDWR)) != -1) { (void)ioctl(i, FBIOGTYPE, &fb_type); if (fb_type.fb_type == FBTYPE_SUN2BW) if (ioctl(i, FBIOGATTR, &fb_gattr) == 0) if (fb_gattr.real_type == FBTYPE_SUN4COLOR) cgfour = 1; /* this is cgfour0 */ (void)close(i); } (void)mktemp(tmpname); /* make temporary file's name */ if (verbose) (void)sprintf(cmd,"echo shelltool -Wp 200 200 csh -c \\\"%s -C", argv[0]); else (void)sprintf(cmd,"echo \"%s -C", argv[0]); for (i=1; i != argc; ++i)/* append the rest of the command line */ (void)sprintf(cmd, "%s %s", cmd, argv[i]); if (verbose) (void)sprintf(cmd, "%s\\\" > %s", cmd, tmpname); else (void)sprintf(cmd, "%s\" > %s", cmd, tmpname); (void)system(cmd); if (cgfour) execlp("suntools","suntools","-8bit_color_only","-s",tmpname, NULL); else execlp("suntools", "suntools", "-s", tmpname, NULL); perror("execlp"); exit(1); /* failed to bring up suntools automatically */ } } else { tty_mode = TRUE; /* should be run in TTY mode */ (void)check_arg(argc, argv);/* options for TTY mode all checked */ } } if ((tmp=strrchr(argv[0], '/')) != NULL) /* running from other directories */ { *tmp = '\0'; /* NULL-terminated */ (void)chdir(argv[0]); /* change current working directory */ } else if (check_exe(argv[0]) == -1) /* from command path */ { if ((tmp1=getenv("PATH")) != NULL) if ((tmp=malloc((unsigned)strlen(tmp1)+2)) != NULL) { (void)strcpy(tmp, tmp1); tmp1=tmp; /* so we can free it later */ if (strtok(tmp, ": ,\n") != NULL) { do { (void)sprintf(cmd, "%s/%s", tmp, argv[0]); if (check_exe(cmd) == 0) /* find it */ { (void)chdir(tmp); /* change current working directory */ break; } } while ((tmp=strtok((char *)NULL, ": ,\n")) != NULL); } free(tmp1); } } init_env(); /* initialize the global Sundiag environment */ if (!tty_mode) { sundiag_frame = window_create((Frame)NULL, FRAME, FRAME_LABEL, NULL, FRAME_ICON, &sundiag_icon, WIN_X, SUNDIAG_X, WIN_Y, SUNDIAG_Y, WIN_HEIGHT, 0, WIN_WIDTH, 0, WIN_ERROR_MSG, "sundiag: cannot create base sundiag frame", FRAME_ARGS, tmp_argc, tmp_argv, /* defult font */ FRAME_ARGC_PTR_ARGV, &argc, argv, /* user's options */ 0); (void)check_arg(argc, argv); } init_misc(); /* initialize misc. data */ init_rpc(); /* start rpc server */ if (probe_flag) conf_probe(); /* probe the hardware configuration */ else { cpuname = "Unknown"; /* cpuname is always needed */ build_user_tests(); /* go checking for user-defined tests */ } if (config_file_only) exit(1); if (!ats_nohost) init_client(hostname); if (option_fname[0] != NULL) if (!load_option(option_fname, 0)) option_fname[0] = NULL; (void)notify_set_itimer_func((Notify_client)client_handle, notify_proc, ITIMER_REAL, ¬ify_timeout , (struct itimerval *)0); (void)notify_set_signal_func((Notify_client)client_handle, kill_proc, SIGINT, NOTIFY_ASYNC); if (!tty_mode) { if ((int)window_get(sundiag_frame, WIN_WIDTH) == 0) /* if not set by command line */ { (void)window_set(sundiag_frame, WIN_HEIGHT, frame_height-SUNDIAG_Y, WIN_WIDTH, frame_width-SUNDIAG_X, 0); } /* If FRAME_LABEL wasn't set by command line argument, set it */ if ((char *)window_get(sundiag_frame, FRAME_LABEL) == NULL) { if (remotehost == NULL || tty_mode) (void)sprintf(cmd, " *** Sundiag %s *** CPU: %s", version, cpuname); else (void)sprintf(cmd, " *** Sundiag %s *** Remote Host: %s CPU: %s", version, remotehost, cpuname); (void)window_set(sundiag_frame, FRAME_LABEL, cmd, 0); } /* 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\nSunView\n", getpid()); (void)fclose(fp); } create_status(sundiag_frame); create_perfmon(sundiag_frame);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -