fix global variables for signal.

This commit is contained in:
tezc 2021-01-20 06:53:13 +03:00
parent 0d8cfd3130
commit aa3da7d73f
2 changed files with 22 additions and 5 deletions

View File

@ -33,6 +33,24 @@
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32)
#include <WinSock2.h>
volatile SOCKET sc_signal_shutdown_fd;
#else
volatile sig_atomic_t sc_signal_shutdown_fd;
#endif
/**
* Set log file fd here, logging will be redirected to this fd, otherwise
* STDERR_FILENO or STDOUT_FILENO will be used.
*/
volatile sig_atomic_t sc_signal_log_fd;
/**
* Internal variable to handle twice shutdown signal.
*/
volatile sig_atomic_t sc_signal_will_shutdown;
#define get_uint(va, size) \
(size) == 3 ? va_arg(va, unsigned long long) : \
(size) == 2 ? va_arg(va, unsigned long) : \
@ -482,4 +500,3 @@ void sc_signal_log(int fd, char *buf, size_t len, char *fmt, ...)
(void) write(fd, buf, written);
}

View File

@ -37,21 +37,21 @@
*/
#if defined(_WIN32)
#include <WinSock2.h>
volatile SOCKET sc_signal_shutdown_fd;
extern volatile SOCKET sc_signal_shutdown_fd;
#else
volatile sig_atomic_t sc_signal_shutdown_fd;
extern volatile sig_atomic_t sc_signal_shutdown_fd;
#endif
/**
* Set log file fd here, logging will be redirected to this fd, otherwise
* STDERR_FILENO or STDOUT_FILENO will be used.
*/
volatile sig_atomic_t sc_signal_log_fd;
extern volatile sig_atomic_t sc_signal_log_fd;
/**
* Internal variable to handle twice shutdown signal.
*/
volatile sig_atomic_t sc_signal_will_shutdown;
extern volatile sig_atomic_t sc_signal_will_shutdown;
/**
* Init signal handler, hooks for shutdown signals and some fatal signals.