summaryrefslogtreecommitdiff
path: root/src/redis-cli.c
diff options
context:
space:
mode:
authorOzan Tezcan <ozantezcan@gmail.com>2022-03-21 14:40:02 +0300
committerGitHub <noreply@github.com>2022-03-21 13:40:02 +0200
commit4517fadb59f40f1244ce110b6c9963d5b811df18 (patch)
tree3525e31bf69c6b2ccbeeff3f78740cbce2c0ab77 /src/redis-cli.c
parente82c1aedeaa7aee8c6290d6ceaafb347996eb671 (diff)
downloadredis-4517fadb59f40f1244ce110b6c9963d5b811df18.tar.gz
Use exit code 1 if redis-cli fails to connect (#10438)
Use exit code 1 if redis-cli fails to connect. Before https://github.com/redis/redis/pull/10382/, on a connection failure, exit code would be 1. After this PR, whether connection is established or not, `noninteractive()` return value is used as the exit code. On a failure, this function returns `REDIS_ERR` which is `-1`. It becomes `255` as exit codes are between `0-255`. There is nothing wrong by returning 1 or 255 on failure as far as I know but it'll break things that expect to see 1 as exit code on a connection failure. This is also how we realized the issue. With this PR, changing behavior back to using 1 as exit code to preserve backward compatibility.
Diffstat (limited to 'src/redis-cli.c')
-rw-r--r--src/redis-cli.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index e06e6af8a..0c003a0dc 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -9044,7 +9044,11 @@ int main(int argc, char **argv) {
if (cliConnect(0) != REDIS_OK) exit(1);
return evalMode(argc,argv);
} else {
- cliConnect(CC_QUIET);
- return noninteractive(argc,argv);
+ int connected = (cliConnect(CC_QUIET) == REDIS_OK);
+ /* Try to serve command even we are not connected. e.g. help command */
+ int retval = noninteractive(argc,argv);
+ /* If failed to connect, exit with "1" for backward compatibility */
+ if (retval != REDIS_OK && !connected) exit(1);
+ return retval;
}
}