mirror of
				https://github.com/tiagovignatti/intel-gpu-tools.git
				synced 2025-11-03 19:47:15 +00:00 
			
		
		
		
	lib: print the signal name to stderr when handling a signal
Print the received signal name to stderr when handling a signal. This uses an array of handled signal names since strsignal() only provides descriptions. Signed-off-by: Thomas Wood <thomas.wood@intel.com>
This commit is contained in:
		
							parent
							
								
									aecad4fc2e
								
							
						
					
					
						commit
						4ff4ea601a
					
				@ -1303,8 +1303,10 @@ static struct {
 | 
				
			|||||||
static igt_exit_handler_t exit_handler_fn[MAX_EXIT_HANDLERS];
 | 
					static igt_exit_handler_t exit_handler_fn[MAX_EXIT_HANDLERS];
 | 
				
			||||||
static bool exit_handler_disabled;
 | 
					static bool exit_handler_disabled;
 | 
				
			||||||
static sigset_t saved_sig_mask;
 | 
					static sigset_t saved_sig_mask;
 | 
				
			||||||
static const int handled_signals[] =
 | 
					#define SIGDEF(x) { x, #x, sizeof(#x) - 1 }
 | 
				
			||||||
	{ SIGINT, SIGHUP, SIGTERM, SIGQUIT, SIGPIPE, SIGABRT, SIGSEGV, SIGBUS };
 | 
					static const struct { int number; const char *name; size_t name_len; } handled_signals[] =
 | 
				
			||||||
 | 
						{ SIGDEF(SIGINT), SIGDEF(SIGHUP), SIGDEF(SIGTERM), SIGDEF(SIGQUIT),
 | 
				
			||||||
 | 
						  SIGDEF(SIGPIPE), SIGDEF(SIGABRT), SIGDEF(SIGSEGV), SIGDEF(SIGBUS) };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int install_sig_handler(int sig_num, sighandler_t handler)
 | 
					static int install_sig_handler(int sig_num, sighandler_t handler)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -1357,8 +1359,20 @@ static void igt_atexit_handler(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void fatal_sig_handler(int sig)
 | 
					static void fatal_sig_handler(int sig)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	restore_all_sig_handler();
 | 
						restore_all_sig_handler();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; i < ARRAY_SIZE(handled_signals); i++) {
 | 
				
			||||||
 | 
							if (handled_signals[i].number == sig) {
 | 
				
			||||||
 | 
								write(STDERR_FILENO, "Received signal ", 16);
 | 
				
			||||||
 | 
								write(STDERR_FILENO, handled_signals[i].name,
 | 
				
			||||||
 | 
								      handled_signals[i].name_len);
 | 
				
			||||||
 | 
								write(STDERR_FILENO, ".\n", 2);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * exit_handler_disabled is always false here, since when we set it
 | 
						 * exit_handler_disabled is always false here, since when we set it
 | 
				
			||||||
	 * we also block signals.
 | 
						 * we also block signals.
 | 
				
			||||||
@ -1415,7 +1429,7 @@ void igt_install_exit_handler(igt_exit_handler_t fn)
 | 
				
			|||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < ARRAY_SIZE(handled_signals); i++) {
 | 
						for (i = 0; i < ARRAY_SIZE(handled_signals); i++) {
 | 
				
			||||||
		if (install_sig_handler(handled_signals[i],
 | 
							if (install_sig_handler(handled_signals[i].number,
 | 
				
			||||||
					fatal_sig_handler))
 | 
										fatal_sig_handler))
 | 
				
			||||||
			goto err;
 | 
								goto err;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -1447,7 +1461,7 @@ void igt_disable_exit_handler(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	sigemptyset(&set);
 | 
						sigemptyset(&set);
 | 
				
			||||||
	for (i = 0; i < ARRAY_SIZE(handled_signals); i++)
 | 
						for (i = 0; i < ARRAY_SIZE(handled_signals); i++)
 | 
				
			||||||
		sigaddset(&set, handled_signals[i]);
 | 
							sigaddset(&set, handled_signals[i].number);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (sigprocmask(SIG_BLOCK, &set, &saved_sig_mask)) {
 | 
						if (sigprocmask(SIG_BLOCK, &set, &saved_sig_mask)) {
 | 
				
			||||||
		perror("sigprocmask");
 | 
							perror("sigprocmask");
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user