Project

General

Profile

Bug #9352 » 0001-socket-preserve-errno-before-rb_sys_fail_-and-friend.patch

normalperson (Eric Wong), 01/03/2014 04:35 PM

View differences:

ext/socket/socket.c
rsock_sys_fail_host_port(const char *mesg, VALUE host, VALUE port)
{
VALUE message;
int err = errno;
port = rb_String(port);
message = rb_sprintf("%s for \"%s\" port %s",
mesg, StringValueCStr(host), StringValueCStr(port));
errno = err;
rb_sys_fail_str(message);
}
......
rsock_sys_fail_path(const char *mesg, VALUE path)
{
VALUE message;
int err = errno;
if (RB_TYPE_P(path, T_STRING)) {
if (memchr(RSTRING_PTR(path), '\0', RSTRING_LEN(path))) {
path = rb_str_inspect(path);
......
message = rb_sprintf("%s for \"%s\"", mesg,
StringValueCStr(path));
}
errno = err;
rb_sys_fail_str(message);
}
else {
......
rsock_sys_fail_sockaddr(const char *mesg, struct sockaddr *addr, socklen_t len)
{
VALUE rai;
int err = errno;
rai = rsock_addrinfo_new(addr, len, PF_UNSPEC, 0, 0, Qnil, Qnil);
errno = err;
rsock_sys_fail_raddrinfo(mesg, rai);
}
......
rsock_sys_fail_raddrinfo(const char *mesg, VALUE rai)
{
VALUE str, message;
int err = errno;
str = rsock_addrinfo_inspect_sockaddr(rai);
message = rb_sprintf("%s for %s", mesg, StringValueCStr(str));
errno = err;
rb_sys_fail_str(message);
}
void
rsock_sys_fail_raddrinfo_or_sockaddr(const char *mesg, VALUE addr, VALUE rai)
{
int err = errno;
if (NIL_P(rai)) {
StringValue(addr);
errno = err;
rsock_sys_fail_sockaddr(mesg,
(struct sockaddr *)RSTRING_PTR(addr),
(socklen_t)RSTRING_LEN(addr)); /* overflow should be checked already */
(3-3/3)