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
70cb03e1
Commit
70cb03e1
authored
Oct 10, 2011
by
Salvatore Sanfilippo
Browse files
Merge pull request #126 from florean/unstable
Unlink Unix socket file on shutdown
parents
d83eda48
85238765
Changes
6
Show whitespace changes
Inline
Side-by-side
redis.conf
View file @
70cb03e1
...
@@ -34,6 +34,7 @@ port 6379
...
@@ -34,6 +34,7 @@ port 6379
# on a unix socket when not specified.
# on a unix socket when not specified.
#
#
# unixsocket /tmp/redis.sock
# unixsocket /tmp/redis.sock
# unixsocketperm 755
# Close the connection after a client is idle for N seconds (0 to disable)
# Close the connection after a client is idle for N seconds (0 to disable)
timeout
300
timeout
300
...
...
src/anet.c
View file @
70cb03e1
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#include <sys/types.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/tcp.h>
...
@@ -291,7 +292,7 @@ int anetTcpServer(char *err, int port, char *bindaddr)
...
@@ -291,7 +292,7 @@ int anetTcpServer(char *err, int port, char *bindaddr)
return
s
;
return
s
;
}
}
int
anetUnixServer
(
char
*
err
,
char
*
path
)
int
anetUnixServer
(
char
*
err
,
char
*
path
,
mode_t
perm
)
{
{
int
s
;
int
s
;
struct
sockaddr_un
sa
;
struct
sockaddr_un
sa
;
...
@@ -304,6 +305,8 @@ int anetUnixServer(char *err, char *path)
...
@@ -304,6 +305,8 @@ int anetUnixServer(char *err, char *path)
strncpy
(
sa
.
sun_path
,
path
,
sizeof
(
sa
.
sun_path
)
-
1
);
strncpy
(
sa
.
sun_path
,
path
,
sizeof
(
sa
.
sun_path
)
-
1
);
if
(
anetListen
(
err
,
s
,(
struct
sockaddr
*
)
&
sa
,
sizeof
(
sa
))
==
ANET_ERR
)
if
(
anetListen
(
err
,
s
,(
struct
sockaddr
*
)
&
sa
,
sizeof
(
sa
))
==
ANET_ERR
)
return
ANET_ERR
;
return
ANET_ERR
;
if
(
perm
)
chmod
(
sa
.
sun_path
,
perm
);
return
s
;
return
s
;
}
}
...
...
src/anet.h
View file @
70cb03e1
...
@@ -46,7 +46,7 @@ int anetUnixNonBlockConnect(char *err, char *path);
...
@@ -46,7 +46,7 @@ int anetUnixNonBlockConnect(char *err, char *path);
int
anetRead
(
int
fd
,
char
*
buf
,
int
count
);
int
anetRead
(
int
fd
,
char
*
buf
,
int
count
);
int
anetResolve
(
char
*
err
,
char
*
host
,
char
*
ipbuf
);
int
anetResolve
(
char
*
err
,
char
*
host
,
char
*
ipbuf
);
int
anetTcpServer
(
char
*
err
,
int
port
,
char
*
bindaddr
);
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
anetTcpAccept
(
char
*
err
,
int
serversock
,
char
*
ip
,
int
*
port
);
int
anetUnixAccept
(
char
*
err
,
int
serversock
);
int
anetUnixAccept
(
char
*
err
,
int
serversock
);
int
anetWrite
(
int
fd
,
char
*
buf
,
int
count
);
int
anetWrite
(
int
fd
,
char
*
buf
,
int
count
);
...
...
src/config.c
View file @
70cb03e1
...
@@ -73,6 +73,11 @@ void loadServerConfig(char *filename) {
...
@@ -73,6 +73,11 @@ void loadServerConfig(char *filename) {
server
.
bindaddr
=
zstrdup
(
argv
[
1
]);
server
.
bindaddr
=
zstrdup
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"unixsocket"
)
&&
argc
==
2
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"unixsocket"
)
&&
argc
==
2
)
{
server
.
unixsocket
=
zstrdup
(
argv
[
1
]);
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
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"save"
)
&&
argc
==
3
)
{
int
seconds
=
atoi
(
argv
[
1
]);
int
seconds
=
atoi
(
argv
[
1
]);
int
changes
=
atoi
(
argv
[
2
]);
int
changes
=
atoi
(
argv
[
2
]);
...
...
src/redis.c
View file @
70cb03e1
...
@@ -822,6 +822,7 @@ void initServerConfig() {
...
@@ -822,6 +822,7 @@ void initServerConfig() {
server.port = REDIS_SERVERPORT;
server.port = REDIS_SERVERPORT;
server.bindaddr = NULL;
server.bindaddr = NULL;
server.unixsocket = NULL;
server.unixsocket = NULL;
server.unixsocketperm = 0;
server.ipfd = -1;
server.ipfd = -1;
server.sofd = -1;
server.sofd = -1;
server.dbnum = REDIS_DEFAULT_DBNUM;
server.dbnum = REDIS_DEFAULT_DBNUM;
...
@@ -935,7 +936,7 @@ void initServer() {
...
@@ -935,7 +936,7 @@ void initServer() {
}
}
if (server.unixsocket != NULL) {
if (server.unixsocket != NULL) {
unlink(server.unixsocket); /* don't care if this fails */
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) {
if (server.sofd == ANET_ERR) {
redisLog(REDIS_WARNING, "Opening socket: %s", server.neterr);
redisLog(REDIS_WARNING, "Opening socket: %s", server.neterr);
exit(1);
exit(1);
...
@@ -1236,6 +1237,10 @@ int prepareForShutdown() {
...
@@ -1236,6 +1237,10 @@ int prepareForShutdown() {
/* Close the listening sockets. Apparently this allows faster restarts. */
/* Close the listening sockets. Apparently this allows faster restarts. */
if (server.ipfd != -1) close(server.ipfd);
if (server.ipfd != -1) close(server.ipfd);
if (server.sofd != -1) close(server.sofd);
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...");
redisLog(REDIS_WARNING,"Redis is now ready to exit, bye bye...");
return REDIS_OK;
return REDIS_OK;
...
...
src/redis.h
View file @
70cb03e1
...
@@ -515,6 +515,7 @@ struct redisServer {
...
@@ -515,6 +515,7 @@ struct redisServer {
int
port
;
int
port
;
char
*
bindaddr
;
char
*
bindaddr
;
char
*
unixsocket
;
char
*
unixsocket
;
mode_t
unixsocketperm
;
int
ipfd
;
int
ipfd
;
int
sofd
;
int
sofd
;
int
cfd
;
int
cfd
;
...
...
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