[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Comments on libmemcached patch?



Hi,

Attached is a small patch to make libmemcached build under GNU/Hurd.
Comments are welcome!

Thanks!
diff -ur libmemcached-0.44/clients/ms_conn.c libmemcached-0.44.modified/clients/ms_conn.c
--- libmemcached-0.44/clients/ms_conn.c	2010-07-22 17:06:58.000000000 +0200
+++ libmemcached-0.44.modified/clients/ms_conn.c	2011-09-26 21:47:14.000000000 +0200
@@ -2125,6 +2125,9 @@
     limit_to_mtu= c->udp;
 
     /* We may need to start a new msghdr if this one is full. */
+#ifndef IOV_MAX
+#define IOV_MAX 1024
+#endif
     if ((m->msg_iovlen == IOV_MAX)
         || (limit_to_mtu && (c->msgbytes >= UDP_MAX_SEND_PAYLOAD_SIZE)))
     {
diff -ur libmemcached-0.44/clients/ms_setting.c libmemcached-0.44.modified/clients/ms_setting.c
--- libmemcached-0.44/clients/ms_setting.c	2010-08-03 02:34:02.000000000 +0200
+++ libmemcached-0.44.modified/clients/ms_setting.c	2011-09-27 18:12:59.000000000 +0200
@@ -304,13 +304,16 @@
  */
 static void ms_no_config_file()
 {
-  char userpath[PATH_MAX];
+  char *userpath= NULL;
+  size_t len;
   struct passwd *usr= NULL;
   FILE *fd;
 
   usr= getpwuid(getuid());
 
-  snprintf(userpath, PATH_MAX, "%s/%s", usr->pw_dir, DEFAULT_CONFIG_NAME);
+  len= strlen(usr->pw_dir) + 1 + strlen(DEFAULT_CONFIG_NAME) + 1;
+  userpath= malloc(len);
+  snprintf(userpath, len, "%s/%s", usr->pw_dir, DEFAULT_CONFIG_NAME);
 
   if (access (userpath, F_OK | R_OK) == 0)
     goto exit;
@@ -321,6 +324,7 @@
   {
     fprintf(stderr, "Could not create default configure file %s\n", userpath);
     perror(strerror(errno));
+    free(userpath);
     exit(1);
   }
   fprintf(fd, "%s", DEFAULT_CONGIF_STR);
@@ -328,6 +332,7 @@
 
 exit:
   ms_setting.cfg_file= strdup(userpath);
+  free(userpath);
 } /* ms_no_config_file */
 
 
diff -ur libmemcached-0.44/tests/server.c libmemcached-0.44.modified/tests/server.c
--- libmemcached-0.44/tests/server.c	2010-08-03 08:30:54.000000000 +0200
+++ libmemcached-0.44.modified/tests/server.c	2011-09-27 18:07:50.000000000 +0200
@@ -117,8 +117,12 @@
           }
         }
 
-        char buffer[PATH_MAX];
-        snprintf(buffer, sizeof(buffer), PID_FILE_BASE, x);
+        char *buffer= NULL;
+        size_t len= 0;
+        /* x < construct.count= 4 */
+        len= strlen(PID_FILE_BASE) + 1;
+        buffer= malloc(len);
+        snprintf(buffer, len, PID_FILE_BASE, x);
         kill_file(buffer);
 
         if (x == 0)
@@ -142,6 +146,7 @@
 	}
         count= sprintf(end_ptr, "localhost:%u,", port);
         end_ptr+= count;
+        free(buffer);
       }
       *end_ptr= 0;
 
@@ -149,9 +154,12 @@
       int *pids= calloc(construct->count, sizeof(int));
       for (uint32_t x= 0; x < construct->count; x++)
       {
-        char buffer[PATH_MAX]; /* Nothing special for number */
-
-        snprintf(buffer, sizeof(buffer), PID_FILE_BASE, x);
+        char *buffer= NULL; /* Nothing special for number */
+        size_t len= 0;
+        /* x < construct.count= 4 */
+        len= strlen(PID_FILE_BASE) + 1;
+        buffer= malloc(len);
+        snprintf(buffer, len, PID_FILE_BASE, x);
 
         uint32_t counter= 3000; // Absurd, just to catch run away process
         while (pids[x] <= 0  && --counter)
@@ -198,8 +206,10 @@
             if (pids[y] > 0)
               kill(pids[y], SIGTERM);
           }
+          free(buffer);
           abort();
         }
+        free(buffer);
       }
       free(pids);
 
@@ -229,9 +239,14 @@
   {
     for (uint32_t x= 0; x < construct->count; x++)
     {
-      char file_buffer[PATH_MAX]; /* Nothing special for number */
-      snprintf(file_buffer, sizeof(file_buffer), PID_FILE_BASE, x);
+      char *file_buffer=NULL; /* Nothing special for number */
+      size_t len= 0;
+      len= strlen(PID_FILE_BASE) + 1;
+      /* x < construct.count= 4 */
+      file_buffer= malloc(len);
+      snprintf(file_buffer, len, PID_FILE_BASE, x);
       kill_file(file_buffer);
+      free(file_buffer);
     }
 
     free(construct->server_list);

Reply to: