Clean up the syslog(3) messages on the setsockopt(2) errors:

o Always check a setsockopt(2) return value
o Use a consistent message format
o Don't abort if the failed setsockopt(2) was actually not vital
o Use LOG_WARNING, not LOG_ERR, in non-fatal cases

MFC after:	1 week
This commit is contained in:
Yaroslav Tykhiy 2002-07-24 14:50:17 +00:00
parent 8e4c33e9e7
commit 406d1ae93a

View File

@ -456,12 +456,13 @@ main(int argc, char *argv[], char **envp)
}
if (setsockopt(ctl_sock, SOL_SOCKET, SO_REUSEADDR,
(char *)&on, sizeof(on)) < 0)
syslog(LOG_ERR, "control setsockopt: %m");
syslog(LOG_WARNING,
"control setsockopt (SO_REUSEADDR): %m");
if (family == AF_INET6 && enable_v4 == 0) {
if (setsockopt(ctl_sock, IPPROTO_IPV6, IPV6_V6ONLY,
(char *)&on, sizeof (on)) < 0)
syslog(LOG_ERR,
"control setsockopt(IPV6_V6ONLY): %m");
syslog(LOG_WARNING,
"control setsockopt (IPV6_V6ONLY): %m");
}
memcpy(&server_addr, res->ai_addr, res->ai_addr->sa_len);
if (bind(ctl_sock, (struct sockaddr *)&server_addr,
@ -551,7 +552,7 @@ main(int argc, char *argv[], char **envp)
{
tos = IPTOS_LOWDELAY;
if (setsockopt(0, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)
syslog(LOG_WARNING, "setsockopt (IP_TOS): %m");
syslog(LOG_WARNING, "control setsockopt (IP_TOS): %m");
}
#endif
/*
@ -559,7 +560,7 @@ main(int argc, char *argv[], char **envp)
* for peer's ACK before issuing our next reply.
*/
if (setsockopt(0, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) < 0)
syslog(LOG_WARNING, "control setsockopt TCP_NODELAY: %m");
syslog(LOG_WARNING, "control setsockopt (TCP_NODELAY): %m");
data_source.su_port = htons(ntohs(ctrl_addr.su_port) - 1);
@ -569,7 +570,7 @@ main(int argc, char *argv[], char **envp)
/* Try to handle urgent data inline */
#ifdef SO_OOBINLINE
if (setsockopt(0, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on)) < 0)
syslog(LOG_ERR, "setsockopt: %m");
syslog(LOG_WARNING, "control setsockopt (SO_OOBINLINE): %m");
#endif
#ifdef F_SETOWN
@ -1667,7 +1668,7 @@ getdatasock(char *mode)
goto bad;
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
(char *) &on, sizeof(on)) < 0)
goto bad;
syslog(LOG_WARNING, "data setsockopt (SO_REUSEADDR): %m");
/* anchor socket to avoid multi-homing problems */
data_source = ctrl_addr;
data_source.su_port = htons(20); /* ftp-data port */
@ -1685,7 +1686,7 @@ getdatasock(char *mode)
{
on = IPTOS_THROUGHPUT;
if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0)
syslog(LOG_WARNING, "setsockopt (IP_TOS): %m");
syslog(LOG_WARNING, "data setsockopt (IP_TOS): %m");
}
#endif
#ifdef TCP_NOPUSH
@ -1697,12 +1698,12 @@ getdatasock(char *mode)
*/
on = 1;
if (setsockopt(s, IPPROTO_TCP, TCP_NOPUSH, (char *)&on, sizeof on) < 0)
syslog(LOG_WARNING, "setsockopt (TCP_NOPUSH): %m");
syslog(LOG_WARNING, "data setsockopt (TCP_NOPUSH): %m");
#endif
#ifdef SO_SNDBUF
on = 65536;
if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&on, sizeof on) < 0)
syslog(LOG_WARNING, "setsockopt (SO_SNDBUF): %m");
syslog(LOG_WARNING, "data setsockopt (SO_SNDBUF): %m");
#endif
return (fdopen(s, mode));
@ -1766,8 +1767,9 @@ dataconn(char *name, off_t size, char *mode)
if (from.su_family == AF_INET)
{
tos = IPTOS_THROUGHPUT;
(void) setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos,
sizeof(int));
if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos,
sizeof(int)) < 0)
syslog(LOG_WARNING, "pdata setsockopt (IP_TOS): %m");
}
#endif
reply(150, "Opening %s mode data connection for '%s'%s.",