This is the mail archive of the
mailing list for the Cygwin project.
Re: syslog function: Bad file descriptor
- From: "D. Boland" <daniel at boland dot nl>
- To: cygwin at cygwin dot com
- Date: Wed, 06 Aug 2014 13:30:37 +0200
- Subject: Re: syslog function: Bad file descriptor
- Authentication-results: sourceware.org; auth=none
- References: <53E10628 dot 3C42FD6F at boland dot nl> <20140805164842 dot GA13601 at calimero dot vinschen dot de> <53E117B7 dot 4C81186A at boland dot nl> <20140805190014 dot GD13601 at calimero dot vinschen dot de> <53E13FFE dot E7A33C0D at boland dot nl> <20140806091941 dot GK13601 at calimero dot vinschen dot de>
Corinna Vinschen wrote:
> On Aug 5 22:35, D. Boland wrote:
> > Corinna Vinschen wrote:
> > >
> > > Can you produce another strace for the overwriting case (non-R/O aliases)
> > > for comparison? Also, can you do the same strace with no syslogd running?
> > >
> > > It might be necessary to create a few test versions of Cygwin with more
> > > debug output, but let's please see these straces first.
> > I attached all three of them in a zipped file.
> Thanks. I got it now. AFAICS it's a bug in sendmail. Take a look
> into your newaliases.strace.txt file. Start at line 260 (stripping
> off timestamp, thread and process info):
> 260: normalize_posix_path: src /dev/log
> Here the syslog() function tries to open a connection to a syslogd
> listening on /dev/log.
> 282: cygwin_socket: 3 = socket(1, 2 (flags 0x0), 0)
> Socket created, file descriptor is 3.
> 296: connect_syslogd: found /dev/log, fd = 3, type = DGRAM
> Yes, there's a listener on /dev/log. Now Cygwin stores the info that fd
> 3 is the connection to the syslog daemon.
> 332: close: close(3)
> And at line 332, a file descriptor close orgy starts. sendmail closes
> all descriptors from 3 to 255. This obviously closes fd 3, but how's
> Cygwin's syslog() function to know?
> 2263: open: 3 = open(/etc/mail/aliases, 0x8000)
> Uh oh! Now fd 3 is reused for the aliases file. Things certainly go
> 2651: writev: -1 = writev(3, 0x2287F0, 2), errno 9
> This is syslog trying to write the log to the descriptor it knows
> is connected to /dev/log. Fortunately the aliases file is R/O at
> this point, but it's pretty much working as designed. Syslog()
> doesn't know the application broke its connection to the syslog
> daemon. It dutyfully writes to the syslog descriptor it knows
> As for using a file descriptor inside of syslog, that's perfectly
> valid behaviour, see
> "The openlog() and syslog() functions may allocate a file descriptor."
> Without looking into the sources, I'd assume there's a closelog()
> call missing prior to the descriptor close orgy. This closelog()
> call should fix the problem.
It is exactly as you say. I found the close() orgy and put a closelog() prior to it.
Now it works perfectly without corrupting the aliases file (writable to sendmail).
I'm asking myself if this closing of 253 file descriptors is a sensible thing to do.
What would Sendmail be trying to accomplish there? It comments "Be shure we have
enough file descriptors". And: "in 4.4BSD, the table ([of fd's]) can be huge; impose
a reasonable limit". Bizarre.
Could it be that incoming e-mail is such a volatile process that previous opened
file descriptors are not closed quick enough? This feels like a crude hack.
Can you give your opinion on this?
Thanks for the quick response & the time you put into this.
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple