From 668f000cb148ee9e06b90d3b0b9504a16a3e7c52 Mon Sep 17 00:00:00 2001 From: Brandon Carpenter Date: Thu, 3 Oct 2013 16:21:42 -0700 Subject: [PATCH] Add abstract namespace support for IPC sockets on Linux. Converts an initial strudel or "at sign" (@) in the Unix socket path to a NULL character ('\0') indicating that the socket uses the abstract namespace instead of the filesystem namespace. For instance, binding a socket to 'ipc://@/tmp/tester' will not create a file associated with the socket whereas binding to 'ipc:///tmp/tester' will create the file /tmp/tester. See issue 567 for more information. --- AUTHORS | 1 + src/ipc_address.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/AUTHORS b/AUTHORS index ab849c70..8481813f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -20,6 +20,7 @@ Ben Gray Bernd Prager Bernd Melchers Bob Beaty +Brandon Carpenter Brian Buchanan Brett Cameron Burak Arslan diff --git a/src/ipc_address.cpp b/src/ipc_address.cpp index 39f0042a..fb1acc86 100644 --- a/src/ipc_address.cpp +++ b/src/ipc_address.cpp @@ -54,6 +54,10 @@ int zmq::ipc_address_t::resolve (const char *path_) address.sun_family = AF_UNIX; strcpy (address.sun_path, path_); +#if defined ZMQ_HAVE_LINUX + if (*path_ == '@') + *address.sun_path = '\0'; +#endif return 0; } @@ -65,7 +69,15 @@ int zmq::ipc_address_t::to_string (std::string &addr_) } std::stringstream s; +#if !defined ZMQ_HAVE_LINUX s << "ipc://" << address.sun_path; +#else + s << "ipc://"; + if (*address.sun_path) + s << address.sun_path; + else + s << "@" << address.sun_path + 1; +#endif addr_ = s.str (); return 0; }