X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:date:from:to:subject:message-id:reply-to
	:references:mime-version:content-type:in-reply-to; q=dns; s=
	default; b=MIkAC2YXoXGNd+B3gt+ZPZxGBFdoNj01V8GpA7nkAicWqQ92muAJd
	3LrQJ8Li6CLavlutkKooGL8k1KdW/9b9rvWe02bS21hTpG/PRcChfBLlOikywZWW
	0Kg28vc0yC+CGn0uEqTSaJsgpwaWlAx3yOU3IuQn1DVPoSraaE5ZrE=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:date:from:to:subject:message-id:reply-to
	:references:mime-version:content-type:in-reply-to; s=default;
	 bh=pwYXH7hhc+xkBYGAoZWbPCz5DhU=; b=RmgZwL4b4N2A09xSzRxVd+wQ6TaE
	MhryN19QhgOG+GWKL+rJ9Vgn2SAXbOOdEy56OUFDeRTQLwN7Fv9Ok2iqulmoyASH
	wMO8NOMeWAcQjbl6gM8GGtEtLAbTs3QNiZC8bvsqGFBP1682zCQA3X8nozgkoHjo
	IzaWhRpRyQTlX2E=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-5.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2
X-HELO: calimero.vinschen.de
Date: Wed, 6 Aug 2014 11:19:41 +0200
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: syslog function: Bad file descriptor
Message-ID: <20140806091941.GK13601@calimero.vinschen.de>
Reply-To: cygwin@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
References: <53E10628.3C42FD6F@boland.nl> <20140805164842.GA13601@calimero.vinschen.de> <53E117B7.4C81186A@boland.nl> <20140805190014.GD13601@calimero.vinschen.de> <53E13FFE.E7A33C0D@boland.nl>
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;	protocol="application/pgp-signature"; boundary="SUk9VBj82R8Xhb8H"
Content-Disposition: inline
In-Reply-To: <53E13FFE.E7A33C0D@boland.nl>
User-Agent: Mutt/1.5.23 (2014-03-12)

--SUk9VBj82R8Xhb8H
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Aug  5 22:35, D. Boland wrote:
> Corinna Vinschen wrote:
> >
> > Can you produce another strace for the overwriting case (non-R/O aliase=
s)
> > for comparison?  Also, can you do the same strace with no syslogd runni=
ng?
> >=20
> > It might be necessary to create a few test versions of Cygwin with more
> > debug output, but let's please see these straces first.
>=20
> 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 =3D socket(1, 2 (flags 0x0), 0)

Socket created, file descriptor is 3.

  296:  connect_syslogd: found /dev/log, fd =3D 3, type =3D 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 =3D open(/etc/mail/aliases, 0x8000)

Uh oh!  Now fd 3 is reused for the aliases file.  Things certainly go
downhill.

 2651:  writev: -1 =3D 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
about.

As for using a file descriptor inside of syslog, that's perfectly
valid behaviour, see
http://pubs.opengroup.org/onlinepubs/9699919799/functions/closelog.html:

  "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.


HTH,
Corinna

--=20
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

--SUk9VBj82R8Xhb8H
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBAgAGBQJT4fMtAAoJEPU2Bp2uRE+ghA4P/RohkP3AMQOl3T/qHeXnee5P
t/Kzo0iotbsU9DI0/DjI6y7FkDhhHk5DBILXSpkGJLT+blYxirJ2CMGvglar7c/t
MdR+m+9vYTQ1faoZ72mcSmSufJNP/M3rYMExAxPN4UFLsCBiyzNt5DsPsfathKSC
88T3clevbHDOdFlZWsTLeDVFegFmwoUXyhDYJ2W1Ih/Q+FXgQPYSxPYMJgADe/lJ
aiAun72HP61TjGOdJKpUPk+IBQR17+xFLoZbhjGCrRe33CWwQxaG5qGSEhj+0MqQ
QJA4pGxUdBfEjNrO5O/yfycszEjEGKuJKIKN14ChKJkIsF7rG9gBU/cjgywApMnf
QXV7OPB9Yv8yxRw175uNRLt6zPeTzvqC9+jMBnQJtJ1dA3RPAEFTBYkD758RmCcm
8TEVhuRBB5xpzjtDETJHoi3XgdGltEfvRj5v6iZPAWbF15/MHqZuUpowg/GBPCrx
WkcRPRr+IhbIbybGcefhefPSFevk99ks0K0j8ts/cDbfBT8IvbY9FoQizvSZQ7M3
Y9XSZvMgSjN25KWEAK/TgS5UwsyJa/ArlM78qTpfq8chl3Fskc8ajpn/u3Qlq+H9
7mySQJWqwK7tP0HXkopsDVl2ScELYs7DzrzAGUjps/HG1gruVVcoT/wN3vn2D6G5
FxkegKz8rESCNjRMvO1t
=kULr
-----END PGP SIGNATURE-----

--SUk9VBj82R8Xhb8H--
