libimobiledevice / idevicerestore

Restore/upgrade firmware of iOS devices
https://libimobiledevice.org
GNU Lesser General Public License v3.0
1.24k stars 387 forks source link

Using sigaction won't compile on Windows #283

Open taanders opened 4 years ago

taanders commented 4 years ago

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

    signal(SIGINT, handle_signal);
    signal(SIGTERM, handle_signal);
    signal(SIGABRT, handle_signal)
taanders commented 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
akhileshkrsingh1 commented 1 month ago

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.