summaryrefslogtreecommitdiff
path: root/memcached.c
diff options
context:
space:
mode:
authorJefty Negapatan <jefty.dev@gmail.com>2020-04-11 15:12:11 +0200
committerdormando <dormando@rydia.net>2020-04-11 18:04:38 -0700
commitbbc544e52b3044831387ec70bb63f7c6abba9b3b (patch)
tree6ca2796355fe560cd372c3c01e6ba90b2da934b8 /memcached.c
parent05a794b2e9c2001c7d9000d648da64af3f8c9ade (diff)
downloadmemcached-bbc544e52b3044831387ec70bb63f7c6abba9b3b.tar.gz
Add build option to disable unix socket functionality.
1. configure.ac - Add --disable-unix-socket to disable and define DISABLE_UNIX_SOCKET. 2. memcached.* - Guard all unix socket-related codes with DISABLE_UNIX_SOCKET. Take note of negative checking (#ifndef DISABLE_UNIX_SOCKET instead of #ifdef UNIX_SOCKET). This is just to make sure that current code even without a config file is the default or supports unix socket. 3. t/ - Check first if unix socket is supported before executing some unix socket-related tests.
Diffstat (limited to 'memcached.c')
-rw-r--r--memcached.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/memcached.c b/memcached.c
index 8701857..b4be9ef 100644
--- a/memcached.c
+++ b/memcached.c
@@ -3371,7 +3371,6 @@ static inline void get_conn_text(const conn *c, const int af,
addr_text[0] = '\0';
const char *protoname = "?";
unsigned short port = 0;
- size_t pathlen = 0;
switch (af) {
case AF_INET:
@@ -3396,7 +3395,10 @@ static inline void get_conn_text(const conn *c, const int af,
protoname = IS_UDP(c->transport) ? "udp6" : "tcp6";
break;
+#ifndef DISABLE_UNIX_SOCKET
case AF_UNIX:
+ {
+ size_t pathlen = 0;
// this strncpy call originally could piss off an address
// sanitizer; we supplied the size of the dest buf as a limiter,
// but optimized versions of strncpy could read past the end of
@@ -3419,7 +3421,9 @@ static inline void get_conn_text(const conn *c, const int af,
pathlen);
addr_text[pathlen] = '\0';
protoname = "unix";
+ }
break;
+#endif /* #ifndef DISABLE_UNIX_SOCKET */
}
if (strlen(addr_text) < 2) {
@@ -7812,6 +7816,7 @@ static int server_sockets(int port, enum network_transport transport,
}
}
+#ifndef DISABLE_UNIX_SOCKET
static int new_socket_unix(void) {
int sfd;
int flags;
@@ -7889,6 +7894,9 @@ static int server_socket_unix(const char *path, int access_mask) {
return 0;
}
+#else
+#define server_socket_unix(path, access_mask) -1
+#endif /* #ifndef DISABLE_UNIX_SOCKET */
/*
* We keep the current time of day in a global variable that's updated by a
@@ -7967,9 +7975,13 @@ static void usage(void) {
printf(PACKAGE " " VERSION "\n");
printf("-p, --port=<num> TCP port to listen on (default: %d)\n"
"-U, --udp-port=<num> UDP port to listen on (default: %d, off)\n"
+#ifndef DISABLE_UNIX_SOCKET
"-s, --unix-socket=<file> UNIX socket to listen on (disables network support)\n"
+#endif /* #ifndef DISABLE_UNIX_SOCKET */
"-A, --enable-shutdown enable ascii \"shutdown\" command\n"
+#ifndef DISABLE_UNIX_SOCKET
"-a, --unix-mask=<mask> access mask for UNIX socket, in octal (default: %o)\n"
+#endif /* #ifndef DISABLE_UNIX_SOCKET */
"-l, --listen=<addr> interface to listen on (default: INADDR_ANY)\n"
#ifdef TLS
" if TLS/SSL is enabled, 'notls' prefix can be used to\n"
@@ -7991,7 +8003,11 @@ static void usage(void) {
"-P, --pidfile=<file> save PID in <file>, only used with -d option\n"
"-f, --slab-growth-factor=<num> chunk size growth factor (default: %2.2f)\n"
"-n, --slab-min-size=<bytes> min space used for key+value+flags (default: %d)\n",
- settings.port, settings.udpport, settings.access, (unsigned long) settings.maxbytes / (1 << 20),
+ settings.port, settings.udpport,
+#ifndef DISABLE_UNIX_SOCKET
+ settings.access,
+#endif /* #ifndef DISABLE_UNIX_SOCKET */
+ (unsigned long) settings.maxbytes / (1 << 20),
settings.maxconns, settings.factor, settings.chunk_size);
verify_default("udp-port",settings.udpport == 0);
printf("-L, --enable-largepages try to use large memory pages (if available)\n");
@@ -9016,8 +9032,13 @@ int main (int argc, char **argv) {
#endif
break;
case 'a':
+#ifndef DISABLE_UNIX_SOCKET
/* access for unix domain socket, as octal mask (like chmod)*/
settings.access= strtol(optarg,NULL,8);
+#else
+ fprintf(stderr, "This server is not built with unix socket support.\n");
+ exit(EX_USAGE);
+#endif /* #ifndef DISABLE_UNIX_SOCKET */
break;
case 'U':
settings.udpport = atoi(optarg);
@@ -9028,7 +9049,12 @@ int main (int argc, char **argv) {
tcp_specified = true;
break;
case 's':
+#ifndef DISABLE_UNIX_SOCKET
settings.socketpath = optarg;
+#else
+ fprintf(stderr, "This server is not built with unix socket support.\n");
+ exit(EX_USAGE);
+#endif /* #ifndef DISABLE_UNIX_SOCKET */
break;
case 'm':
settings.maxbytes = ((size_t)atoi(optarg)) * 1024 * 1024;