Open taanders opened 4 years ago
Something like this may work:
#ifdef WIN32
signal(SIGINT, handle_signal);
signal(SIGTERM, handle_signal);
signal(SIGABRT, handle_signal);
#else
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = handle_signal;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sa, NULL);
#endif
You're correct. sigaction is typically used in Unix-like systems (such as Linux, macOS, etc.) for handling signals. Windows doesn't use signals in the same way Unix does, so sigaction isn't available on Windows.
On Windows, you'd typically use different mechanisms for similar purposes, such as Windows signals or structured exception handling (SEH). For example, you might use SetUnhandledExceptionFilter to catch unhandled exceptions.
Using sigaction won't compile on Windows: https://github.com/libimobiledevice/idevicerestore/commit/3050e61588bfc79b3b360fa25db32c81e3264efb
I think it needs to be done like this way on Windows side: https://stackoverflow.com/questions/32389905/sigaction-and-porting-linux-code-to-windows