Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
d0ccebcf
Commit
d0ccebcf
authored
Nov 04, 2009
by
antirez
Browse files
masterauth option merged, thanks to Anthony Lauzon
parent
eaa256ad
Changes
2
Show whitespace changes
Inline
Side-by-side
Makefile
View file @
d0ccebcf
...
@@ -7,10 +7,10 @@ ifeq ($(uname_S),SunOS)
...
@@ -7,10 +7,10 @@ ifeq ($(uname_S),SunOS)
CFLAGS
?=
-std
=
c99
-pedantic
-O2
-Wall
-W
-D__EXTENSIONS__
-D_XPG6
CFLAGS
?=
-std
=
c99
-pedantic
-O2
-Wall
-W
-D__EXTENSIONS__
-D_XPG6
CCLINK
?=
-ldl
-lnsl
-lsocket
-lm
CCLINK
?=
-ldl
-lnsl
-lsocket
-lm
else
else
CFLAGS
?=
-std
=
c99
-pedantic
-O2
-Wall
-W
$(ARCH)
CFLAGS
?=
-std
=
c99
-pedantic
-O2
-Wall
-W
$(ARCH)
$(PROF)
CCLINK
?=
-lm
CCLINK
?=
-lm
endif
endif
CCOPT
=
$(CFLAGS)
$(CCLINK)
$(ARCH)
CCOPT
=
$(CFLAGS)
$(CCLINK)
$(ARCH)
$(PROF)
DEBUG
?=
-g
-rdynamic
-ggdb
DEBUG
?=
-g
-rdynamic
-ggdb
OBJ
=
adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o
OBJ
=
adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o
...
@@ -71,3 +71,9 @@ log:
...
@@ -71,3 +71,9 @@ log:
32bit
:
32bit
:
make
ARCH
=
"-arch i386"
make
ARCH
=
"-arch i386"
gprof
:
make
PROF
=
"-pg"
32bitgprof
:
make
PROF
=
"-pg"
ARCH
=
"-arch i386"
redis.c
View file @
d0ccebcf
...
@@ -281,6 +281,7 @@ struct redisServer {
...
@@ -281,6 +281,7 @@ struct redisServer {
int
shareobjects
;
int
shareobjects
;
/* Replication related */
/* Replication related */
int
isslave
;
int
isslave
;
char
*
masterauth
;
char
*
masterhost
;
char
*
masterhost
;
int
masterport
;
int
masterport
;
redisClient
*
master
;
/* client that is master for this slave */
redisClient
*
master
;
/* client that is master for this slave */
...
@@ -1052,6 +1053,7 @@ static void initServerConfig() {
...
@@ -1052,6 +1053,7 @@ static void initServerConfig() {
appendServerSaveParams
(
60
,
10000
);
/* save after 1 minute and 10000 changes */
appendServerSaveParams
(
60
,
10000
);
/* save after 1 minute and 10000 changes */
/* Replication related */
/* Replication related */
server
.
isslave
=
0
;
server
.
isslave
=
0
;
server
.
masterauth
=
NULL
;
server
.
masterhost
=
NULL
;
server
.
masterhost
=
NULL
;
server
.
masterport
=
6379
;
server
.
masterport
=
6379
;
server
.
master
=
NULL
;
server
.
master
=
NULL
;
...
@@ -1230,6 +1232,8 @@ static void loadServerConfig(char *filename) {
...
@@ -1230,6 +1232,8 @@ static void loadServerConfig(char *filename) {
server
.
masterhost
=
sdsnew
(
argv
[
1
]);
server
.
masterhost
=
sdsnew
(
argv
[
1
]);
server
.
masterport
=
atoi
(
argv
[
2
]);
server
.
masterport
=
atoi
(
argv
[
2
]);
server
.
replstate
=
REDIS_REPL_CONNECT
;
server
.
replstate
=
REDIS_REPL_CONNECT
;
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"masterauth"
)
&&
argc
==
2
)
{
server
.
masterauth
=
zstrdup
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"glueoutputbuf"
)
&&
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"glueoutputbuf"
)
&&
argc
==
2
)
{
if
((
server
.
glueoutputbuf
=
yesnotoi
(
argv
[
1
]))
==
-
1
)
{
if
((
server
.
glueoutputbuf
=
yesnotoi
(
argv
[
1
]))
==
-
1
)
{
err
=
"argument must be 'yes' or 'no'"
;
goto
loaderr
;
err
=
"argument must be 'yes' or 'no'"
;
goto
loaderr
;
...
@@ -5128,7 +5132,7 @@ static void updateSlavesWaitingBgsave(int bgsaveerr) {
...
@@ -5128,7 +5132,7 @@ static void updateSlavesWaitingBgsave(int bgsaveerr) {
}
}
static
int
syncWithMaster
(
void
)
{
static
int
syncWithMaster
(
void
)
{
char
buf
[
1024
],
tmpfile
[
256
];
char
buf
[
1024
],
tmpfile
[
256
]
,
authcmd
[
1024
]
;
int
dumpsize
;
int
dumpsize
;
int
fd
=
anetTcpConnect
(
NULL
,
server
.
masterhost
,
server
.
masterport
);
int
fd
=
anetTcpConnect
(
NULL
,
server
.
masterhost
,
server
.
masterport
);
int
dfd
;
int
dfd
;
...
@@ -5138,6 +5142,30 @@ static int syncWithMaster(void) {
...
@@ -5138,6 +5142,30 @@ static int syncWithMaster(void) {
strerror
(
errno
));
strerror
(
errno
));
return
REDIS_ERR
;
return
REDIS_ERR
;
}
}
/* AUTH with the master if required. */
if
(
server
.
masterauth
)
{
snprintf
(
authcmd
,
1024
,
"AUTH %s
\r\n
"
,
server
.
masterauth
);
if
(
syncWrite
(
fd
,
authcmd
,
strlen
(
server
.
masterauth
)
+
7
,
5
)
==
-
1
)
{
close
(
fd
);
redisLog
(
REDIS_WARNING
,
"Unable to AUTH to MASTER: %s"
,
strerror
(
errno
));
return
REDIS_ERR
;
}
/* Read the AUTH result. */
if
(
syncReadLine
(
fd
,
buf
,
1024
,
3600
)
==
-
1
)
{
close
(
fd
);
redisLog
(
REDIS_WARNING
,
"I/O error reading auth result from MASTER: %s"
,
strerror
(
errno
));
return
REDIS_ERR
;
}
if
(
buf
[
0
]
!=
'+'
)
{
close
(
fd
);
redisLog
(
REDIS_WARNING
,
"Cannot AUTH to MASTER, is the masterauth password correct?"
);
return
REDIS_ERR
;
}
}
/* Issue the SYNC command */
/* Issue the SYNC command */
if
(
syncWrite
(
fd
,
"SYNC
\r\n
"
,
7
,
5
)
==
-
1
)
{
if
(
syncWrite
(
fd
,
"SYNC
\r\n
"
,
7
,
5
)
==
-
1
)
{
close
(
fd
);
close
(
fd
);
...
...
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