Mercurial > dovecot > core-2.2
diff src/lib/network.c @ 3523:d1ed3b3548db HEAD
Added some more error messages. Also if net_connect_ip() gives my_ip
parameter and it can't be given to bind(), don't silently ignore it.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 07 Aug 2005 16:06:56 +0300 |
parents | ddfa507bb74f |
children | 5ff3b88db948 |
line wrap: on
line diff
--- a/src/lib/network.c Sun Aug 07 15:51:12 2005 +0300 +++ b/src/lib/network.c Sun Aug 07 16:06:56 2005 +0300 @@ -124,8 +124,10 @@ so.sin.sin_family = ip->family; fd = socket(ip->family, SOCK_STREAM, 0); - if (fd == -1) + if (fd == -1) { + i_error("socket() failed: %m"); return -1; + } /* set socket options */ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); @@ -137,8 +139,9 @@ sin_set_ip(&so, my_ip); if (bind(fd, &so.sa, SIZEOF_SOCKADDR(so)) == -1) { /* failed, set it back to INADDR_ANY */ - sin_set_ip(&so, NULL); - bind(fd, &so.sa, SIZEOF_SOCKADDR(so)); + i_error("bind(%s) failed: %m", net_ip2addr(my_ip)); + close_save_errno(fd); + return -1; } } @@ -175,8 +178,10 @@ /* create the socket */ fd = socket(PF_UNIX, SOCK_STREAM, 0); - if (fd == -1) + if (fd == -1) { + i_error("socket(%s) failed: %m", path); return -1; + } net_set_nonblock(fd, TRUE); @@ -270,8 +275,10 @@ fd = socket(AF_INET, SOCK_STREAM, 0); } #endif - if (fd == -1) + if (fd == -1) { + i_error("socket() failed: %m"); return -1; + } /* set socket options */ setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); @@ -286,7 +293,9 @@ #endif /* specify the address/port we want to listen in */ ret = bind(fd, &so.sa, SIZEOF_SOCKADDR(so)); - if (ret >= 0) { + if (ret < 0) + i_error("bind(%s) failed: %m", net_ip2addr(my_ip)); + else { /* get the actual port we started listen */ len = SIZEOF_SOCKADDR(so); ret = getsockname(fd, &so.sa, &len); @@ -297,7 +306,6 @@ if (listen(fd, backlog) >= 0) return fd; } - } /* error */ @@ -320,11 +328,15 @@ /* create the socket */ fd = socket(PF_UNIX, SOCK_STREAM, 0); - if (fd == -1) + if (fd == -1) { + i_error("socket() failed: %m"); return -1; + } /* bind */ - if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) == 0) { + if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) + i_error("bind(%s) failed: %m", path); + else { /* start listening */ if (listen(fd, backlog) == 0) return fd;