Skip to content

Commit 23e515d

Browse files
committed
Signals should be returned by syscalls to be able to exit loop
1 parent e881b7c commit 23e515d

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

examples/ocsp_responder/ocsp_responder.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ char* myoptarg = NULL;
8181
#define MAX_CERTS 16
8282

8383
/* Simple logging macro */
84-
#define LOG_ERROR(...) fprintf(stderr, __VA_ARGS__)
84+
#define LOG_ERROR(...) \
85+
do { \
86+
if (got_signal) \
87+
fprintf(stderr, "Shutdown requested, exiting loop\n"); \
88+
else \
89+
fprintf(stderr, __VA_ARGS__); \
90+
} while (0)
8591

8692
#ifndef _WIN32
8793
/* Signal handler flag */
@@ -811,8 +817,14 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
811817

812818
#ifndef _WIN32
813819
/* Install signal handlers for clean shutdown */
814-
signal(SIGTERM, sig_handler);
815-
signal(SIGINT, sig_handler);
820+
{
821+
struct sigaction sa;
822+
memset(&sa, 0, sizeof(sa));
823+
sa.sa_handler = sig_handler;
824+
/* Do NOT set SA_RESTART so accept() is interrupted */
825+
sigaction(SIGTERM, &sa, NULL);
826+
sigaction(SIGINT, &sa, NULL);
827+
}
816828
if (opts.verbose) {
817829
printf("Signal handlers installed\n");
818830
}

0 commit comments

Comments
 (0)