⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sundiag.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
static	conf_probe(){  int	childpid;  char	myhostname[MAXHOSTNAMELEN];	childpid = vfork();	/* fork the probing routine */	if (childpid == 0)	/* in child process */	{	  if (remotehost == NULL) {	    if (makedevice)              execlp("./probe", "./probe", "-m", 0);		/* start the probing routine, make the device file if missing */	    else              execlp("./probe", "./probe", 0);	/* start the probing routine */	  } else {	    if ((gethostname(myhostname, MAXHOSTNAMELEN - 1)) == -1) {		(void)fprintf(stderr, "Can't get my hostname\n");		_exit(1);	    }	    if (makedevice)	      execlp("remote", "remote", remotehost, "probe", "-m", myhostname,		     0);	    else	      execlp("remote", "remote", remotehost, "probe", "-h", myhostname,		     0);	  }	  perror("execlp(probe)");	  _exit(-1);    	}	(void)notify_set_wait3_func((Notify_client)probe_handle,						wait_probe, childpid);	if (verbose)	  (void)fprintf(stderr,		"\nSundiag: Starting probing routine, please wait...\n");	while (not_done)	/* wait until done, no time out yet ! */	  (void)notify_dispatch();}/****************************************************************************** * Initializes the global Sundiag environment.				      * ******************************************************************************/static	init_env(){  int	tmpfd;  struct fbtype	fb_type;	frame_width = 1152;	frame_height = 900;		/* default dimensions */	tmp_argv[1] = STANDARD_FONT;	/* default font */		if (!tty_mode)	{	  if ((tmpfd=open("/dev/fb", O_RDWR)) != -1)	  {	    (void)ioctl(tmpfd, FBIOGTYPE, &fb_type);	    frame_width = fb_type.fb_width;	    frame_height = fb_type.fb_height;	    if (frame_width > 1500)	      tmp_argv[1] = BOLD_FONT;	/* must be on hi-res monitor */	    (void)close(tmpfd);	  }	  sundiag_font = pf_open(tmp_argv[1]);	  if (sundiag_font == NULL)	  {	    default_x = 0;		/* use it as a flag */	    default_y = 0;	  }	  else	  {	    default_x = sundiag_font->pf_defaultsize.x;	    default_y = sundiag_font->pf_defaultsize.y;	    /* get the size of the default font */	    (void)pf_close(sundiag_font);	  }	}	if (option_fname[0] == NULL)	/* if no specified option file yet */	{	  /* check if .sundiag exists */	  (void)sprintf(option_fname, "%s/%s", OPTION_DIR, OPT_FILE);	  if (access(option_fname, R_OK) == 0)	    (void)strcpy(option_fname, OPT_FILE);	  else		    option_fname[0]=NULL;	}}/****************************************************************************** * wait_probe() is the notify procedure when probing routine exits.	      * ******************************************************************************//*ARGSUSED*/static	Notify_value wait_probe(me, pid, status, rusage)int *me;int pid;union wait *status;struct rusage *rusage;{  if (exist_tests == 0)  {    (void)fprintf(stderr, "Sundiag: failed probing system configuration!\n");    if (remotehost == NULL)      (void)unlink(SUNDIAG_PID);    exit(1);  }  not_done = 0;  return(NOTIFY_DONE);}/****************************************************************************** * sundiag_exit() is to be called to exit Sundiag abnormally.		      * ******************************************************************************//*ARGSUSED*/sundiag_exit(code)int	code;{	  (void)notify_stop();	  sundiag_done = 1;	  logmsg(quit_abnorm_info, 1, QUIT_ABNORM_INFO);	  if (running == GO || running == SUSPEND || running == KILL)	  {	    kill_all_tests();	    log_status();	  }	  write_log("\n\n", info_fp);		/* delimiter */	  write_log("\n\n", error_fp);		/* delimiter */	  if (tty_mode)	  {	    if (tty_ppid != 0)	      (void)kill(tty_ppid, SIGTERM);	      restore_term_tty_state();         /* clean up curses remnates */	  }    	  if (remotehost == NULL)	    (void)unlink(SUNDIAG_PID);	  exit(code);}/****************************************************************************** * The SIGHUP and SIGINT signal handlers(set by notify_set_signal_func()).    * ******************************************************************************/Notify_value	kill_proc(){	(void)notify_stop();	sundiag_done = 1;	logmsg(quit_sundiag_info, 1, QUIT_SUNDIAG_INFO);	if (running == GO || running == SUSPEND || running == KILL)	{	  kill_all_tests();	  log_status();	}	write_log("\n\n", info_fp);	/* delimiter */	write_log("\n\n", error_fp);	/* delimiter */	if (tty_mode)	{	  term_tty();		/* clean up curses routines */	  if (tty_ppid != 0)	    (void)kill(tty_ppid, SIGTERM);	}    	if (remotehost == NULL)	  (void)unlink(SUNDIAG_PID);	exit(0);}/****************************************************************************** * The "notify_interpose_destroy_func()" procedure for the Sundiag frame.     * * Its purpose is to clean up the mess before exits.			      * ******************************************************************************/static Notify_value	stop_notifier_proc(frame, status)Frame		frame;Destroy_status	status;{	if (status != DESTROY_CHECKING)	{	  (void)notify_stop();	  sundiag_done = 1;	  logmsg(quit_sundiag_info, 1, QUIT_SUNDIAG_INFO);	  if (running == GO || running == SUSPEND || running == KILL)	  {	    kill_all_tests();	    log_status();	  }	  write_log("\n\n", info_fp);		/* delimiter */	  write_log("\n\n", error_fp);		/* delimiter */	}    	if (remotehost == NULL)	  (void)unlink(SUNDIAG_PID);	return(notify_next_destroy_func(frame, status));}/****************************************************************************** * notify_proc(), the periodic timer function(called once every second) to    * * handle backgroud tasks.						      * ******************************************************************************/static	Notify_value	notify_proc(){  long		current_time;  static long	previous_time=0;  static int	rpc_check=0;  static int	heart_count=0;  static int	elapse_secs=0;  static unsigned  last_log=0;	current_time = (long)time((time_t *)0);  /* get current time of the day */	if ( batch_mode ) {		if ( previous_time == 0 ) /* must be the initial pass */			elapse_secs = 1;		else 			    /* get the elapse seconds */			elapse_secs = current_time - previous_time;		previous_time = current_time; /* save the current time */	}	if (sundiag_done)		return(NOTIFY_DONE);	/* quiting... */	if (running == GO)	{	  elapse_count += current_time - last_elapse; /* increment the elapsed seconds */	  last_elapse = current_time;	  if (log_period != 0)	/* if periodical status log required */	  {	    if (last_log > elapse_count) last_log = elapse_count;	    if ((elapse_count - last_log) >= (log_period*60))  /* time to log */	    {	      last_log += (log_period*60);	      logmsg(period_log_info, 0, PERIOD_LOG_INFO);	      log_status();	      if (send_email==2 || send_email==3)		sd_send_mail();	    }	  }	  else	  {		last_log = elapse_count-1;	  }	  (void)time_display();	/* display elapse time on status sunwindow */	  (void)invoke_tests();	/* periodically start enabled tests */	}	else if (running == KILL) {		(void)check_term();/* check whether all tests are terminated */		if (auto_quit && running == IDLE)    /* all tests are killed */		  kill_proc();			     /* quit from here */		if (batch_mode && running == IDLE)		{			if (batch_ready) {	/* time to load next batch entry */				heart_count = 0;				batch_ready = FALSE;				batch();			}		}	}	if ( schedule_file == TRUE )		sched_proc(elapse_count, current_time);	if (!tty_mode && !no_perfmon)	  perfmon_update();	if ( (ats_nohost == 0) || batch_mode )		heart_count += elapse_secs;	if (!ats_nohost)	{	  if (++rpc_check == 10)	  {	    rpc_check = 0;	    amp_elapsed_time();	/* check the message queue for un-ack'ed msg */	  }	  if (heart_count >= 60)	  {	    heart_count = 0;	    send_pong();	/* send SUNDIAG_ATS_PONG to ATS */	  }	}	if (batch_mode)	{	  if (heart_count >= 60)	  {	    batch_pong(heart_count/60);	/* batch timer */	    heart_count = 0;	  }	}	return(NOTIFY_DONE);}/****************************************************************************** * set_input_notify, to be called to register input-pending event.	      * ******************************************************************************/set_input_notify(){	  (void)notify_set_input_func((Notify_client)client_handle,		handle_input, 0);	/* call "handle_input" when needed */}/****************************************************************************** * unset_input_notify, to be called to unregister input-pending event.	      * ******************************************************************************/unset_input_notify(){	(void)notify_set_input_func((Notify_client)client_handle,		NOTIFY_FUNC_NULL, 0);}/****************************************************************************** * check_sundiag(), check whether sundiag is already running.		      * * return: TRUE, if there is already a copy of Sundiag running.		      * *	   FALSE, if no Sundiag or only copies of remote Sundiag running.     *  ******************************************************************************/static int check_sundiag(){  int	pid;  FILE	*fp;  char	tmp[22];    fp = fopen(SUNDIAG_PID, "r");    if (fp == (FILE *)0) return(FALSE);    else    {	pid = atoi(fgets(tmp, 20, fp));	(void)fclose(fp);	if (kill(pid, 0) == 0) return(TRUE);	/* if it is a valid pid */	(void)unlink(SUNDIAG_PID);		/* remove it for safty sake */	return(FALSE);    }}/****************************************************************************** * sd_send_mail() sends the INFO. Sundiag message file to the specified user( * * defaulted to be "root"). 						      * ******************************************************************************/void	sd_send_mail(){  char	buff[162];  int	pid;  (void)sprintf(buff,"tail -60 /usr/adm/sundiaglog/sundiag.info | /usr/ucb/mail -s \"Sundiag status\" %s", eaddress);  if ((pid=vfork()) == 0)		/* child */  {    (void)execl("/bin/csh", "csh", "-c", buff, (char *)0);    _exit(127);  }  if (pid != -1)			/* succeeded */    (void)notify_set_wait3_func((Notify_client)client_handle,			notify_default_wait3, pid);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -