Set 'loading' and 'shutdown_asap' to volatile sig_atomic_t type (#7845)

We may access and modify these two variables in signal handler function,
to guarantee them async-signal-safe, so we should set them to volatile
sig_atomic_t type.

It doesn't look like this could have caused any real issue, and it seems that
signals are handled in main thread on most platforms. But we want to follow C
and POSIX standard in signal handler function.

(cherry picked from commit f1863a1fe760610cebfd1c121623a3c12a79d600)
This commit is contained in:
Wang Yuan 2020-09-25 21:25:47 +08:00 committed by Oran Agra
parent 90555566ed
commit 5d1ac2df64

View File

@ -1069,7 +1069,7 @@ struct redisServer {
dict *orig_commands; /* Command table before command renaming. */
aeEventLoop *el;
_Atomic unsigned int lruclock; /* Clock for LRU eviction */
int shutdown_asap; /* SHUTDOWN needed ASAP */
volatile sig_atomic_t shutdown_asap; /* SHUTDOWN needed ASAP */
int activerehashing; /* Incremental rehash in serverCron() */
int active_defrag_running; /* Active defragmentation running (holds current scan aggressiveness) */
char *pidfile; /* PID file path */
@ -1126,7 +1126,7 @@ struct redisServer {
long long events_processed_while_blocked; /* processEventsWhileBlocked() */
/* RDB / AOF loading information */
int loading; /* We are loading data from disk if true */
volatile sig_atomic_t loading; /* We are loading data from disk if true */
off_t loading_total_bytes;
off_t loading_loaded_bytes;
time_t loading_start_time;