Fix redis_check_rdb() hang when rdb is FIFO (#12022)
When loading RDB over the named piped, redis_check_rdb() is hung at fopen, because fopen blocks until another process opens the FIFO for writing. The fix is to check if RDB is FIFO. If yes, return an error.
This commit is contained in:
parent
4375b01cc7
commit
d5d56d0d95
@ -186,6 +186,12 @@ void rdbCheckSetupSignals(void) {
|
||||
sigaction(SIGABRT, &act, NULL);
|
||||
}
|
||||
|
||||
static int isFifo(char *filename) {
|
||||
struct stat stat_p;
|
||||
stat(filename, &stat_p);
|
||||
return S_ISFIFO(stat_p.st_mode);
|
||||
}
|
||||
|
||||
/* Check the specified RDB file. Return 0 if the RDB looks sane, otherwise
|
||||
* 1 is returned.
|
||||
* The file is specified as a filename in 'rdbfilename' if 'fp' is not NULL,
|
||||
@ -199,6 +205,11 @@ int redis_check_rdb(char *rdbfilename, FILE *fp) {
|
||||
static rio rdb; /* Pointed by global struct riostate. */
|
||||
struct stat sb;
|
||||
|
||||
if (isFifo(rdbfilename)) {
|
||||
/* Cannot check RDB over named pipe because fopen blocks until another process opens the FIFO for writing. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
int closefile = (fp == NULL);
|
||||
if (fp == NULL && (fp = fopen(rdbfilename,"r")) == NULL) return 1;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user