]> git.saurik.com Git - redis.git/commitdiff
masterauth option merged, thanks to Anthony Lauzon
authorantirez <antirez@gmail.com>
Wed, 4 Nov 2009 08:53:43 +0000 (09:53 +0100)
committerantirez <antirez@gmail.com>
Wed, 4 Nov 2009 08:53:43 +0000 (09:53 +0100)
Makefile
redis.c

index ba3d5009be469df0f43989369b279d85de65f8e0..49d0cb3808b923cbaefd603fd7c39943c97feead 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,10 +7,10 @@ ifeq ($(uname_S),SunOS)
   CFLAGS?= -std=c99 -pedantic -O2 -Wall -W -D__EXTENSIONS__ -D_XPG6
   CCLINK?= -ldl -lnsl -lsocket -lm
 else
-  CFLAGS?= -std=c99 -pedantic -O2 -Wall -W $(ARCH)
+  CFLAGS?= -std=c99 -pedantic -O2 -Wall -W $(ARCH) $(PROF)
   CCLINK?= -lm
 endif
-CCOPT= $(CFLAGS) $(CCLINK) $(ARCH)
+CCOPT= $(CFLAGS) $(CCLINK) $(ARCH) $(PROF)
 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
@@ -71,3 +71,9 @@ log:
 
 32bit:
        make ARCH="-arch i386"
+
+gprof:
+       make PROF="-pg"
+
+32bitgprof:
+       make PROF="-pg" ARCH="-arch i386"
diff --git a/redis.c b/redis.c
index e0e93aadda7cf69217db7131cc7b4d76f8e82e45..21098e56dab98f971bd90cdac40d90a6c28c906a 100644 (file)
--- a/redis.c
+++ b/redis.c
@@ -281,6 +281,7 @@ struct redisServer {
     int shareobjects;
     /* Replication related */
     int isslave;
+    char *masterauth;
     char *masterhost;
     int masterport;
     redisClient *master;    /* client that is master for this slave */
@@ -1052,6 +1053,7 @@ static void initServerConfig() {
     appendServerSaveParams(60,10000); /* save after 1 minute and 10000 changes */
     /* Replication related */
     server.isslave = 0;
+    server.masterauth = NULL;
     server.masterhost = NULL;
     server.masterport = 6379;
     server.master = NULL;
@@ -1230,6 +1232,8 @@ static void loadServerConfig(char *filename) {
             server.masterhost = sdsnew(argv[1]);
             server.masterport = atoi(argv[2]);
             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) {
             if ((server.glueoutputbuf = yesnotoi(argv[1])) == -1) {
                 err = "argument must be 'yes' or 'no'"; goto loaderr;
@@ -5128,7 +5132,7 @@ static void updateSlavesWaitingBgsave(int bgsaveerr) {
 }
 
 static int syncWithMaster(void) {
-    char buf[1024], tmpfile[256];
+    char buf[1024], tmpfile[256], authcmd[1024];
     int dumpsize;
     int fd = anetTcpConnect(NULL,server.masterhost,server.masterport);
     int dfd;
@@ -5138,6 +5142,30 @@ static int syncWithMaster(void) {
             strerror(errno));
         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 */
     if (syncWrite(fd,"SYNC \r\n",7,5) == -1) {
         close(fd);