Backport #7786 ยป abstract_namespace_fix.diff
ChangeLog | ||
---|---|---|
Thu Jan 31 13:54:44 2013 Shugo Maeda <shugo@ruby-lang.org>
|
||
* ext/socket/raddrinfo.c (rsock_unix_sockaddr_len): return
|
||
sizeof(sa_familiy_t) if path is empty. see "Autobind Feature" in
|
||
unix(7) for details.
|
||
* ext/socket/lib/socket.rb (unix_socket_abstract_name?): treat an
|
||
empty path as an abstract name.
|
||
* test/socket/test_unix.rb: related test.
|
||
Wed Jan 30 15:26:37 2013 Shugo Maeda <shugo@ruby-lang.org>
|
||
* ext/socket/unixsocket.c (rsock_init_unixsock): use rb_inspect()
|
||
because rb_sys_fail_str() fails if its argument contains NUL.
|
||
* test/socket/test_unix.rb: related test.
|
||
Tue Jan 29 09:26:20 2013 Shugo Maeda <shugo@ruby-lang.org>
|
||
* ext/socket/socket.c (sock_s_pack_sockaddr_un): calculate the
|
||
correct address length of an abstract socket.
|
||
* test/socket/test_unix.rb: related test.
|
||
Sat Jan 26 08:29:33 2013 Shugo Maeda <shugo@ruby-lang.org>
|
||
* ext/socket/raddrinfo (rsock_unix_sockaddr_len): renamed from
|
||
rsock_unixpath_len, because it returns not the length of the path,
|
||
but the length of a socket address for the path.
|
||
Fri Jan 25 16:47:31 2013 Shugo Maeda <shugo@ruby-lang.org>
|
||
* ext/socket/raddrinfo.c (rsock_unixpath_len, init_unix_addrinfo),
|
||
ext/socket/unixsocket.c (unixsock_connect_internal,
|
||
rsock_init_unixsock): calculate the correct address length of
|
||
an abstract socket. Without this fix, sizeof(struct sockaddr_un)
|
||
is specified as the length of an abstract socket for bind(2) or
|
||
connect(2), so the address of the socket is filled with extra NUL
|
||
characters. See unix(7) for details.
|
||
* ext/socket/lib/socket.rb (unix_server_socket): don't access the
|
||
file system if the platform is Linux and path starts with NUL,
|
||
which means that the socket is an abstract socket.
|
||
* test/socket/test_unix.rb: related test.
|
||
Fri Apr 27 07:15:07 2012 Tanaka Akira <akr@fsij.org>
|
||
* ext/socket/socket.c (sock_s_pack_sockaddr_un): support the longest
|
||
path in sockaddr_un, really.
|
||
reported by nagachika.
|
||
http://d.hatena.ne.jp/nagachika/20120426/ruby_trunk_changes_35474_35476
|
||
Thu Apr 26 12:28:06 2012 Tanaka Akira <akr@fsij.org>
|
||
* ext/socket/raddrinfo.c (init_unix_addrinfo): support the longest
|
||
path in sockaddr_un.
|
||
(inspect_sockaddr): ditto.
|
||
(addrinfo_mdump): ditto.
|
||
(addrinfo_mload): ditto.
|
||
(rsock_unixpath_str): new function.
|
||
(rsock_unixpath): removed.
|
||
(rsock_unixaddr): use rsock_unixpath_str.
|
||
* ext/socket/socket.c (sock_s_pack_sockaddr_un): support the longest
|
||
path in sockaddr_un.
|
||
(sock_s_unpack_sockaddr_un): ditto.
|
||
(sock_s_gethostbyaddr): unused variable removed.
|
||
* ext/socket/unixsocket.c (rsock_init_unixsock): support the longest
|
||
path in sockaddr_un.
|
||
* ext/socket/rubysocket.h (rsock_unixpath_str): declared.
|
||
(rsock_unixpath): removed.
|
||
* test/socket/test_unix.rb: comment out test_nul because abstract unix
|
||
sockets may contain NULs.
|
||
Tue Jan 15 16:30:29 2013 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||
* thread_pthread.c (gvl_init): Reset gvl.wait_yield explicitly when
|
ext/socket/basicsocket.c | ||
---|---|---|
{
|
||
struct sockaddr_storage buf;
|
||
socklen_t len = (socklen_t)sizeof buf;
|
||
socklen_t len0 = len;
|
||
rb_io_t *fptr;
|
||
GetOpenFile(sock, fptr);
|
||
if (getsockname(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
|
||
rb_sys_fail("getsockname(2)");
|
||
if (len0 < len) len = len0;
|
||
return rb_str_new((char*)&buf, len);
|
||
}
|
||
... | ... | |
{
|
||
struct sockaddr_storage buf;
|
||
socklen_t len = (socklen_t)sizeof buf;
|
||
socklen_t len0 = len;
|
||
rb_io_t *fptr;
|
||
GetOpenFile(sock, fptr);
|
||
if (getpeername(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
|
||
rb_sys_fail("getpeername(2)");
|
||
if (len0 < len) len = len0;
|
||
return rb_str_new((char*)&buf, len);
|
||
}
|
||
... | ... | |
{
|
||
struct sockaddr_storage buf;
|
||
socklen_t len = (socklen_t)sizeof buf;
|
||
socklen_t len0 = len;
|
||
rb_io_t *fptr;
|
||
GetOpenFile(sock, fptr);
|
||
if (getsockname(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
|
||
rb_sys_fail("getsockname(2)");
|
||
if (len0 < len) len = len0;
|
||
return rsock_fd_socket_addrinfo(fptr->fd, (struct sockaddr *)&buf, len);
|
||
}
|
||
... | ... | |
{
|
||
struct sockaddr_storage buf;
|
||
socklen_t len = (socklen_t)sizeof buf;
|
||
socklen_t len0 = len;
|
||
rb_io_t *fptr;
|
||
GetOpenFile(sock, fptr);
|
||
if (getpeername(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
|
||
rb_sys_fail("getpeername(2)");
|
||
if (len0 < len) len = len0;
|
||
return rsock_fd_socket_addrinfo(fptr->fd, (struct sockaddr *)&buf, len);
|
||
}
|
||
ext/socket/init.c | ||
---|---|---|
rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
|
||
{
|
||
int fd2;
|
||
socklen_t len0 = len ? *len : 0;
|
||
rb_secure(3);
|
||
rb_io_set_nonblock(fptr);
|
||
... | ... | |
}
|
||
rb_sys_fail("accept(2)");
|
||
}
|
||
if (len && len0 < *len) *len = len0;
|
||
rb_update_max_fd(fd2);
|
||
make_fd_nonblock(fd2);
|
||
return rsock_init_sock(rb_obj_alloc(klass), fd2);
|
||
... | ... | |
accept_blocking(void *data)
|
||
{
|
||
struct accept_arg *arg = data;
|
||
return (VALUE)accept(arg->fd, arg->sockaddr, arg->len);
|
||
int ret;
|
||
socklen_t len0 = 0;
|
||
if (arg->len) len0 = *arg->len;
|
||
ret = accept(arg->fd, arg->sockaddr, arg->len);
|
||
if (arg->len && len0 < *arg->len) *arg->len = len0;
|
||
return (VALUE)ret;
|
||
}
|
||
VALUE
|
ext/socket/lib/socket.rb | ||
---|---|---|
# }
|
||
#
|
||
def self.unix_server_socket(path)
|
||
begin
|
||
st = File.lstat(path)
|
||
rescue Errno::ENOENT
|
||
end
|
||
if st && st.socket? && st.owned?
|
||
File.unlink path
|
||
if !unix_socket_abstract_name?(path)
|
||
begin
|
||
st = File.lstat(path)
|
||
rescue Errno::ENOENT
|
||
end
|
||
if st && st.socket? && st.owned?
|
||
File.unlink path
|
||
end
|
||
end
|
||
s = Addrinfo.unix(path).listen
|
||
if block_given?
|
||
... | ... | |
yield s
|
||
ensure
|
||
s.close if !s.closed?
|
||
File.unlink path
|
||
if !unix_socket_abstract_name?(path)
|
||
File.unlink path
|
||
end
|
||
end
|
||
else
|
||
s
|
||
end
|
||
end
|
||
class << self
|
||
private
|
||
def unix_socket_abstract_name?(path)
|
||
/linux/ =~ RUBY_PLATFORM && /\A(\0|\z)/ =~ path
|
||
end
|
||
end
|
||
# creates a UNIX socket server on _path_.
|
||
# It calls the block for each socket accepted.
|
||
#
|
ext/socket/raddrinfo.c | ||
---|---|---|
}
|
||
#ifdef HAVE_SYS_UN_H
|
||
const char*
|
||
rsock_unixpath(struct sockaddr_un *sockaddr, socklen_t len)
|
||
VALUE
|
||
rsock_unixpath_str(struct sockaddr_un *sockaddr, socklen_t len)
|
||
{
|
||
if (sockaddr->sun_path < (char*)sockaddr + len)
|
||
return sockaddr->sun_path;
|
||
char *s, *e;
|
||
s = sockaddr->sun_path;
|
||
e = (char *)sockaddr + len;
|
||
while (s < e && *(e-1) == '\0')
|
||
e--;
|
||
if (s <= e)
|
||
return rb_str_new(s, e-s);
|
||
else
|
||
return "";
|
||
return rb_str_new2("");
|
||
}
|
||
VALUE
|
||
rsock_unixaddr(struct sockaddr_un *sockaddr, socklen_t len)
|
||
{
|
||
return rb_assoc_new(rb_str_new2("AF_UNIX"),
|
||
rb_str_new2(rsock_unixpath(sockaddr, len)));
|
||
rsock_unixpath_str(sockaddr, len));
|
||
}
|
||
socklen_t
|
||
rsock_unix_sockaddr_len(VALUE path)
|
||
{
|
||
#ifdef __linux__
|
||
if (RSTRING_LEN(path) == 0) {
|
||
/* autobind; see unix(7) for details. */
|
||
return (socklen_t) sizeof(sa_family_t);
|
||
}
|
||
else if (RSTRING_PTR(path)[0] == '\0') {
|
||
/* abstract namespace; see unix(7) for details. */
|
||
return (socklen_t) offsetof(struct sockaddr_un, sun_path) +
|
||
RSTRING_LEN(path);
|
||
}
|
||
else {
|
||
#endif
|
||
return (socklen_t) sizeof(struct sockaddr_un);
|
||
#ifdef __linux__
|
||
}
|
||
#endif
|
||
}
|
||
#endif
|
||
... | ... | |
init_unix_addrinfo(rb_addrinfo_t *rai, VALUE path, int socktype)
|
||
{
|
||
struct sockaddr_un un;
|
||
socklen_t len;
|
||
StringValue(path);
|
||
if (sizeof(un.sun_path) <= (size_t)RSTRING_LEN(path))
|
||
rb_raise(rb_eArgError, "too long unix socket path (max: %dbytes)",
|
||
(int)sizeof(un.sun_path)-1);
|
||
if (sizeof(un.sun_path) < (size_t)RSTRING_LEN(path))
|
||
rb_raise(rb_eArgError,
|
||
"too long unix socket path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
|
||
(size_t)RSTRING_LEN(path), sizeof(un.sun_path));
|
||
MEMZERO(&un, struct sockaddr_un, 1);
|
||
un.sun_family = AF_UNIX;
|
||
memcpy((void*)&un.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
|
||
init_addrinfo(rai, (struct sockaddr *)&un, (socklen_t)sizeof(un),
|
||
len = rsock_unix_sockaddr_len(path);
|
||
init_addrinfo(rai, (struct sockaddr *)&un, len,
|
||
PF_UNIX, socktype, 0, Qnil, Qnil);
|
||
}
|
||
#endif
|
||
... | ... | |
case AF_UNIX:
|
||
{
|
||
struct sockaddr_un *addr = (struct sockaddr_un *)&rai->addr;
|
||
char *p, *s, *t, *e;
|
||
char *p, *s, *e;
|
||
s = addr->sun_path;
|
||
e = (char*)addr + rai->sockaddr_len;
|
||
while (s < e && *(e-1) == '\0')
|
||
e--;
|
||
if (e < s)
|
||
rb_str_cat2(ret, "too-short-AF_UNIX-sockaddr");
|
||
else if (s == e)
|
||
... | ... | |
else {
|
||
int printable_only = 1;
|
||
p = s;
|
||
while (p < e && *p != '\0') {
|
||
while (p < e) {
|
||
printable_only = printable_only && ISPRINT(*p) && !ISSPACE(*p);
|
||
p++;
|
||
}
|
||
t = p;
|
||
while (p < e && *p == '\0')
|
||
p++;
|
||
if (printable_only && /* only printable, no space */
|
||
t < e && /* NUL terminated */
|
||
p == e) { /* no data after NUL */
|
||
if (s == t)
|
||
rb_str_cat2(ret, "empty-path-AF_UNIX-sockaddr");
|
||
else if (s[0] == '/') /* absolute path */
|
||
rb_str_cat2(ret, s);
|
||
else
|
||
rb_str_catf(ret, "AF_UNIX %s", s);
|
||
if (printable_only) { /* only printable, no space */
|
||
if (s[0] != '/') /* relative path */
|
||
rb_str_cat2(ret, "AF_UNIX ");
|
||
rb_str_cat(ret, s, p - s);
|
||
}
|
||
else {
|
||
rb_str_cat2(ret, "AF_UNIX");
|
||
e = (char *)addr->sun_path + sizeof(addr->sun_path);
|
||
while (s < e && *(e-1) == '\0')
|
||
e--;
|
||
while (s < e)
|
||
rb_str_catf(ret, ":%02x", (unsigned char)*s++);
|
||
}
|
||
... | ... | |
struct sockaddr_un *su = (struct sockaddr_un *)&rai->addr;
|
||
char *s, *e;
|
||
s = su->sun_path;
|
||
e = (char*)s + sizeof(su->sun_path);
|
||
e = (char*)su + rai->sockaddr_len;
|
||
while (s < e && *(e-1) == '\0')
|
||
e--;
|
||
sockaddr = rb_str_new(s, e-s);
|
||
... | ... | |
case AF_UNIX:
|
||
{
|
||
struct sockaddr_un uaddr;
|
||
memset(&uaddr, 0, sizeof(uaddr));
|
||
MEMZERO(&uaddr, struct sockaddr_un, 1);
|
||
uaddr.sun_family = AF_UNIX;
|
||
StringValue(v);
|
||
if (sizeof(uaddr.sun_path) <= (size_t)RSTRING_LEN(v))
|
||
rb_raise(rb_eSocket, "too long AF_UNIX path");
|
||
if (sizeof(uaddr.sun_path) < (size_t)RSTRING_LEN(v))
|
||
rb_raise(rb_eSocket,
|
||
"too long AF_UNIX path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
|
||
(size_t)RSTRING_LEN(v), sizeof(uaddr.sun_path));
|
||
memcpy(uaddr.sun_path, RSTRING_PTR(v), RSTRING_LEN(v));
|
||
len = (socklen_t)sizeof(uaddr);
|
||
memcpy(&ss, &uaddr, len);
|
ext/socket/rubysocket.h | ||
---|---|---|
int rsock_revlookup_flag(VALUE revlookup, int *norevlookup);
|
||
#ifdef HAVE_SYS_UN_H
|
||
const char* rsock_unixpath(struct sockaddr_un *sockaddr, socklen_t len);
|
||
VALUE rsock_unixpath_str(struct sockaddr_un *sockaddr, socklen_t len);
|
||
VALUE rsock_unixaddr(struct sockaddr_un *sockaddr, socklen_t len);
|
||
socklen_t rsock_unix_sockaddr_len(VALUE path);
|
||
#endif
|
||
int rsock_socket(int domain, int type, int proto);
|
ext/socket/socket.c | ||
---|---|---|
{
|
||
VALUE addr, family;
|
||
struct hostent *h;
|
||
struct sockaddr *sa;
|
||
char **pch;
|
||
VALUE ary, names;
|
||
int t = AF_INET;
|
||
rb_scan_args(argc, argv, "11", &addr, &family);
|
||
sa = (struct sockaddr*)StringValuePtr(addr);
|
||
StringValue(addr);
|
||
if (!NIL_P(family)) {
|
||
t = rsock_family_arg(family);
|
||
}
|
||
... | ... | |
sock_s_pack_sockaddr_un(VALUE self, VALUE path)
|
||
{
|
||
struct sockaddr_un sockaddr;
|
||
char *sun_path;
|
||
VALUE addr;
|
||
StringValue(path);
|
||
MEMZERO(&sockaddr, struct sockaddr_un, 1);
|
||
sockaddr.sun_family = AF_UNIX;
|
||
sun_path = StringValueCStr(path);
|
||
if (sizeof(sockaddr.sun_path) <= strlen(sun_path)) {
|
||
rb_raise(rb_eArgError, "too long unix socket path (max: %dbytes)",
|
||
(int)sizeof(sockaddr.sun_path)-1);
|
||
if (sizeof(sockaddr.sun_path) < (size_t)RSTRING_LEN(path)) {
|
||
rb_raise(rb_eArgError, "too long unix socket path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
|
||
(size_t)RSTRING_LEN(path), sizeof(sockaddr.sun_path));
|
||
}
|
||
strncpy(sockaddr.sun_path, sun_path, sizeof(sockaddr.sun_path)-1);
|
||
addr = rb_str_new((char*)&sockaddr, sizeof(sockaddr));
|
||
memcpy(sockaddr.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
|
||
addr = rb_str_new((char*)&sockaddr, rsock_unix_sockaddr_len(path));
|
||
OBJ_INFECT(addr, path);
|
||
return addr;
|
||
... | ... | |
sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
|
||
{
|
||
struct sockaddr_un * sockaddr;
|
||
const char *sun_path;
|
||
VALUE path;
|
||
sockaddr = (struct sockaddr_un*)SockAddrStringValuePtr(addr);
|
||
... | ... | |
rb_raise(rb_eTypeError, "too long sockaddr_un - %ld longer than %d",
|
||
RSTRING_LEN(addr), (int)sizeof(struct sockaddr_un));
|
||
}
|
||
sun_path = rsock_unixpath(sockaddr, RSTRING_LENINT(addr));
|
||
if (sizeof(struct sockaddr_un) == RSTRING_LEN(addr) &&
|
||
sun_path == sockaddr->sun_path &&
|
||
sun_path + strlen(sun_path) == RSTRING_PTR(addr) + RSTRING_LEN(addr)) {
|
||
rb_raise(rb_eArgError, "sockaddr_un.sun_path not NUL terminated");
|
||
}
|
||
path = rb_str_new2(sun_path);
|
||
path = rsock_unixpath_str(sockaddr, RSTRING_LENINT(addr));
|
||
OBJ_INFECT(path, addr);
|
||
return path;
|
||
}
|
ext/socket/unixsocket.c | ||
---|---|---|
#ifdef HAVE_SYS_UN_H
|
||
struct unixsock_arg {
|
||
struct sockaddr_un *sockaddr;
|
||
socklen_t sockaddrlen;
|
||
int fd;
|
||
};
|
||
... | ... | |
{
|
||
struct unixsock_arg *arg = (struct unixsock_arg *)a;
|
||
return (VALUE)rsock_connect(arg->fd, (struct sockaddr*)arg->sockaddr,
|
||
(socklen_t)sizeof(*arg->sockaddr), 0);
|
||
arg->sockaddrlen, 0);
|
||
}
|
||
VALUE
|
||
rsock_init_unixsock(VALUE sock, VALUE path, int server)
|
||
{
|
||
struct sockaddr_un sockaddr;
|
||
socklen_t sockaddrlen;
|
||
int fd, status;
|
||
rb_io_t *fptr;
|
||
... | ... | |
MEMZERO(&sockaddr, struct sockaddr_un, 1);
|
||
sockaddr.sun_family = AF_UNIX;
|
||
if (sizeof(sockaddr.sun_path) <= (size_t)RSTRING_LEN(path)) {
|
||
rb_raise(rb_eArgError, "too long unix socket path (max: %dbytes)",
|
||
(int)sizeof(sockaddr.sun_path)-1);
|
||
if (sizeof(sockaddr.sun_path) < (size_t)RSTRING_LEN(path)) {
|
||
rb_raise(rb_eArgError, "too long unix socket path (%ldbytes given but %dbytes max)",
|
||
RSTRING_LEN(path), (int)sizeof(sockaddr.sun_path));
|
||
}
|
||
memcpy(sockaddr.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
|
||
sockaddrlen = rsock_unix_sockaddr_len(path);
|
||
if (server) {
|
||
status = bind(fd, (struct sockaddr*)&sockaddr, (socklen_t)sizeof(sockaddr));
|
||
status = bind(fd, (struct sockaddr*)&sockaddr, sockaddrlen);
|
||
}
|
||
else {
|
||
int prot;
|
||
struct unixsock_arg arg;
|
||
arg.sockaddr = &sockaddr;
|
||
arg.sockaddrlen = sockaddrlen;
|
||
arg.fd = fd;
|
||
status = (int)rb_protect(unixsock_connect_internal, (VALUE)&arg, &prot);
|
||
if (prot) {
|
||
... | ... | |
if (status < 0) {
|
||
close(fd);
|
||
rb_sys_fail(sockaddr.sun_path);
|
||
rb_sys_fail_str(rb_inspect(path));
|
||
}
|
||
if (server) {
|
||
... | ... | |
socklen_t len = (socklen_t)sizeof(addr);
|
||
if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
|
||
rb_sys_fail(0);
|
||
fptr->pathv = rb_obj_freeze(rb_str_new_cstr(rsock_unixpath(&addr, len)));
|
||
fptr->pathv = rb_obj_freeze(rsock_unixpath_str(&addr, len));
|
||
}
|
||
return rb_str_dup(fptr->pathv);
|
||
}
|
||
... | ... | |
rb_io_t *fptr;
|
||
struct sockaddr_un addr;
|
||
socklen_t len = (socklen_t)sizeof addr;
|
||
socklen_t len0 = len;
|
||
GetOpenFile(sock, fptr);
|
||
if (getpeername(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
|
||
rb_sys_fail("getpeername(2)");
|
||
if (len0 < len) len = len0;
|
||
return rsock_unixaddr(&addr, len);
|
||
}
|
||
test/socket/test_unix.rb | ||
---|---|---|
assert_raise(ArgumentError) { UNIXServer.new("a" * 300) }
|
||
end
|
||
def test_nul
|
||
assert_raise(ArgumentError) { Socket.sockaddr_un("a\0b") }
|
||
def test_abstract_namespace
|
||
return if /linux/ !~ RUBY_PLATFORM
|
||
addr = Socket.pack_sockaddr_un("\0foo")
|
||
assert_match(/\0foo\z/, addr)
|
||
assert_equal("\0foo", Socket.unpack_sockaddr_un(addr))
|
||
end
|
||
def test_dgram_pair
|
||
... | ... | |
}
|
||
end
|
||
def test_abstract_unix_server
|
||
return if /linux/ !~ RUBY_PLATFORM
|
||
name = "\0ruby-test_unix"
|
||
s0 = nil
|
||
UNIXServer.open(name) {|s|
|
||
assert_equal(name, s.local_address.unix_path)
|
||
s0 = s
|
||
UNIXSocket.open(name) {|c|
|
||
sock = s.accept
|
||
begin
|
||
assert_equal(name, c.remote_address.unix_path)
|
||
ensure
|
||
sock.close
|
||
end
|
||
}
|
||
}
|
||
assert(s0.closed?)
|
||
end
|
||
def test_abstract_unix_socket_econnrefused
|
||
return if /linux/ !~ RUBY_PLATFORM
|
||
name = "\0ruby-test_unix"
|
||
assert_raise(Errno::ECONNREFUSED) do
|
||
UNIXSocket.open(name) {}
|
||
end
|
||
end
|
||
def test_abstract_unix_server_socket
|
||
return if /linux/ !~ RUBY_PLATFORM
|
||
name = "\0ruby-test_unix"
|
||
s0 = nil
|
||
Socket.unix_server_socket(name) {|s|
|
||
assert_equal(name, s.local_address.unix_path)
|
||
s0 = s
|
||
Socket.unix(name) {|c|
|
||
sock, = s.accept
|
||
begin
|
||
assert_equal(name, c.remote_address.unix_path)
|
||
ensure
|
||
sock.close
|
||
end
|
||
}
|
||
}
|
||
assert(s0.closed?)
|
||
end
|
||
def test_autobind
|
||
return if /linux/ !~ RUBY_PLATFORM
|
||
s0 = nil
|
||
Socket.unix_server_socket("") {|s|
|
||
name = s.local_address.unix_path
|
||
assert_match(/\A\0[0-9a-f]{5}\z/, name)
|
||
s0 = s
|
||
Socket.unix(name) {|c|
|
||
sock, = s.accept
|
||
begin
|
||
assert_equal(name, c.remote_address.unix_path)
|
||
ensure
|
||
sock.close
|
||
end
|
||
}
|
||
}
|
||
assert(s0.closed?)
|
||
end
|
||
end if defined?(UNIXSocket) && /cygwin/ !~ RUBY_PLATFORM
|