mirror of
				https://github.com/Zygo/bees.git
				synced 2025-10-31 10:10:34 +01:00 
			
		
		
		
	process: ntoa function for signals
This enables signal numbers to be translated to names. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
		| @@ -77,5 +77,7 @@ namespace crucible { | ||||
| 	double getloadavg1(); | ||||
| 	double getloadavg5(); | ||||
| 	double getloadavg15(); | ||||
|  | ||||
| 	string signal_ntoa(int sig); | ||||
| } | ||||
| #endif // CRUCIBLE_PROCESS_H | ||||
|   | ||||
| @@ -2,6 +2,7 @@ | ||||
|  | ||||
| #include "crucible/chatter.h" | ||||
| #include "crucible/error.h" | ||||
| #include "crucible/ntoa.h" | ||||
|  | ||||
| #include <cstdlib> | ||||
| #include <utility> | ||||
| @@ -152,4 +153,76 @@ namespace crucible { | ||||
| 		return loadavg[2]; | ||||
| 	} | ||||
|  | ||||
| 	static const struct bits_ntoa_table signals_table[] = { | ||||
|  | ||||
| 		// POSIX.1-1990 | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGHUP), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGINT), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGQUIT), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGILL), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGABRT), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGFPE), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGKILL), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGSEGV), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGPIPE), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGALRM), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGTERM), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGUSR1), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGUSR2), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGCHLD), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGCONT), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGSTOP), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGTSTP), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGTTIN), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGTTOU), | ||||
|  | ||||
| 		// SUSv2 and POSIX.1-2001 | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGBUS), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGPOLL), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGPROF), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGSYS), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGTRAP), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGURG), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGVTALRM), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGXCPU), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGXFSZ), | ||||
|  | ||||
| 		// Other | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGIOT), | ||||
| #ifdef SIGEMT | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGEMT), | ||||
| #endif | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGSTKFLT), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGIO), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGCLD), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGPWR), | ||||
| #ifdef SIGINFO | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGINFO), | ||||
| #endif | ||||
| #ifdef SIGLOST | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGLOST), | ||||
| #endif | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGWINCH), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGUNUSED), | ||||
|  | ||||
| 		// realtime | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGRTMIN), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGRTMIN+1U), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGRTMIN+2U), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGRTMIN+3U), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGRTMIN+4U), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGRTMIN+5U), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGRTMIN+6U), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGRTMIN+7U), | ||||
| 		NTOA_TABLE_ENTRY_ENUM(SIGRTMAX), | ||||
|  | ||||
| 		NTOA_TABLE_ENTRY_END(), | ||||
| 	}; | ||||
|  | ||||
| 	string | ||||
| 	signal_ntoa(int sig) | ||||
| 	{ | ||||
| 		return bits_ntoa(sig, signals_table); | ||||
| 	} | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user