From f4c791141f9dff309a6ffc4f5dab2666105ba3a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Mon, 23 May 2011 16:29:12 +0200
Subject: [PATCH] Fix memcached compilation on gcc 4.6+

---
 slapos/patch/memcached-gcc4.6.patch | 36 +++++++++++++++++++++++++++++
 slapos/profile/memcached.cfg        |  8 +++++++
 2 files changed, 44 insertions(+)
 create mode 100644 slapos/patch/memcached-gcc4.6.patch

diff --git a/slapos/patch/memcached-gcc4.6.patch b/slapos/patch/memcached-gcc4.6.patch
new file mode 100644
index 0000000000..53647d90ae
--- /dev/null
+++ b/slapos/patch/memcached-gcc4.6.patch
@@ -0,0 +1,36 @@
+diff --git a/items.c b/items.c
+index e7f01ea..9fc6704 100644
+--- a/items.c
++++ b/items.c
+@@ -450,9 +450,7 @@ void do_item_stats_sizes(ADD_STAT add_stats, void *c) {
+         for (i = 0; i < num_buckets; i++) {
+             if (histogram[i] != 0) {
+                 char key[8];
+-                int klen = 0;
+-                klen = snprintf(key, sizeof(key), "%d", i * 32);
+-                assert(klen < sizeof(key));
++                assert(snprintf(key, sizeof(key), "%d", i * 32) < sizeof(key));
+                 APPEND_STAT(key, "%u", histogram[i]);
+             }
+         }
+diff --git a/memcached.c b/memcached.c
+index 750c8b3..0913b77 100644
+--- a/memcached.c
++++ b/memcached.c
+@@ -4627,8 +4627,6 @@ int main (int argc, char **argv) {
+ 
+     /* create the listening socket, bind it, and init */
+     if (settings.socketpath == NULL) {
+-        int udp_port;
+-
+         const char *portnumber_filename = getenv("MEMCACHED_PORT_FILENAME");
+         char temp_portnumber_filename[PATH_MAX];
+         FILE *portnumber_file = NULL;
+@@ -4658,7 +4656,6 @@ int main (int argc, char **argv) {
+          * then daemonise if needed, then init libevent (in some cases
+          * descriptors created by libevent wouldn't survive forking).
+          */
+-        udp_port = settings.udpport ? settings.udpport : settings.port;
+ 
+         /* create the UDP listening socket and bind it */
+         errno = 0;
diff --git a/slapos/profile/memcached.cfg b/slapos/profile/memcached.cfg
index 514799f193..df74baa6fa 100644
--- a/slapos/profile/memcached.cfg
+++ b/slapos/profile/memcached.cfg
@@ -19,6 +19,13 @@ filename = memcached-1.4-fix-array-subscript-is-above-array-bounds.patch
 download-only = true
 md5sum = 472508b9a4b6c0b9f5d6f2abce3444e3
 
+[memcached-gcc4.6.patch]
+recipe = hexagonit.recipe.download
+url = ${:_profile_base_location_}/../patch/${:filename}
+filename = memcached-gcc4.6.patch
+download-only = true
+md5sum = 3418477f64500cd2a8dce046f5d72fec
+
 [memcached]
 <= memcached-1.4.5
 
@@ -39,6 +46,7 @@ configure-options =
 patches =
   ${memcached-strict-aliasing-patch:location}/${memcached-strict-aliasing-patch:filename}
   ${memcached-fix-array-subscript-is-above-array-bounds:location}/${memcached-fix-array-subscript-is-above-array-bounds:filename}
+  ${memcached-gcc4.6.patch:location}/${memcached-gcc4.6.patch:filename}
 patch-options = -p1
 environment =
     LDFLAGS =-Wl,-rpath ${libevent:location}/lib
-- 
2.30.9