mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-05-04 12:41:00 +02:00
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.
This commit is contained in:
parent
d660990cee
commit
7e9776ad7b
6
src/fd.c
6
src/fd.c
@ -414,6 +414,12 @@ ssize_t fd_write_frag_line(int fd, size_t maxlen, const struct ist pfx[], size_t
|
||||
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);
|
||||
|
||||
@ -1504,13 +1504,13 @@ static inline void __do_send_log(struct logsrv *logsrv, int nblogger, char *pid_
|
||||
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)
|
||||
|
||||
@ -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 @@ struct sink *sink_new_fd(const char *name, const char *desc, enum sink_fmt fmt,
|
||||
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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user