Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
e1633328
Commit
e1633328
authored
Feb 23, 2014
by
Salvatore Sanfilippo
Browse files
Merge pull request #1545 from mattsta/fix-redis-cli-sync
Deny SYNC and PSYNC in redis-cli
parents
b1c13863
21648473
Changes
1
Show whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
e1633328
...
@@ -94,6 +94,7 @@ static struct config {
...
@@ -94,6 +94,7 @@ static struct config {
}
config
;
}
config
;
static
void
usage
();
static
void
usage
();
static
void
slaveMode
(
void
);
char
*
redisGitSHA1
(
void
);
char
*
redisGitSHA1
(
void
);
char
*
redisGitDirty
(
void
);
char
*
redisGitDirty
(
void
);
...
@@ -600,6 +601,8 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
...
@@ -600,6 +601,8 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
if
(
!
strcasecmp
(
command
,
"monitor"
))
config
.
monitor_mode
=
1
;
if
(
!
strcasecmp
(
command
,
"monitor"
))
config
.
monitor_mode
=
1
;
if
(
!
strcasecmp
(
command
,
"subscribe"
)
||
if
(
!
strcasecmp
(
command
,
"subscribe"
)
||
!
strcasecmp
(
command
,
"psubscribe"
))
config
.
pubsub_mode
=
1
;
!
strcasecmp
(
command
,
"psubscribe"
))
config
.
pubsub_mode
=
1
;
if
(
!
strcasecmp
(
command
,
"sync"
)
||
!
strcasecmp
(
command
,
"psync"
))
config
.
slave_mode
=
1
;
/* Setup argument length */
/* Setup argument length */
argvlen
=
malloc
(
argc
*
sizeof
(
size_t
));
argvlen
=
malloc
(
argc
*
sizeof
(
size_t
));
...
@@ -621,6 +624,13 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
...
@@ -621,6 +624,13 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
}
}
}
}
if
(
config
.
slave_mode
)
{
printf
(
"Entering slave output mode... (press Ctrl-C to quit)
\n
"
);
slaveMode
();
config
.
slave_mode
=
0
;
return
REDIS_ERR
;
/* Error = slaveMode lost connection to master */
}
if
(
cliReadReply
(
output_raw
)
!=
REDIS_OK
)
{
if
(
cliReadReply
(
output_raw
)
!=
REDIS_OK
)
{
free
(
argvlen
);
free
(
argvlen
);
return
REDIS_ERR
;
return
REDIS_ERR
;
...
@@ -1061,6 +1071,7 @@ static void slaveMode(void) {
...
@@ -1061,6 +1071,7 @@ static void slaveMode(void) {
int
fd
=
context
->
fd
;
int
fd
=
context
->
fd
;
unsigned
long
long
payload
=
sendSync
(
fd
);
unsigned
long
long
payload
=
sendSync
(
fd
);
char
buf
[
1024
];
char
buf
[
1024
];
int
original_output
=
config
.
output
;
fprintf
(
stderr
,
"SYNC with master, discarding %llu "
fprintf
(
stderr
,
"SYNC with master, discarding %llu "
"bytes of bulk transfer...
\n
"
,
payload
);
"bytes of bulk transfer...
\n
"
,
payload
);
...
@@ -1081,6 +1092,7 @@ static void slaveMode(void) {
...
@@ -1081,6 +1092,7 @@ static void slaveMode(void) {
/* Now we can use hiredis to read the incoming protocol. */
/* Now we can use hiredis to read the incoming protocol. */
config
.
output
=
OUTPUT_CSV
;
config
.
output
=
OUTPUT_CSV
;
while
(
cliReadReply
(
0
)
==
REDIS_OK
);
while
(
cliReadReply
(
0
)
==
REDIS_OK
);
config
.
output
=
original_output
;
}
}
/* This function implements --rdb, so it uses the replication protocol in order
/* This function implements --rdb, so it uses the replication protocol in order
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment