📄 sdrtns.c
字号:
} /****************************************************************************** * exception(), catches the signals, which otherwise may cause a core dump. * * Note: used by executing signal(SIGNAME, exception) if core_file == FALSE. * ******************************************************************************//*ARGSUSED*/#ifdef SVR4void exception(sig)int sig ;#elsevoid exception(sig, code, scp, addr)int sig; /* the signal number */int code;struct sigcontext *scp;char *addr;#endif SVR4{ char *core_msg; switch (sig) { case SIGILL: core_msg = "illegal instruction"; break; case SIGTRAP: core_msg = "trace trap"; break; case SIGEMT: core_msg = "emulator trap"; break; case SIGFPE: core_msg = "arithmetic exception"; break; case SIGBUS: core_msg = "bus error"; break; case SIGSEGV: core_msg = "segmentation violation"; break; case SIGSYS: core_msg = "bad argument to system call"; break; default: core_msg = "unknown exception signal"; break; }# ifdef SVR4 (void)sprintf(msg_buf,"%s(%d)", core_msg,sig);# else (void)sprintf(msg_buf,"%s(%d), code= %d, Address= 0x%lx", core_msg, sig, code, (unsigned long)addr);# endif SVR4 send_message(EXCEPTION_RETURN, FATAL, msg_buf);}/****************************************************************************** * finish(), the signal handler for SIGHUP, SIGTERM, and SIGINT. * * Note: This function should be the signal handler for SIGHUP, SIGTERM, and * * SIGINT for all tests to be executed by Sundiag. clean_up() needs * * to be coded and declared external in the test code to do any * * necessary clean ups before exiting. * ******************************************************************************/void finish(){ clean_up(); /* clean up the mess before exit */ exit(INTERRUPT_RETURN); /* INTERRUPT_RETURN is not an error */}/**************************************************************************** NAME: display_usage - display sundiag command line usage for on-line mode. SYNOPSIS: (void) display_usage(rtn_usage) ARGUMENTS: Input: char *rtn_usage - test command line string. DESCRIPTION: display_usage is required for every test code. RETURN VALUE: void GLOBAL: send_message()*****************************************************************************/void display_usage(rtn_usage)char *rtn_usage;{ (void)sprintf(msg_buf, "\nUsage: %s %s%s[s] [c] [p] [r] [q] [u] [v] [d] [t] [h hostname]\n", test_name, rtn_usage != NULL ? rtn_usage : "", rtn_usage != NULL ? " " : ""); send_message (0, CONSOLE, msg_buf);}/**************************************************************************** NAME: standard_usage - display the general usage of Sundiag command lines. SYNOPSIS: void standard_usage() DESCRIPTION: This standard usage of Sundiag command lines is required for every test code; test programmers should accordinglin provide relative command features in their test codes. RETURN VALUE: void GLOBAL: send_message()*****************************************************************************/void standard_usage(){ (void) sprintf(msg_buf, "\nStandard arguments:\n\ s = sundiag mode\n\ c = enable core file\n\ p = single pass\n\ r = run on error\n\ q = quick test\n\ u = list usage\n\ v = verbose mode\n\ d = debug mode\n\ t = trace mode\n\ h hostname = RPC hostname\n\n"); send_message (0, CONSOLE, msg_buf);}/*************************************************************************** test_init(), paired with test_end() to construct Sundiag main code. This simplifies the sundiag test code a lot and relieve most of sundiag chore off the programmer. argc, argv: unix standard input arguments. process_test_args: pointer to function that processes test-specific command line arguments. routine_usage: pointer to function that explains test-specific command arguments. test_usage_msg: pointer to string that contains the general usage of the test command.***************************************************************************/ void test_init(argc, argv, process_test_args, routine_usage, test_usage_msg)int argc;char *argv[];int (*process_test_args)();int (*routine_usage)();char *test_usage_msg;{ int argindex; extern void check_usage(); extern void check_coredump(); extern int check_default(); test_name = argv[0]; test_id = get_test_id(test_name, testname_list); version_id = get_sccs_version (versionid); (void)signal(SIGHUP, finish); (void)signal(SIGTERM, finish); (void)signal(SIGINT, finish); if (argc > 1) { for (argindex = 1; argindex < argc; argindex++) { if (!process_sundiag_args(argc, argv, &argindex)) { if (!process_test_args(argv, argindex)) { display_usage(test_usage_msg); send_message(USAGE_ERROR, ERROR, "Invalid command argument: %s", argv[argindex]); } } check_usage(routine_usage, test_usage_msg); } } else if (check_default(test_usage_msg)) ; else { display_usage (test_usage_msg); exit (USAGE_ERROR); } check_coredump(); sprintf(msg_buf, "%s: Started.\n", test_name); if (verbose) send_message(0, CONSOLE, msg_buf); /* can't use VERBOSE as no way to identify device_name till now */ /* Indicates "started" at very beginning of each test */}/************************************************************************** test_end(), Sundiag test code enclosure routine. Always use this routine to leave Sundiag. This routine will be expanded to do some work more general to Sundiag for visual or statistical purpose. ***************************************************************************/void test_end(){ if (test_error > 0) { if (!exec_by_sundiag) sprintf(msg_buf, "%s: Stopped with errors.", test_name); else sprintf(msg_buf, "Stopped with errors."); } else { if (!exec_by_sundiag) sprintf(msg_buf, "%s: Stopped successfully.", test_name); else sprintf(msg_buf, "Stopped successfully."); } send_message(0, VERBOSE, msg_buf); if (run_on_error && test_error >0) exit(FREERUN_ERROR); else exit(0);} /**************************************************************************** NAME: check_default() Used by test_init() to check any requirement for routine-specific arguments. ASRGUMENTS: input: test_usage_msg - pointer to string that contains the general usage of the test command line. RETURN VALUE: TRUE if test_usage_msg is (char *NULL), or NULL. *****************************************************************************/int check_default(test_usage_msg)char *test_usage_msg;{ return ((test_usage_msg == NULL || *test_usage_msg == NULL)? TRUE : FALSE);}/**************************************************************************** * check_usage() Used by test_init() to display test_usage_msg, standard_usage and routine_usage for 'u' flag set in test command line. routine_usage: pointer to function that explains test-specific command arguments. test_usage_msg: pointer to string that contains the general usage of the test command line. ****************************************************************************/void check_usage(routine_usage, test_usage_msg)int (*routine_usage)();char *test_usage_msg;{ if (list_usage) { display_usage(test_usage_msg); standard_usage(); routine_usage(); exit(0); }} /**************************************************************************** * check_coredump(), used by test_init() to catch some signals to * provent core dump.*****************************************************************************/void check_coredump(){#ifdef SVR4extern void exception(int); if (!core_file) { (void)signal(SIGILL, exception); (void)signal(SIGBUS, exception); (void)signal(SIGSEGV, exception); }#elseextern void exception(); if (!core_file) { (void)signal(SIGILL, exception); (void)signal(SIGBUS, exception); (void)signal(SIGSEGV, exception); }#endif SVR4}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -