mirror of
https://github.com/ruby/ruby.git
synced 2025-09-19 10:33:58 +02:00
merge revision(s) 35474,35479,38939,38943,38963,38991,38994: [Backport #7786]
* 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. * 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 * 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. * 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. * 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. * 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. * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@39096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2618ffc57a
commit
ee6e1db1b6
7 changed files with 163 additions and 65 deletions
|
@ -716,6 +716,7 @@ class Socket < BasicSocket
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
def self.unix_server_socket(path)
|
def self.unix_server_socket(path)
|
||||||
|
if !unix_socket_abstract_name?(path)
|
||||||
begin
|
begin
|
||||||
st = File.lstat(path)
|
st = File.lstat(path)
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
|
@ -723,19 +724,30 @@ class Socket < BasicSocket
|
||||||
if st && st.socket? && st.owned?
|
if st && st.socket? && st.owned?
|
||||||
File.unlink path
|
File.unlink path
|
||||||
end
|
end
|
||||||
|
end
|
||||||
s = Addrinfo.unix(path).listen
|
s = Addrinfo.unix(path).listen
|
||||||
if block_given?
|
if block_given?
|
||||||
begin
|
begin
|
||||||
yield s
|
yield s
|
||||||
ensure
|
ensure
|
||||||
s.close if !s.closed?
|
s.close if !s.closed?
|
||||||
|
if !unix_socket_abstract_name?(path)
|
||||||
File.unlink path
|
File.unlink path
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
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_.
|
# creates a UNIX socket server on _path_.
|
||||||
# It calls the block for each socket accepted.
|
# It calls the block for each socket accepted.
|
||||||
#
|
#
|
||||||
|
|
|
@ -421,20 +421,46 @@ rsock_ipaddr(struct sockaddr *sockaddr, int norevlookup)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_SYS_UN_H
|
#ifdef HAVE_SYS_UN_H
|
||||||
const char*
|
VALUE
|
||||||
rsock_unixpath(struct sockaddr_un *sockaddr, socklen_t len)
|
rsock_unixpath_str(struct sockaddr_un *sockaddr, socklen_t len)
|
||||||
{
|
{
|
||||||
if (sockaddr->sun_path < (char*)sockaddr + len)
|
char *s, *e;
|
||||||
return sockaddr->sun_path;
|
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
|
else
|
||||||
return "";
|
return rb_str_new2("");
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rsock_unixaddr(struct sockaddr_un *sockaddr, socklen_t len)
|
rsock_unixaddr(struct sockaddr_un *sockaddr, socklen_t len)
|
||||||
{
|
{
|
||||||
return rb_assoc_new(rb_str_new2("AF_UNIX"),
|
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
|
#endif
|
||||||
|
|
||||||
|
@ -763,19 +789,22 @@ static void
|
||||||
init_unix_addrinfo(rb_addrinfo_t *rai, VALUE path, int socktype)
|
init_unix_addrinfo(rb_addrinfo_t *rai, VALUE path, int socktype)
|
||||||
{
|
{
|
||||||
struct sockaddr_un un;
|
struct sockaddr_un un;
|
||||||
|
socklen_t len;
|
||||||
|
|
||||||
StringValue(path);
|
StringValue(path);
|
||||||
|
|
||||||
if (sizeof(un.sun_path) <= (size_t)RSTRING_LEN(path))
|
if (sizeof(un.sun_path) < (size_t)RSTRING_LEN(path))
|
||||||
rb_raise(rb_eArgError, "too long unix socket path (max: %dbytes)",
|
rb_raise(rb_eArgError,
|
||||||
(int)sizeof(un.sun_path)-1);
|
"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);
|
MEMZERO(&un, struct sockaddr_un, 1);
|
||||||
|
|
||||||
un.sun_family = AF_UNIX;
|
un.sun_family = AF_UNIX;
|
||||||
memcpy((void*)&un.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
|
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);
|
PF_UNIX, socktype, 0, Qnil, Qnil);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -996,9 +1025,11 @@ inspect_sockaddr(VALUE addrinfo, VALUE ret)
|
||||||
case AF_UNIX:
|
case AF_UNIX:
|
||||||
{
|
{
|
||||||
struct sockaddr_un *addr = (struct sockaddr_un *)&rai->addr;
|
struct sockaddr_un *addr = (struct sockaddr_un *)&rai->addr;
|
||||||
char *p, *s, *t, *e;
|
char *p, *s, *e;
|
||||||
s = addr->sun_path;
|
s = addr->sun_path;
|
||||||
e = (char*)addr + rai->sockaddr_len;
|
e = (char*)addr + rai->sockaddr_len;
|
||||||
|
while (s < e && *(e-1) == '\0')
|
||||||
|
e--;
|
||||||
if (e < s)
|
if (e < s)
|
||||||
rb_str_cat2(ret, "too-short-AF_UNIX-sockaddr");
|
rb_str_cat2(ret, "too-short-AF_UNIX-sockaddr");
|
||||||
else if (s == e)
|
else if (s == e)
|
||||||
|
@ -1006,28 +1037,17 @@ inspect_sockaddr(VALUE addrinfo, VALUE ret)
|
||||||
else {
|
else {
|
||||||
int printable_only = 1;
|
int printable_only = 1;
|
||||||
p = s;
|
p = s;
|
||||||
while (p < e && *p != '\0') {
|
while (p < e) {
|
||||||
printable_only = printable_only && ISPRINT(*p) && !ISSPACE(*p);
|
printable_only = printable_only && ISPRINT(*p) && !ISSPACE(*p);
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
t = p;
|
if (printable_only) { /* only printable, no space */
|
||||||
while (p < e && *p == '\0')
|
if (s[0] != '/') /* relative path */
|
||||||
p++;
|
rb_str_cat2(ret, "AF_UNIX ");
|
||||||
if (printable_only && /* only printable, no space */
|
rb_str_cat(ret, s, p - s);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_str_cat2(ret, "AF_UNIX");
|
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)
|
while (s < e)
|
||||||
rb_str_catf(ret, ":%02x", (unsigned char)*s++);
|
rb_str_catf(ret, ":%02x", (unsigned char)*s++);
|
||||||
}
|
}
|
||||||
|
@ -1201,7 +1221,7 @@ addrinfo_mdump(VALUE self)
|
||||||
struct sockaddr_un *su = (struct sockaddr_un *)&rai->addr;
|
struct sockaddr_un *su = (struct sockaddr_un *)&rai->addr;
|
||||||
char *s, *e;
|
char *s, *e;
|
||||||
s = su->sun_path;
|
s = su->sun_path;
|
||||||
e = (char*)s + sizeof(su->sun_path);
|
e = (char*)su + rai->sockaddr_len;
|
||||||
while (s < e && *(e-1) == '\0')
|
while (s < e && *(e-1) == '\0')
|
||||||
e--;
|
e--;
|
||||||
sockaddr = rb_str_new(s, e-s);
|
sockaddr = rb_str_new(s, e-s);
|
||||||
|
@ -1298,12 +1318,14 @@ addrinfo_mload(VALUE self, VALUE ary)
|
||||||
case AF_UNIX:
|
case AF_UNIX:
|
||||||
{
|
{
|
||||||
struct sockaddr_un uaddr;
|
struct sockaddr_un uaddr;
|
||||||
memset(&uaddr, 0, sizeof(uaddr));
|
MEMZERO(&uaddr, struct sockaddr_un, 1);
|
||||||
uaddr.sun_family = AF_UNIX;
|
uaddr.sun_family = AF_UNIX;
|
||||||
|
|
||||||
StringValue(v);
|
StringValue(v);
|
||||||
if (sizeof(uaddr.sun_path) <= (size_t)RSTRING_LEN(v))
|
if (sizeof(uaddr.sun_path) < (size_t)RSTRING_LEN(v))
|
||||||
rb_raise(rb_eSocket, "too long AF_UNIX path");
|
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));
|
memcpy(uaddr.sun_path, RSTRING_PTR(v), RSTRING_LEN(v));
|
||||||
len = (socklen_t)sizeof(uaddr);
|
len = (socklen_t)sizeof(uaddr);
|
||||||
memcpy(&ss, &uaddr, len);
|
memcpy(&ss, &uaddr, len);
|
||||||
|
|
|
@ -233,8 +233,9 @@ VALUE rsock_make_hostent(VALUE host, struct addrinfo *addr, VALUE (*ipaddr)(stru
|
||||||
int rsock_revlookup_flag(VALUE revlookup, int *norevlookup);
|
int rsock_revlookup_flag(VALUE revlookup, int *norevlookup);
|
||||||
|
|
||||||
#ifdef HAVE_SYS_UN_H
|
#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);
|
VALUE rsock_unixaddr(struct sockaddr_un *sockaddr, socklen_t len);
|
||||||
|
socklen_t rsock_unix_sockaddr_len(VALUE path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int rsock_socket(int domain, int type, int proto);
|
int rsock_socket(int domain, int type, int proto);
|
||||||
|
|
|
@ -954,13 +954,12 @@ sock_s_gethostbyaddr(int argc, VALUE *argv)
|
||||||
{
|
{
|
||||||
VALUE addr, family;
|
VALUE addr, family;
|
||||||
struct hostent *h;
|
struct hostent *h;
|
||||||
struct sockaddr *sa;
|
|
||||||
char **pch;
|
char **pch;
|
||||||
VALUE ary, names;
|
VALUE ary, names;
|
||||||
int t = AF_INET;
|
int t = AF_INET;
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "11", &addr, &family);
|
rb_scan_args(argc, argv, "11", &addr, &family);
|
||||||
sa = (struct sockaddr*)StringValuePtr(addr);
|
StringValue(addr);
|
||||||
if (!NIL_P(family)) {
|
if (!NIL_P(family)) {
|
||||||
t = rsock_family_arg(family);
|
t = rsock_family_arg(family);
|
||||||
}
|
}
|
||||||
|
@ -1371,18 +1370,17 @@ static VALUE
|
||||||
sock_s_pack_sockaddr_un(VALUE self, VALUE path)
|
sock_s_pack_sockaddr_un(VALUE self, VALUE path)
|
||||||
{
|
{
|
||||||
struct sockaddr_un sockaddr;
|
struct sockaddr_un sockaddr;
|
||||||
char *sun_path;
|
|
||||||
VALUE addr;
|
VALUE addr;
|
||||||
|
|
||||||
|
StringValue(path);
|
||||||
MEMZERO(&sockaddr, struct sockaddr_un, 1);
|
MEMZERO(&sockaddr, struct sockaddr_un, 1);
|
||||||
sockaddr.sun_family = AF_UNIX;
|
sockaddr.sun_family = AF_UNIX;
|
||||||
sun_path = StringValueCStr(path);
|
if (sizeof(sockaddr.sun_path) < (size_t)RSTRING_LEN(path)) {
|
||||||
if (sizeof(sockaddr.sun_path) <= strlen(sun_path)) {
|
rb_raise(rb_eArgError, "too long unix socket path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
|
||||||
rb_raise(rb_eArgError, "too long unix socket path (max: %dbytes)",
|
(size_t)RSTRING_LEN(path), sizeof(sockaddr.sun_path));
|
||||||
(int)sizeof(sockaddr.sun_path)-1);
|
|
||||||
}
|
}
|
||||||
strncpy(sockaddr.sun_path, sun_path, sizeof(sockaddr.sun_path)-1);
|
memcpy(sockaddr.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
|
||||||
addr = rb_str_new((char*)&sockaddr, sizeof(sockaddr));
|
addr = rb_str_new((char*)&sockaddr, rsock_unix_sockaddr_len(path));
|
||||||
OBJ_INFECT(addr, path);
|
OBJ_INFECT(addr, path);
|
||||||
|
|
||||||
return addr;
|
return addr;
|
||||||
|
@ -1404,7 +1402,6 @@ static VALUE
|
||||||
sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
|
sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
|
||||||
{
|
{
|
||||||
struct sockaddr_un * sockaddr;
|
struct sockaddr_un * sockaddr;
|
||||||
const char *sun_path;
|
|
||||||
VALUE path;
|
VALUE path;
|
||||||
|
|
||||||
sockaddr = (struct sockaddr_un*)SockAddrStringValuePtr(addr);
|
sockaddr = (struct sockaddr_un*)SockAddrStringValuePtr(addr);
|
||||||
|
@ -1420,13 +1417,7 @@ sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
|
||||||
rb_raise(rb_eTypeError, "too long sockaddr_un - %ld longer than %d",
|
rb_raise(rb_eTypeError, "too long sockaddr_un - %ld longer than %d",
|
||||||
RSTRING_LEN(addr), (int)sizeof(struct sockaddr_un));
|
RSTRING_LEN(addr), (int)sizeof(struct sockaddr_un));
|
||||||
}
|
}
|
||||||
sun_path = rsock_unixpath(sockaddr, RSTRING_LENINT(addr));
|
path = rsock_unixpath_str(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);
|
|
||||||
OBJ_INFECT(path, addr);
|
OBJ_INFECT(path, addr);
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#ifdef HAVE_SYS_UN_H
|
#ifdef HAVE_SYS_UN_H
|
||||||
struct unixsock_arg {
|
struct unixsock_arg {
|
||||||
struct sockaddr_un *sockaddr;
|
struct sockaddr_un *sockaddr;
|
||||||
|
socklen_t sockaddrlen;
|
||||||
int fd;
|
int fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,13 +22,14 @@ unixsock_connect_internal(VALUE a)
|
||||||
{
|
{
|
||||||
struct unixsock_arg *arg = (struct unixsock_arg *)a;
|
struct unixsock_arg *arg = (struct unixsock_arg *)a;
|
||||||
return (VALUE)rsock_connect(arg->fd, (struct sockaddr*)arg->sockaddr,
|
return (VALUE)rsock_connect(arg->fd, (struct sockaddr*)arg->sockaddr,
|
||||||
(socklen_t)sizeof(*arg->sockaddr), 0);
|
arg->sockaddrlen, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rsock_init_unixsock(VALUE sock, VALUE path, int server)
|
rsock_init_unixsock(VALUE sock, VALUE path, int server)
|
||||||
{
|
{
|
||||||
struct sockaddr_un sockaddr;
|
struct sockaddr_un sockaddr;
|
||||||
|
socklen_t sockaddrlen;
|
||||||
int fd, status;
|
int fd, status;
|
||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
|
|
||||||
|
@ -39,19 +41,21 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server)
|
||||||
|
|
||||||
MEMZERO(&sockaddr, struct sockaddr_un, 1);
|
MEMZERO(&sockaddr, struct sockaddr_un, 1);
|
||||||
sockaddr.sun_family = AF_UNIX;
|
sockaddr.sun_family = AF_UNIX;
|
||||||
if (sizeof(sockaddr.sun_path) <= (size_t)RSTRING_LEN(path)) {
|
if (sizeof(sockaddr.sun_path) < (size_t)RSTRING_LEN(path)) {
|
||||||
rb_raise(rb_eArgError, "too long unix socket path (max: %dbytes)",
|
rb_raise(rb_eArgError, "too long unix socket path (%ldbytes given but %dbytes max)",
|
||||||
(int)sizeof(sockaddr.sun_path)-1);
|
RSTRING_LEN(path), (int)sizeof(sockaddr.sun_path));
|
||||||
}
|
}
|
||||||
memcpy(sockaddr.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
|
memcpy(sockaddr.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
|
||||||
|
sockaddrlen = rsock_unix_sockaddr_len(path);
|
||||||
|
|
||||||
if (server) {
|
if (server) {
|
||||||
status = bind(fd, (struct sockaddr*)&sockaddr, (socklen_t)sizeof(sockaddr));
|
status = bind(fd, (struct sockaddr*)&sockaddr, sockaddrlen);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int prot;
|
int prot;
|
||||||
struct unixsock_arg arg;
|
struct unixsock_arg arg;
|
||||||
arg.sockaddr = &sockaddr;
|
arg.sockaddr = &sockaddr;
|
||||||
|
arg.sockaddrlen = sockaddrlen;
|
||||||
arg.fd = fd;
|
arg.fd = fd;
|
||||||
status = (int)rb_protect(unixsock_connect_internal, (VALUE)&arg, &prot);
|
status = (int)rb_protect(unixsock_connect_internal, (VALUE)&arg, &prot);
|
||||||
if (prot) {
|
if (prot) {
|
||||||
|
@ -62,7 +66,7 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server)
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
rb_sys_fail(sockaddr.sun_path);
|
rb_sys_fail_str(rb_inspect(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server) {
|
if (server) {
|
||||||
|
|
|
@ -324,8 +324,11 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
|
||||||
assert_raise(ArgumentError) { UNIXServer.new("a" * 300) }
|
assert_raise(ArgumentError) { UNIXServer.new("a" * 300) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nul
|
def test_abstract_namespace
|
||||||
assert_raise(ArgumentError) { Socket.sockaddr_un("a\0b") }
|
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
|
end
|
||||||
|
|
||||||
def test_dgram_pair
|
def test_dgram_pair
|
||||||
|
@ -507,4 +510,69 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
end
|
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
|
end if defined?(UNIXSocket) && /cygwin/ !~ RUBY_PLATFORM
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#define RUBY_VERSION "1.9.3"
|
#define RUBY_VERSION "1.9.3"
|
||||||
#define RUBY_PATCHLEVEL 380
|
#define RUBY_PATCHLEVEL 381
|
||||||
|
|
||||||
#define RUBY_RELEASE_DATE "2013-02-06"
|
#define RUBY_RELEASE_DATE "2013-02-06"
|
||||||
#define RUBY_RELEASE_YEAR 2013
|
#define RUBY_RELEASE_YEAR 2013
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue