On Mar 11, 8:19 pm, Dustin <[email protected]> wrote:

>   No formal plans, but I've been thinking about isolating it enough to
> do that just to make testing a bit easier.  Enough isolation and it
> starts to look a lot like a library.

That'd be great - I could have used that sort of thing in several
previous projects.  In the mean time, here's what I've done - it
appears to work okay.  As far as I can tell, libmemcached will happily
take socket fds, so I should be set there.  The patch is really
simple, so I don't mind porting it to future releases as needed, if
you're not interested in incorporating it.  I may want to move to
multiple machines later anyway.

I appreciate your thoughts - thanks!

-nate

--- memcached-1.2.6/memcached.c 2008-07-29 12:37:27.000000000 -0400
+++ memcached-1.2.6.nwp/memcached.c     2009-03-11 20:22:22.000000000
-0400
@@ -45,6 +45,11 @@
 #include <assert.h>
 #include <limits.h>

+/* unistd.h is here */
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
 #ifdef HAVE_MALLOC_H
 /* OpenBSD has a malloc.h, but warns to use stdlib.h instead */
 #ifndef __OpenBSD__
@@ -3163,7 +3168,17 @@

     /* create unix mode sockets after dropping privileges */
     if (settings.socketpath != NULL) {
-        if (server_socket_unix(settings.socketpath,settings.access))
{
+        if (strcmp("-",settings.socketpath) == 0) {
+          struct stat st;
+          if(fstat(STDIN_FILENO,&st) || !S_ISSOCK(st.st_mode)) {
+            fprintf(stderr, "failed to listen - stdin is not a socket
\n");
+            exit(EXIT_FAILURE);
+          }
+          if(server_socket(STDIN_FILENO,0)) {
+            fprintf(stderr, "failed to listen\n");
+            exit(EXIT_FAILURE);
+          }
+        } else if (server_socket_unix
(settings.socketpath,settings.access)) {
           fprintf(stderr, "failed to listen\n");
           exit(EXIT_FAILURE);
         }

Reply via email to