[dovecot-cvs] dovecot/src/lib network.c,1.29,1.30
cras at dovecot.org
cras at dovecot.org
Sun Aug 7 16:06:58 EEST 2005
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv31297/src/lib
Modified Files:
network.c
Log Message:
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.
Index: network.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/network.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- network.c 29 May 2005 00:26:19 -0000 1.29
+++ network.c 7 Aug 2005 13:06:56 -0000 1.30
@@ -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;
More information about the dovecot-cvs
mailing list