# 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
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
return s;
}
-int anetUnixServer(char *err, char *path)
+int anetUnixServer(char *err, char *path, mode_t perm)
{
int s;
struct sockaddr_un sa;
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;
}
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);
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]);
server.port = REDIS_SERVERPORT;
server.bindaddr = NULL;
server.unixsocket = NULL;
+ server.unixsocketperm = 0;
server.ipfd = -1;
server.sofd = -1;
server.dbnum = REDIS_DEFAULT_DBNUM;
}
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);
int port;
char *bindaddr;
char *unixsocket;
+ mode_t unixsocketperm;
int ipfd;
int sofd;
int cfd;