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
16 16
rsock_sys_fail_host_port(const char *mesg, VALUE host, VALUE port)
17 17
{
18 18
    VALUE message;
19
    int err = errno;
19 20

  
20 21
    port = rb_String(port);
21 22

  
22 23
    message = rb_sprintf("%s for \"%s\" port %s",
23 24
	    mesg, StringValueCStr(host), StringValueCStr(port));
24 25

  
26
    errno = err;
25 27
    rb_sys_fail_str(message);
26 28
}
27 29

  
......
29 31
rsock_sys_fail_path(const char *mesg, VALUE path)
30 32
{
31 33
    VALUE message;
34
    int err = errno;
35

  
32 36
    if (RB_TYPE_P(path, T_STRING)) {
33 37
        if (memchr(RSTRING_PTR(path), '\0', RSTRING_LEN(path))) {
34 38
            path = rb_str_inspect(path);
......
39 43
            message = rb_sprintf("%s for \"%s\"", mesg,
40 44
                    StringValueCStr(path));
41 45
        }
46
        errno = err;
42 47
        rb_sys_fail_str(message);
43 48
    }
44 49
    else {
......
50 55
rsock_sys_fail_sockaddr(const char *mesg, struct sockaddr *addr, socklen_t len)
51 56
{
52 57
    VALUE rai;
58
    int err = errno;
53 59

  
54 60
    rai = rsock_addrinfo_new(addr, len, PF_UNSPEC, 0, 0, Qnil, Qnil);
55 61

  
62
    errno = err;
56 63
    rsock_sys_fail_raddrinfo(mesg, rai);
57 64
}
58 65

  
......
60 67
rsock_sys_fail_raddrinfo(const char *mesg, VALUE rai)
61 68
{
62 69
    VALUE str, message;
70
    int err = errno;
63 71

  
64 72
    str = rsock_addrinfo_inspect_sockaddr(rai);
65 73
    message = rb_sprintf("%s for %s", mesg, StringValueCStr(str));
66 74

  
75
    errno = err;
67 76
    rb_sys_fail_str(message);
68 77
}
69 78

  
70 79
void
71 80
rsock_sys_fail_raddrinfo_or_sockaddr(const char *mesg, VALUE addr, VALUE rai)
72 81
{
82
    int err = errno;
83

  
73 84
    if (NIL_P(rai)) {
74 85
        StringValue(addr);
86

  
87
        errno = err;
75 88
        rsock_sys_fail_sockaddr(mesg,
76 89
            (struct sockaddr *)RSTRING_PTR(addr),
77 90
            (socklen_t)RSTRING_LEN(addr)); /* overflow should be checked already */
78
-