[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openbsd-tech
Subject:    Re: Syslog uses connect/send/close on each call, waits forever if send() returns ENOBUFS
From:       "Christiano F. Haesbaert" <haesbaert () haesbaert ! org>
Date:       2011-02-28 14:03:23
Message-ID: AANLkTi=ADs814VFc2wWqyVQPwFYcOW823491x3E4Zkm7 () mail ! gmail ! com
[Download RAW message or body]

On 27 February 2011 12:22, Eric <airuike@gmail.com> wrote:
> I was working on syslog and noticed two things that I don't fully
understand:
>
> - Each call to syslog calls connect(), send(), and close()--Is this
> method used for a particular reason, or can I chang it so that each
> call just uses sendto(), and it no longer needs to use the struct
> syslog_data.connected variable to save state?
>

I'm not familiar with the code but calling connect(2) on a UDP socket
results in having ICMP errors returned in the socket, with that you
can get an ICMP port unreachable or something instead of timing out,
so maybe that is the reason.

> - If the call to send() were to ever keep returning with ENOBUFS,
> syslog() would hang indefinitely (things like ssh login would probably
> stop working).  It seems unlikely that this would ever happen, but I
> could easily add a counter to put an upper bound on the number of
> tries.
>

You'll find this behaviour in other programs as well, there is no
point in giving up, since the next call on the next packet will also
return ENOBUFS.
The only thing to would be to sleep a while, just to be nicer to the
CPU, but that is ugly.
But then, if the kernel is out of mbufs, the last thing you want is to
"lose" the next available mbuf, so not sleeping is a better solution.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic