mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
Don't rely on cliReadReply being able to return on shutdown
This commit is contained in:
parent
a57d9cc437
commit
36e5db6d24
13
redis-cli.c
13
redis-cli.c
@ -54,6 +54,7 @@ static struct config {
|
|||||||
long repeat;
|
long repeat;
|
||||||
int dbnum;
|
int dbnum;
|
||||||
int interactive;
|
int interactive;
|
||||||
|
int shutdown;
|
||||||
int monitor_mode;
|
int monitor_mode;
|
||||||
int pubsub_mode;
|
int pubsub_mode;
|
||||||
int raw_output;
|
int raw_output;
|
||||||
@ -313,7 +314,10 @@ static int cliReadMultiBulkReply(int fd) {
|
|||||||
static int cliReadReply(int fd) {
|
static int cliReadReply(int fd) {
|
||||||
char type;
|
char type;
|
||||||
|
|
||||||
if (anetRead(fd,&type,1) <= 0) exit(1);
|
if (anetRead(fd,&type,1) <= 0) {
|
||||||
|
if (config.shutdown) return 0;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case '-':
|
case '-':
|
||||||
printf("(error) ");
|
printf("(error) ");
|
||||||
@ -356,7 +360,6 @@ static int selectDb(int fd) {
|
|||||||
|
|
||||||
static int cliSendCommand(int argc, char **argv, int repeat) {
|
static int cliSendCommand(int argc, char **argv, int repeat) {
|
||||||
struct redisCommand *rc = lookupCommand(argv[0]);
|
struct redisCommand *rc = lookupCommand(argv[0]);
|
||||||
int shutdown = 0;
|
|
||||||
int fd, j, retval = 0;
|
int fd, j, retval = 0;
|
||||||
sds cmd;
|
sds cmd;
|
||||||
|
|
||||||
@ -372,7 +375,7 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcasecmp(rc->name,"shutdown")) shutdown = 1;
|
if (!strcasecmp(rc->name,"shutdown")) config.shutdown = 1;
|
||||||
if (!strcasecmp(rc->name,"monitor")) config.monitor_mode = 1;
|
if (!strcasecmp(rc->name,"monitor")) config.monitor_mode = 1;
|
||||||
if (!strcasecmp(rc->name,"subscribe") ||
|
if (!strcasecmp(rc->name,"subscribe") ||
|
||||||
!strcasecmp(rc->name,"psubscribe")) config.pubsub_mode = 1;
|
!strcasecmp(rc->name,"psubscribe")) config.pubsub_mode = 1;
|
||||||
@ -410,8 +413,9 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
retval = cliReadReply(fd);
|
retval = cliReadReply(fd);
|
||||||
|
|
||||||
if (retval) {
|
if (retval) {
|
||||||
return shutdown ? 0 : retval;
|
return retval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -594,6 +598,7 @@ int main(int argc, char **argv) {
|
|||||||
config.hostport = 6379;
|
config.hostport = 6379;
|
||||||
config.repeat = 1;
|
config.repeat = 1;
|
||||||
config.dbnum = 0;
|
config.dbnum = 0;
|
||||||
|
config.shutdown = 0;
|
||||||
config.interactive = 0;
|
config.interactive = 0;
|
||||||
config.monitor_mode = 0;
|
config.monitor_mode = 0;
|
||||||
config.pubsub_mode = 0;
|
config.pubsub_mode = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user