MINOR: fd/log/sink: make the non-blocking initialization depend on the initialized bit

Logs and sinks were resorting to dirty hacks to initialize an FD to
non-blocking mode. Now we have a bit for this in the fd tab so we can
do it on the fly on first use of the file descriptor. Previously it was
set per log server by writing value 1 to the port, or during a sink
initialization regardless of the usage of the fd.
diff --git a/src/fd.c b/src/fd.c
index 17cf52b..58d73d4 100644
--- a/src/fd.c
+++ b/src/fd.c
@@ -414,6 +414,12 @@
 		vec++;
 	}
 
+	if (unlikely(!fdtab[fd].initialized)) {
+		fdtab[fd].initialized = 1;
+		if (!isatty(fd))
+			fcntl(fd, F_SETFL, O_NONBLOCK);
+	}
+
 	HA_SPIN_LOCK(FD_LOCK, &fdtab[fd].lock);
 	sent = writev(fd, iovec, vec);
 	HA_SPIN_UNLOCK(FD_LOCK, &fdtab[fd].lock);
diff --git a/src/log.c b/src/log.c
index b2e6231..72602b7 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1504,13 +1504,13 @@
 	if (logsrv->addr.ss_family == AF_UNSPEC) {
 		/* the socket's address is a file descriptor */
 		plogfd = (int *)&((struct sockaddr_in *)&logsrv->addr)->sin_addr.s_addr;
-		if (unlikely(!((struct sockaddr_in *)&logsrv->addr)->sin_port)) {
+		if (!fdtab[*plogfd].initialized) {
 			/* FD not yet initialized to non-blocking mode.
 			 * DON'T DO IT ON A TERMINAL!
 			 */
+			fdtab[*plogfd].initialized = 1;
 			if (!isatty(*plogfd))
 				fcntl(*plogfd, F_SETFL, O_NONBLOCK);
-			((struct sockaddr_in *)&logsrv->addr)->sin_port = 1;
 		}
 	}
 	else if (logsrv->addr.ss_family == AF_UNIX)
diff --git a/src/sink.c b/src/sink.c
index ed49062..bd06f1e 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -18,8 +18,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <fcntl.h>
-#include <unistd.h>
 #include <common/compat.h>
 #include <common/config.h>
 #include <common/ist.h>
@@ -93,11 +91,6 @@
 		goto end;
 	}
 
-	/* FD not yet initialized to non-blocking mode.
-	 * DON'T DO IT ON A TERMINAL!
-	 */
-	if (!isatty(fd))
-		fcntl(fd, F_SETFL, O_NONBLOCK);
 	sink->type = SINK_TYPE_FD;
 	sink->ctx.fd = fd;
  end: