From 917043fa438d9bbe9a80fb838fcfd33a7e390952 Mon Sep 17 00:00:00 2001 From: Wang Yuan Date: Fri, 25 Sep 2020 21:25:47 +0800 Subject: [PATCH] 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. --- src/server.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server.h b/src/server.h index 5c266f61d..b920e1f4c 100644 --- a/src/server.h +++ b/src/server.h @@ -1072,7 +1072,7 @@ struct redisServer { dict *orig_commands; /* Command table before command renaming. */ aeEventLoop *el; redisAtomic 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 */ @@ -1129,7 +1129,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;