mirror of
https://github.com/fluencelabs/redis
synced 2025-03-17 16:10:50 +00:00
Merge pull request #126 from florean/unstable
Unlink Unix socket file on shutdown
This commit is contained in:
commit
70cb03e172
@ -34,6 +34,7 @@ port 6379
|
||||
# on a unix socket when not specified.
|
||||
#
|
||||
# unixsocket /tmp/redis.sock
|
||||
# unixsocketperm 755
|
||||
|
||||
# Close the connection after a client is idle for N seconds (0 to disable)
|
||||
timeout 300
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
@ -291,7 +292,7 @@ int anetTcpServer(char *err, int port, char *bindaddr)
|
||||
return s;
|
||||
}
|
||||
|
||||
int anetUnixServer(char *err, char *path)
|
||||
int anetUnixServer(char *err, char *path, mode_t perm)
|
||||
{
|
||||
int s;
|
||||
struct sockaddr_un sa;
|
||||
@ -304,6 +305,8 @@ int anetUnixServer(char *err, char *path)
|
||||
strncpy(sa.sun_path,path,sizeof(sa.sun_path)-1);
|
||||
if (anetListen(err,s,(struct sockaddr*)&sa,sizeof(sa)) == ANET_ERR)
|
||||
return ANET_ERR;
|
||||
if (perm)
|
||||
chmod(sa.sun_path, perm);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ int anetUnixNonBlockConnect(char *err, char *path);
|
||||
int anetRead(int fd, char *buf, int count);
|
||||
int anetResolve(char *err, char *host, char *ipbuf);
|
||||
int anetTcpServer(char *err, int port, char *bindaddr);
|
||||
int anetUnixServer(char *err, char *path);
|
||||
int anetUnixServer(char *err, char *path, mode_t perm);
|
||||
int anetTcpAccept(char *err, int serversock, char *ip, int *port);
|
||||
int anetUnixAccept(char *err, int serversock);
|
||||
int anetWrite(int fd, char *buf, int count);
|
||||
|
@ -73,6 +73,11 @@ void loadServerConfig(char *filename) {
|
||||
server.bindaddr = zstrdup(argv[1]);
|
||||
} else if (!strcasecmp(argv[0],"unixsocket") && argc == 2) {
|
||||
server.unixsocket = zstrdup(argv[1]);
|
||||
} else if (!strcasecmp(argv[0],"unixsocketperm") && argc == 2) {
|
||||
server.unixsocketperm = (mode_t)strtol(argv[1], NULL, 8);
|
||||
if (errno || server.unixsocketperm > 0777) {
|
||||
err = "Invalid socket file permissions"; goto loaderr;
|
||||
}
|
||||
} else if (!strcasecmp(argv[0],"save") && argc == 3) {
|
||||
int seconds = atoi(argv[1]);
|
||||
int changes = atoi(argv[2]);
|
||||
|
@ -822,6 +822,7 @@ void initServerConfig() {
|
||||
server.port = REDIS_SERVERPORT;
|
||||
server.bindaddr = NULL;
|
||||
server.unixsocket = NULL;
|
||||
server.unixsocketperm = 0;
|
||||
server.ipfd = -1;
|
||||
server.sofd = -1;
|
||||
server.dbnum = REDIS_DEFAULT_DBNUM;
|
||||
@ -935,7 +936,7 @@ void initServer() {
|
||||
}
|
||||
if (server.unixsocket != NULL) {
|
||||
unlink(server.unixsocket); /* don't care if this fails */
|
||||
server.sofd = anetUnixServer(server.neterr,server.unixsocket);
|
||||
server.sofd = anetUnixServer(server.neterr,server.unixsocket,server.unixsocketperm);
|
||||
if (server.sofd == ANET_ERR) {
|
||||
redisLog(REDIS_WARNING, "Opening socket: %s", server.neterr);
|
||||
exit(1);
|
||||
@ -1236,6 +1237,10 @@ int prepareForShutdown() {
|
||||
/* Close the listening sockets. Apparently this allows faster restarts. */
|
||||
if (server.ipfd != -1) close(server.ipfd);
|
||||
if (server.sofd != -1) close(server.sofd);
|
||||
if (server.unixsocket) {
|
||||
redisLog(REDIS_NOTICE,"Removing the unix socket file.");
|
||||
unlink(server.unixsocket); /* don't care if this fails */
|
||||
}
|
||||
|
||||
redisLog(REDIS_WARNING,"Redis is now ready to exit, bye bye...");
|
||||
return REDIS_OK;
|
||||
|
@ -515,6 +515,7 @@ struct redisServer {
|
||||
int port;
|
||||
char *bindaddr;
|
||||
char *unixsocket;
|
||||
mode_t unixsocketperm;
|
||||
int ipfd;
|
||||
int sofd;
|
||||
int cfd;
|
||||
|
Loading…
x
Reference in New Issue
Block a user