GNU bug report logs - #47596
File descriptor error when exiting emacs on android 11

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Henrik Grimler <henrik@HIDDEN>; dated Sun, 4 Apr 2021 19:21:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 47596 <at> debbugs.gnu.org:


Received: (at 47596) by debbugs.gnu.org; 6 May 2021 10:45:30 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu May 06 06:45:30 2021
Received: from localhost ([127.0.0.1]:37326 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lebVZ-0000ru-W9
	for submit <at> debbugs.gnu.org; Thu, 06 May 2021 06:45:30 -0400
Received: from quimby.gnus.org ([95.216.78.240]:47152)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1lebVX-0000je-Iq
 for 47596 <at> debbugs.gnu.org; Thu, 06 May 2021 06:45:28 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID
 :In-Reply-To:Date:References:Subject:Cc:To:From:Sender:Reply-To:Content-ID:
 Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
 :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=YlIJaUCraJ8wVvlMwk9RPiuESFKMPjSjTnCxhDqwLxQ=; b=h4pdX1UZIhj/E49otPzuM6PH2L
 70bJ+2Oa2KDT9aKHoMdyvNZ7+Q1jxorgg2igASdWklruUQafqC30rN7jRVChMOr2+hewPbbNCA/4v
 ln0i+MCfBXUeEInnA73TnCouUs/ip2Ye2kXeL9X61PdecoGaNgSNFM/Qwe5idAh39250=;
Received: from cm-84.212.220.105.getinternet.no ([84.212.220.105] helo=xo)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1lebVO-0006D7-5T; Thu, 06 May 2021 12:45:20 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Henrik Grimler <henrik@HIDDEN>
Subject: Re: bug#47596: File descriptor error when exiting emacs on android 11
References: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
 <83im51deye.fsf@HIDDEN>
 <730dad3a54f0f53b22e9603879e949b60f5b2c00.camel@HIDDEN>
 <191e2295b88384adf0e7cc1e3dc84cf8f37eb973.camel@HIDDEN>
 <838s5wdhef.fsf@HIDDEN>
 <2215b2299da65d790a705d9b83051028a1a2b693.camel@HIDDEN>
X-Now-Playing: Nico's _Do Or Die_: "Femme Fatale"
Date: Thu, 06 May 2021 12:45:17 +0200
In-Reply-To: <2215b2299da65d790a705d9b83051028a1a2b693.camel@HIDDEN>
 (Henrik Grimler's message of "Mon, 05 Apr 2021 19:29:52 +0200")
Message-ID: <87k0ocw37m.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 
 Content preview:  Henrik Grimler <henrik@HIDDEN> writes: >> > In emacs fdopen
    is run in init_standard_fds, where we have >> > >> >   force_open (STDERR_FILENO,
    O_RDONLY); >> > >> >   /* Set buferr if possible on platforms defining _PC_PIPE_BUF,
    as >> >   [...] 
 
 Content analysis details:   (-2.9 points, 5.0 required)
 
  pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
                             [score: 0.0000]
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 47596
Cc: Eli Zaretskii <eliz@HIDDEN>, 47596 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Henrik Grimler <henrik@HIDDEN> writes:

>> > In emacs fdopen is run in init_standard_fds, where we have
>> >=20
>> > =C2=A0 force_open (STDERR_FILENO, O_RDONLY);
>> >=20
>> > =C2=A0 /* Set buferr if possible on platforms defining _PC_PIPE_BUF, as
>> > =C2=A0=C2=A0=C2=A0=C2=A0 they support the notion of atomic writes to p=
ipes.=C2=A0 */
>> > =C2=A0 #ifdef _PC_PIPE_BUF
>> > =C2=A0=C2=A0=C2=A0 buferr =3D fdopen (STDERR_FILENO, "w");
>> > =C2=A0=C2=A0=C2=A0 if (buferr)
>> > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 setvbuf (buferr, NULL, _IOLBF, 0);
>> > =C2=A0 #endif
>> > }
>>=20
>> This just creates a copy of stderr that has special buffering.=C2=A0
>> Again,
>> entirely valid for a C program to do that.
>
> I probably should have included a bit more context in the android bug
> report to better show what the code does.=20

Did you try to include this context in the Android bug report and see
what they say then?

--=20
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47596; Package emacs. Full text available.

Message received at 47596 <at> debbugs.gnu.org:


Received: (at 47596) by debbugs.gnu.org; 5 Apr 2021 17:30:03 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 05 13:30:03 2021
Received: from localhost ([127.0.0.1]:38516 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lTT34-0008Ub-Pa
	for submit <at> debbugs.gnu.org; Mon, 05 Apr 2021 13:30:03 -0400
Received: from h04mx15.reliablemail.org ([185.76.67.208]:28870)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <henrik@HIDDEN>) id 1lTT32-0008Tg-Vw
 for 47596 <at> debbugs.gnu.org; Mon, 05 Apr 2021 13:30:01 -0400
X-Halon-Out: 88601665-9634-11eb-a4a4-354a41e2f763
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=grimler.se; 
 s=default;
 h=Content-Transfer-Encoding:MIME-Version:Content-Type:References:
 In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To:Content-ID:
 Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
 :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=aYBTpUNHsQcYbQb54i+nZfmQUJQ15WlS72RoAqpAKcA=; b=W0qRIt/+FVjPDOubghonO+EfoI
 VFdTTnQCyokeh8MWD4efzUXVFFUUt3RCJDM1buLxBIzd6WCNBR0I7Gli9KhDdKxdd/S6m6EXRb1Yy
 fKenIJToTb62hTh2J2yz3XeexUyL2Vwc562XcHyhiqPq/7StGzyZc3NlVyodd0830n+/NFGL3WLcd
 vqnDfEx1yv7gXPctP5P7JTKnX8VRwLsSpkgwrJ+X5sJPnKMmGOPcbPrPCBV0/92GbZucIr7rJ5q9x
 lwZtScRXpDln5DwsMO4/rp8zSOBmMl2z9VeUeG7AVTe+ukVHcPtjnQHjxla6eJfKz00hcE2cMP/uH
 m/nTPMOw==;
Message-ID: <2215b2299da65d790a705d9b83051028a1a2b693.camel@HIDDEN>
Subject: Re: bug#47596: File descriptor error when exiting emacs on android 11
From: Henrik Grimler <henrik@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Date: Mon, 05 Apr 2021 19:29:52 +0200
In-Reply-To: <838s5wdhef.fsf@HIDDEN>
References: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
 <83im51deye.fsf@HIDDEN>
 <730dad3a54f0f53b22e9603879e949b60f5b2c00.camel@HIDDEN>
 <191e2295b88384adf0e7cc1e3dc84cf8f37eb973.camel@HIDDEN>
 <838s5wdhef.fsf@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.38.4 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-OutGoing-Spam-Status: No, score=-1.0
X-AntiAbuse: This header was added to track abuse,
 please include it with any abuse report
X-AntiAbuse: Primary Hostname - cpsrv07.misshosting.com
X-AntiAbuse: Original Domain - debbugs.gnu.org
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - grimler.se
X-Get-Message-Sender-Via: cpsrv07.misshosting.com: authenticated_id:
 henrik@HIDDEN
X-Authenticated-Sender: cpsrv07.misshosting.com: henrik@HIDDEN
X-Source: 
X-Source-Args: 
X-Source-Dir: 
X-Spam-Score: 2.3 (++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 
 Content preview:  Hi, I received feedback on the android issue tracker  https://issuetracker.google.com/issues/184380442 
    that the snippet: > > #include <stdio.h> > > int main() > > { > >   fdopen
    (2, "w"); > >   fclose (stderr); > > } 
 
 Content analysis details:   (2.3 points, 10.0 required)
 
  pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_PASS               SPF: sender matches SPF record
  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
  2.3 HAS_X_OUTGOING_SPAM_STAT Has header claiming outbound spam scan
                             - why trust the results?
X-Debbugs-Envelope-To: 47596
Cc: 47596 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi,

I received feedback on the android issue tracker 
https://issuetracker.google.com/issues/184380442 
that the snippet:

> > #include <stdio.h>
> > int main()
> > {
> >   fdopen (2, "w");
> >   fclose (stderr);
> > }

is problematic, because:

> yes. you have two FILE*s that both think they own file descriptor 2.
> depending on what you're actually trying to do, you probably meant to
> use freopen(3) instead?
https://man7.org/linux/man-pages/man3/fopen.3.html

Does freopen make sense for buferr?

> > In emacs fdopen is run in init_standard_fds, where we have
> > 
> >   force_open (STDERR_FILENO, O_RDONLY);
> > 
> >   /* Set buferr if possible on platforms defining _PC_PIPE_BUF, as
> >      they support the notion of atomic writes to pipes.  */
> >   #ifdef _PC_PIPE_BUF
> >     buferr = fdopen (STDERR_FILENO, "w");
> >     if (buferr)
> >       setvbuf (buferr, NULL, _IOLBF, 0);
> >   #endif
> > }
> 
> This just creates a copy of stderr that has special buffering. 
> Again,
> entirely valid for a C program to do that.

I probably should have included a bit more context in the android bug
report to better show what the code does. 

Best regards,
Henrik Grimler






Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47596; Package emacs. Full text available.

Message received at 47596 <at> debbugs.gnu.org:


Received: (at 47596) by debbugs.gnu.org; 5 Apr 2021 13:38:44 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 05 09:38:44 2021
Received: from localhost ([127.0.0.1]:37290 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lTPRE-0004Xz-7T
	for submit <at> debbugs.gnu.org; Mon, 05 Apr 2021 09:38:44 -0400
Received: from h03mx16.reliablemail.org ([173.236.90.20]:24384)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <henrik@HIDDEN>) id 1lTPRB-0004Xq-EU
 for 47596 <at> debbugs.gnu.org; Mon, 05 Apr 2021 09:38:42 -0400
X-Halon-Out: 3a21af12-9614-11eb-947f-00163c72d6d3
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=grimler.se; 
 s=default;
 h=Content-Transfer-Encoding:MIME-Version:Content-Type:References:
 In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To:Content-ID:
 Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
 :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=Qd71lnnktJlWNpVfYyNwtyKiAa2ZFuyhiPfz8ODSlqs=; b=OpuldSvmvCg92BBgJejRc/1fNR
 UjqyoikjtX2twwa6IRt5gENCS02s56Gwfg3hDgvXfr1ZwuGSpkmasalMYfq7Fa5PseGAXFtXUYmLl
 VeRftTT6LPtGqGqrmgIWYi/LlafU2HR0FFvn+nnbJ8BS+2+RQv08+IkjZH5ebvg+SLcNu4xsq+ALS
 3JftJ/uE3QGCs02lMw66brRi13Gd8pm+IxL2D6PJdz14hIIwAj39FNaM8rOekTvIBWh2Gxg4ua2aS
 8v2qZTFuxB1UIer7+UZPRbi/xGXCxHsOprKg6FPUK8OpybBv8qhIa3INo0li+Pf6DDogwMoDlU04H
 s2s42Vug==;
Message-ID: <ee1ec93437c031e560bfe55cde75c0bc630e4bea.camel@HIDDEN>
Subject: Re: bug#47596: File descriptor error when exiting emacs on android 11
From: Henrik Grimler <henrik@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Date: Mon, 05 Apr 2021 15:38:36 +0200
In-Reply-To: <835z10dh2u.fsf@HIDDEN>
References: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
 <83im51deye.fsf@HIDDEN>
 <730dad3a54f0f53b22e9603879e949b60f5b2c00.camel@HIDDEN>
 <191e2295b88384adf0e7cc1e3dc84cf8f37eb973.camel@HIDDEN>
 <576632572a00e4ec75b92344cd6cd8957df42820.camel@HIDDEN>
 <aebd3ec4283ee06473e7e5d69efcddc2d409b867.camel@HIDDEN>
 <835z10dh2u.fsf@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.38.4 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-OutGoing-Spam-Status: No, score=-1.0
X-AntiAbuse: This header was added to track abuse,
 please include it with any abuse report
X-AntiAbuse: Primary Hostname - cpsrv07.misshosting.com
X-AntiAbuse: Original Domain - debbugs.gnu.org
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - grimler.se
X-Get-Message-Sender-Via: cpsrv07.misshosting.com: authenticated_id:
 henrik@HIDDEN
X-Authenticated-Sender: cpsrv07.misshosting.com: henrik@HIDDEN
X-Source: 
X-Source-Args: 
X-Source-Dir: 
X-Spam-Score: 2.3 (++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 
 Content preview:  Hi, > You are operating on the wrong stream, so I do see a
    problem with this > patch.  The purpose of this fragment is to close stderr,
    not the > buffered copy of stderr. > Thanks for the feedback! 
 
 Content analysis details:   (2.3 points, 10.0 required)
 
  pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/,
                              no trust
                             [173.236.90.20 listed in list.dnswl.org]
 -0.0 SPF_PASS               SPF: sender matches SPF record
  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
  2.3 HAS_X_OUTGOING_SPAM_STAT Has header claiming outbound spam scan
                             - why trust the results?
X-Debbugs-Envelope-To: 47596
Cc: 47596 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)


Hi,

> You are operating on the wrong stream, so I do see a problem with this
> patch.  The purpose of this fragment is to close stderr, not the
> buffered copy of stderr.

> 
Thanks for the feedback!

> Is ADDRESS_SANITIZER defined in your build?

Yes, it is configured with emacs_cv_sanitize_address=yes. Setting this
option has been done for android since emacs 25, and supposedly fixed
some malloc issue back then [1]. I tried building without setting
emacs_cv_sanitize_address=yes just now (configure then sets =no), but
it does not seem to influence this fdsan error.

> In any case, I do want to wait for the Android developers to respond
> to the issue in their tracker.

I will update the issue and add the minimal non-working example
obtained here as well.

Best regards,
Henrik Grimler

[1]
https://github.com/termux/termux-packages/commit/8ce98d7fe9130cd151cc2ec34b3b1e7ecb0aeace#diff-8fd6b84ed67057870fa4f209d2309b53bf3c097b732cb3b8e639f58a37d138c1R7





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47596; Package emacs. Full text available.

Message received at 47596 <at> debbugs.gnu.org:


Received: (at 47596) by debbugs.gnu.org; 5 Apr 2021 12:57:57 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 05 08:57:57 2021
Received: from localhost ([127.0.0.1]:37271 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lTOnl-0003Rj-Bw
	for submit <at> debbugs.gnu.org; Mon, 05 Apr 2021 08:57:57 -0400
Received: from eggs.gnu.org ([209.51.188.92]:49582)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1lTOnk-0003RX-3x
 for 47596 <at> debbugs.gnu.org; Mon, 05 Apr 2021 08:57:56 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:57829)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1lTOne-00050l-RT; Mon, 05 Apr 2021 08:57:50 -0400
Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4866
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1lTOnd-00070T-FP; Mon, 05 Apr 2021 08:57:50 -0400
Date: Mon, 05 Apr 2021 15:57:45 +0300
Message-Id: <835z10dh2u.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Henrik Grimler <henrik@HIDDEN>
In-Reply-To: <aebd3ec4283ee06473e7e5d69efcddc2d409b867.camel@HIDDEN>
 (message from Henrik Grimler on Mon, 05 Apr 2021 11:48:50 +0200)
Subject: Re: bug#47596: File descriptor error when exiting emacs on android 11
References: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
 <83im51deye.fsf@HIDDEN>
 <730dad3a54f0f53b22e9603879e949b60f5b2c00.camel@HIDDEN>
 <191e2295b88384adf0e7cc1e3dc84cf8f37eb973.camel@HIDDEN>
 <576632572a00e4ec75b92344cd6cd8957df42820.camel@HIDDEN>
 <aebd3ec4283ee06473e7e5d69efcddc2d409b867.camel@HIDDEN>
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 47596
Cc: 47596 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

> From: Henrik Grimler <henrik@HIDDEN>
> Cc: 47596 <at> debbugs.gnu.org
> Date: Mon, 05 Apr 2021 11:48:50 +0200
> 
> A better way to fix the error is to use buferr instead of stderr when
> calling `close_streams` in `close_output_streams`. I cannot see any
> obvious problems with this, so I propose this patch:

You are operating on the wrong stream, so I do see a problem with this
patch.  The purpose of this fragment is to close stderr, not the
buffered copy of stderr.

> --- ./src/sysdep.c.orig	2021-04-05 09:06:33.847835653 +0000
> +++ ./src/sysdep.c	2021-04-05 09:05:47.957856162 +0000
> @@ -2837,8 +2837,8 @@
>       sanitizer might report to stderr after this function is invoked.
> */
>    bool err = buferr && (fflush (buferr) != 0 || ferror (buferr));
>    if (err | (ADDRESS_SANITIZER
> -	     ? fflush (stderr) != 0 || ferror (stderr)
> -	     : close_stream (stderr) != 0))
> +	     ? fflush (buferr) != 0 || ferror (buferr)
> +	     : close_stream (buferr) != 0))
>      _exit (EXIT_FAILURE);
>  }
>  ^L
> ```
> 
> With it I can start and exit emacs on android without the fdsan error. 

Is ADDRESS_SANITIZER defined in your build?

In any case, I do want to wait for the Android developers to respond
to the issue in their tracker.

Thanks.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47596; Package emacs. Full text available.

Message received at 47596 <at> debbugs.gnu.org:


Received: (at 47596) by debbugs.gnu.org; 5 Apr 2021 12:52:35 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 05 08:52:34 2021
Received: from localhost ([127.0.0.1]:37264 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lTOiY-0003K4-N8
	for submit <at> debbugs.gnu.org; Mon, 05 Apr 2021 08:52:34 -0400
Received: from eggs.gnu.org ([209.51.188.92]:48622)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1lTOiW-0003JZ-NZ
 for 47596 <at> debbugs.gnu.org; Mon, 05 Apr 2021 08:52:33 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:57793)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1lTOiR-0001ad-Fr; Mon, 05 Apr 2021 08:52:27 -0400
Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4518
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1lTOiQ-0004V6-UN; Mon, 05 Apr 2021 08:52:27 -0400
Date: Mon, 05 Apr 2021 15:52:22 +0300
Message-Id: <837dlgdhbt.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Henrik Grimler <henrik@HIDDEN>
In-Reply-To: <576632572a00e4ec75b92344cd6cd8957df42820.camel@HIDDEN>
 (message from Henrik Grimler on Mon, 05 Apr 2021 10:59:55 +0200)
Subject: Re: bug#47596: File descriptor error when exiting emacs on android 11
References: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
 <83im51deye.fsf@HIDDEN>
 <730dad3a54f0f53b22e9603879e949b60f5b2c00.camel@HIDDEN>
 <191e2295b88384adf0e7cc1e3dc84cf8f37eb973.camel@HIDDEN>
 <576632572a00e4ec75b92344cd6cd8957df42820.camel@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 47596
Cc: 47596 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

> From: Henrik Grimler <henrik@HIDDEN>
> Cc: 47596 <at> debbugs.gnu.org
> Date: Mon, 05 Apr 2021 10:59:55 +0200
> 
> > #include <stdio.h>
> > int main()
> > {
> >   fdopen (2, "w");
> >   fclose (stderr);
> > }
> > ```
> 
> Changing to this:
> 
> ```
> 
> #include <stdio.h>
> int main()
> {
>   FILE *err = fdopen (2, "w");
>   fclose (err);
> }
> ```
> 
> makes it work.

Which again makes no sense, because the program that works is a no-op:
it creates a copy of stderr and immediately closes it.

> So I suppose the sanitizer does not like that stderr is
> closed with `fclose (stderr)` instead of by using the fd obtained from
> fdopen (which was thrown away in my minimal example). 
> 
> Still not sure if this is actually problematic, but at least now I
> understand how the sanitizer "thinks".

If that's what it thinks, it's a clear bug in the sanitizer, IMO.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47596; Package emacs. Full text available.

Message received at 47596 <at> debbugs.gnu.org:


Received: (at 47596) by debbugs.gnu.org; 5 Apr 2021 12:51:00 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 05 08:51:00 2021
Received: from localhost ([127.0.0.1]:37254 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lTOh2-0003HB-Br
	for submit <at> debbugs.gnu.org; Mon, 05 Apr 2021 08:51:00 -0400
Received: from eggs.gnu.org ([209.51.188.92]:48294)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1lTOh0-0003Gz-Nw
 for 47596 <at> debbugs.gnu.org; Mon, 05 Apr 2021 08:50:59 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:57783)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1lTOgu-0000e2-JL; Mon, 05 Apr 2021 08:50:52 -0400
Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4422
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1lTOgt-0004PQ-TX; Mon, 05 Apr 2021 08:50:52 -0400
Date: Mon, 05 Apr 2021 15:50:48 +0300
Message-Id: <838s5wdhef.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Henrik Grimler <henrik@HIDDEN>
In-Reply-To: <191e2295b88384adf0e7cc1e3dc84cf8f37eb973.camel@HIDDEN>
 (message from Henrik Grimler on Mon, 05 Apr 2021 10:14:10 +0200)
Subject: Re: bug#47596: File descriptor error when exiting emacs on android 11
References: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
 <83im51deye.fsf@HIDDEN>
 <730dad3a54f0f53b22e9603879e949b60f5b2c00.camel@HIDDEN>
 <191e2295b88384adf0e7cc1e3dc84cf8f37eb973.camel@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 47596
Cc: 47596 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

> From: Henrik Grimler <henrik@HIDDEN>
> Cc: 47596 <at> debbugs.gnu.org
> Date: Mon, 05 Apr 2021 10:14:10 +0200
> 
> Compiling this, on any optimisation level, is enough to trigger the
> error:
> 
> ```
> #include <stdio.h>
> int main()
> {
>   fdopen (2, "w");
>   fclose (stderr);
> }
> ```

Any idea why?  It makes no sense to me, and the above is an entirely
valid program, AFAICT.

> In emacs fdopen is run in init_standard_fds, where we have
> 
> ```
> [...]
> 
>   force_open (STDERR_FILENO, O_RDONLY);
> 
>   /* Set buferr if possible on platforms defining _PC_PIPE_BUF, as
>      they support the notion of atomic writes to pipes.  */
>   #ifdef _PC_PIPE_BUF
>     buferr = fdopen (STDERR_FILENO, "w");
>     if (buferr)
>       setvbuf (buferr, NULL, _IOLBF, 0);
>   #endif
> }
> ```

This just creates a copy of stderr that has special buffering.  Again,
entirely valid for a C program to do that.

> so I suppose there is either some very fundamental issue with 
> `fdopen (STDERR_FILENO, "w")` here, or the file descriptor sanitizer on
> android is broken.

Likely the latter, so I'm reluctant to make any changes in Emacs until
the issue you opened against Android gets some response that makes
sense.

> If I avoid that part of init_standard_fds, i.e. change the ifdef to
> something like `#if defined(_PC_PIPE_BUF) && !defined(__ANDROID__)`, I
> get an emacs that seem to fully work on android.

Feel free to make such changes in your copy, but I'd prefer not to
change Emacs until the root cause behind these weird problems becomes
clear.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47596; Package emacs. Full text available.

Message received at 47596 <at> debbugs.gnu.org:


Received: (at 47596) by debbugs.gnu.org; 5 Apr 2021 09:48:57 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 05 05:48:57 2021
Received: from localhost ([127.0.0.1]:36962 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lTLqr-0004Qu-7c
	for submit <at> debbugs.gnu.org; Mon, 05 Apr 2021 05:48:57 -0400
Received: from h01mx15.reliablemail.org ([173.236.5.211]:13393)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <henrik@HIDDEN>) id 1lTLqo-0004Ql-PF
 for 47596 <at> debbugs.gnu.org; Mon, 05 Apr 2021 05:48:56 -0400
X-Halon-Out: 20938dc8-95f4-11eb-a316-00163c81f1a9
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=grimler.se; 
 s=default;
 h=Content-Transfer-Encoding:MIME-Version:Content-Type:References:
 In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To:Content-ID:
 Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
 :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=1sJHJzOYAkicYUVcAj5F7bqAGyptyvgKybtxzim8evs=; b=UlC+oBRqBXrFg6sMYPOZH1FD0q
 MeXn9ZOmdWWj3JFlHPyQERo/k/6V4vyBPJttOwT3aP49NTQ/BiRvKLsQ+pkqZivV5HNwxs4eTgFhn
 Zp1eJ4zdalrG+lkg9uX9lBlveW24GcTtLY/fv/tsldNg7CwiyD/hjkRmth4T3RlASHVr/SHVu4kHM
 oD4Hcmf036SiBsm1G0O3SMByJkMsyGi9WlmX5mGIVzHuQ+jd08FBefXJv8BFdbOCTzzIARRSoL763
 9RJ/V6I+MSz4sTZp1p00S0sWCwDYjm663pj5h7k+oT3HGIZgz8A8ZJVTWy2KgJXcYx9LRzrHk3AyA
 TId2Uuzg==;
Message-ID: <aebd3ec4283ee06473e7e5d69efcddc2d409b867.camel@HIDDEN>
Subject: Re: bug#47596: File descriptor error when exiting emacs on android 11
From: Henrik Grimler <henrik@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Date: Mon, 05 Apr 2021 11:48:50 +0200
In-Reply-To: <576632572a00e4ec75b92344cd6cd8957df42820.camel@HIDDEN>
References: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
 <83im51deye.fsf@HIDDEN>
 <730dad3a54f0f53b22e9603879e949b60f5b2c00.camel@HIDDEN>
 <191e2295b88384adf0e7cc1e3dc84cf8f37eb973.camel@HIDDEN>
 <576632572a00e4ec75b92344cd6cd8957df42820.camel@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.38.4 
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-OutGoing-Spam-Status: No, score=-1.0
X-AntiAbuse: This header was added to track abuse,
 please include it with any abuse report
X-AntiAbuse: Primary Hostname - cpsrv07.misshosting.com
X-AntiAbuse: Original Domain - debbugs.gnu.org
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - grimler.se
X-Get-Message-Sender-Via: cpsrv07.misshosting.com: authenticated_id:
 henrik@HIDDEN
X-Authenticated-Sender: cpsrv07.misshosting.com: henrik@HIDDEN
X-Source: 
X-Source-Args: 
X-Source-Dir: 
X-Spam-Score: 2.0 (++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview:  Hi, A better way to fix the error is to use buferr instead
 of stderr when calling `close_streams` in `close_output_streams`. I cannot
 see any obvious problems with this, so I propose this patch: ``` 
 Content analysis details:   (2.0 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
 -0.0 SPF_PASS               SPF: sender matches SPF record
 -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/,
 no trust [173.236.5.211 listed in list.dnswl.org]
 2.0 HAS_X_OUTGOING_SPAM_STAT Has header claiming outbound spam scan
 - why trust the results?
X-Debbugs-Envelope-To: 47596
Cc: 47596 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi,

A better way to fix the error is to use buferr instead of stderr when
calling `close_streams` in `close_output_streams`. I cannot see any
obvious problems with this, so I propose this patch:

```

--- ./src/sysdep.c.orig	2021-04-05 09:06:33.847835653 +0000
+++ ./src/sysdep.c	2021-04-05 09:05:47.957856162 +0000
@@ -2837,8 +2837,8 @@
      sanitizer might report to stderr after this function is invoked.
*/
   bool err = buferr && (fflush (buferr) != 0 || ferror (buferr));
   if (err | (ADDRESS_SANITIZER
-	     ? fflush (stderr) != 0 || ferror (stderr)
-	     : close_stream (stderr) != 0))
+	     ? fflush (buferr) != 0 || ferror (buferr)
+	     : close_stream (buferr) != 0))
     _exit (EXIT_FAILURE);
 }
 ^L
```

With it I can start and exit emacs on android without the fdsan error. 

Best regards,
Henrik Grimler





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47596; Package emacs. Full text available.

Message received at 47596 <at> debbugs.gnu.org:


Received: (at 47596) by debbugs.gnu.org; 5 Apr 2021 09:00:09 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 05 05:00:09 2021
Received: from localhost ([127.0.0.1]:36907 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lTL5c-0003DU-6h
	for submit <at> debbugs.gnu.org; Mon, 05 Apr 2021 05:00:08 -0400
Received: from h04mx15.reliablemail.org ([185.76.67.208]:21263)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <henrik@HIDDEN>) id 1lTL5X-0003CO-2R
 for 47596 <at> debbugs.gnu.org; Mon, 05 Apr 2021 05:00:05 -0400
X-Halon-Out: 4ab7deb2-95ed-11eb-a4a4-354a41e2f763
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=grimler.se; 
 s=default;
 h=Content-Transfer-Encoding:MIME-Version:Content-Type:References:
 In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To:Content-ID:
 Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
 :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=g1ibhrf5csf6JlttFjsb587sMPIGpuijfDtsNbLKTAg=; b=oGOjxladP9XBgwcwtvdbRcPRzf
 US3CO2UfQLNXeC6FIqizqDOag5WdIv6t64zixBRfoQlvjz+kPOAM+lTHzcu814YriLYlt4CslE4ZA
 TGwIs4DMN/JFlhzffFtlK7HmCrOZs8LkMibXfXN7fIxH6IbVEA/YCirSjDMsO8mgOSkYGCKbZMjmW
 Drp4RHd8fOY0ktbbdecOw9JXgzLQzKAChmYAtth2mODlHiRP5vLYNQdGiG7Y/NiSBFwvFR8vhubmW
 c3L1QQpLEbyYTUzohYI+nXvCUv/Ago5XGg9Fk92XjntohnEu435qHAwZkFSUPP/iNBpYHYvpXBfTi
 wq45ae/g==;
Message-ID: <576632572a00e4ec75b92344cd6cd8957df42820.camel@HIDDEN>
Subject: Re: bug#47596: File descriptor error when exiting emacs on android 11
From: Henrik Grimler <henrik@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Date: Mon, 05 Apr 2021 10:59:55 +0200
In-Reply-To: <191e2295b88384adf0e7cc1e3dc84cf8f37eb973.camel@HIDDEN>
References: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
 <83im51deye.fsf@HIDDEN>
 <730dad3a54f0f53b22e9603879e949b60f5b2c00.camel@HIDDEN>
 <191e2295b88384adf0e7cc1e3dc84cf8f37eb973.camel@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.38.4 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-OutGoing-Spam-Status: No, score=-1.0
X-AntiAbuse: This header was added to track abuse,
 please include it with any abuse report
X-AntiAbuse: Primary Hostname - cpsrv07.misshosting.com
X-AntiAbuse: Original Domain - debbugs.gnu.org
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - grimler.se
X-Get-Message-Sender-Via: cpsrv07.misshosting.com: authenticated_id:
 henrik@HIDDEN
X-Authenticated-Sender: cpsrv07.misshosting.com: henrik@HIDDEN
X-Source: 
X-Source-Args: 
X-Source-Dir: 
X-Spam-Score: 2.0 (++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 
 Content preview:  Hi again, > Compiling this, on any optimisation level, is
   enough to trigger the > error: > > ``` > #include <stdio.h> > int main() >
    { >   fdopen (2, "w"); >   fclose (stderr); > } > ``` Changing to this:
    
 
 Content analysis details:   (2.0 points, 10.0 required)
 
  pts rule name              description
 ---- ---------------------- --------------------------------------------------
  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
 -0.0 SPF_PASS               SPF: sender matches SPF record
  2.0 HAS_X_OUTGOING_SPAM_STAT Has header claiming outbound spam scan
                             - why trust the results?
X-Debbugs-Envelope-To: 47596
Cc: 47596 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi again,


> Compiling this, on any optimisation level, is enough to trigger the
> error:
> 
> ```
> #include <stdio.h>
> int main()
> {
>   fdopen (2, "w");
>   fclose (stderr);
> }
> ```

Changing to this:

```

#include <stdio.h>
int main()
{
  FILE *err = fdopen (2, "w");
  fclose (err);
}
```

makes it work. So I suppose the sanitizer does not like that stderr is
closed with `fclose (stderr)` instead of by using the fd obtained from
fdopen (which was thrown away in my minimal example). 

Still not sure if this is actually problematic, but at least now I
understand how the sanitizer "thinks".

Best regards,
Henrik Grimler





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47596; Package emacs. Full text available.

Message received at 47596 <at> debbugs.gnu.org:


Received: (at 47596) by debbugs.gnu.org; 5 Apr 2021 08:14:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 05 04:14:16 2021
Received: from localhost ([127.0.0.1]:36871 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lTKNE-00027n-IJ
	for submit <at> debbugs.gnu.org; Mon, 05 Apr 2021 04:14:16 -0400
Received: from h01mx15.reliablemail.org ([173.236.5.211]:38050)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <henrik@HIDDEN>) id 1lTKNC-00027d-KC
 for 47596 <at> debbugs.gnu.org; Mon, 05 Apr 2021 04:14:15 -0400
X-Halon-Out: e6a85747-95e6-11eb-a316-00163c81f1a9
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=grimler.se; 
 s=default;
 h=Content-Transfer-Encoding:MIME-Version:Content-Type:References:
 In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To:Content-ID:
 Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
 :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=lmS1AS4xpM7AxOPttqEKoGWimx6FIoKw36szMqycq3k=; b=g+ss6j5G40vSA6tTgsAiHTnvMR
 KSQ7BK+RpwQI9EttJxSMyKjmuwXkxiAl7atPOuLNpCNY1QNgvettvuQIU86PHqJmsQPtiBdQv1MT2
 TcmLpz4yto4NBlORfcoUKLIgFSgiDpdmg6EfJRnl2TsiH6Hl37I+EnYo4u2ziA8RkdX8hNMn1x5Dg
 03YxehBJzUsEkngGzN7DOBrpfSYv220abBWu/dqqCKyGasTA/NGh0auJ5fRldP81NgB7dbnP4w9o6
 Y8NKjVvH7nvU0+LAsemEuygjgF+3ctBYOLl6Hit2lnrIgDy2B8MStkr2BEWTD5dcxkAcDVabqr29W
 BrpKyL5w==;
Message-ID: <191e2295b88384adf0e7cc1e3dc84cf8f37eb973.camel@HIDDEN>
Subject: Re: bug#47596: File descriptor error when exiting emacs on android 11
From: Henrik Grimler <henrik@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Date: Mon, 05 Apr 2021 10:14:10 +0200
In-Reply-To: <730dad3a54f0f53b22e9603879e949b60f5b2c00.camel@HIDDEN>
References: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
 <83im51deye.fsf@HIDDEN>
 <730dad3a54f0f53b22e9603879e949b60f5b2c00.camel@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.38.4 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-OutGoing-Spam-Status: No, score=-1.0
X-AntiAbuse: This header was added to track abuse,
 please include it with any abuse report
X-AntiAbuse: Primary Hostname - cpsrv07.misshosting.com
X-AntiAbuse: Original Domain - debbugs.gnu.org
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - grimler.se
X-Get-Message-Sender-Via: cpsrv07.misshosting.com: authenticated_id:
 henrik@HIDDEN
X-Authenticated-Sender: cpsrv07.misshosting.com: henrik@HIDDEN
X-Source: 
X-Source-Args: 
X-Source-Dir: 
X-Spam-Score: 2.0 (++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview:  Hi, Compiling this, on any optimisation level, is enough to
 trigger the error: ``` #include <stdio.h> int main() { fdopen (2, "w"); fclose
 (stderr); } ``` 
 Content analysis details:   (2.0 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/,
 no trust [173.236.5.211 listed in list.dnswl.org]
 0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
 -0.0 SPF_PASS               SPF: sender matches SPF record
 2.0 HAS_X_OUTGOING_SPAM_STAT Has header claiming outbound spam scan
 - why trust the results?
X-Debbugs-Envelope-To: 47596
Cc: 47596 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi,

Compiling this, on any optimisation level, is enough to trigger the
error:

```
#include <stdio.h>
int main()
{
  fdopen (2, "w");
  fclose (stderr);
}
```

In emacs fdopen is run in init_standard_fds, where we have

```
[...]

  force_open (STDERR_FILENO, O_RDONLY);

  /* Set buferr if possible on platforms defining _PC_PIPE_BUF, as
     they support the notion of atomic writes to pipes.  */
  #ifdef _PC_PIPE_BUF
    buferr = fdopen (STDERR_FILENO, "w");
    if (buferr)
      setvbuf (buferr, NULL, _IOLBF, 0);
  #endif
}
```

so I suppose there is either some very fundamental issue with 
`fdopen (STDERR_FILENO, "w")` here, or the file descriptor sanitizer on
android is broken.

If I avoid that part of init_standard_fds, i.e. change the ifdef to
something like `#if defined(_PC_PIPE_BUF) && !defined(__ANDROID__)`, I
get an emacs that seem to fully work on android.

Best regards,
Henrik Grimler





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47596; Package emacs. Full text available.

Message received at 47596 <at> debbugs.gnu.org:


Received: (at 47596) by debbugs.gnu.org; 4 Apr 2021 20:11:34 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 04 16:11:34 2021
Received: from localhost ([127.0.0.1]:36517 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lT95p-0003eI-TF
	for submit <at> debbugs.gnu.org; Sun, 04 Apr 2021 16:11:34 -0400
Received: from h04mx15.reliablemail.org ([185.76.67.208]:51673)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <henrik@HIDDEN>) id 1lT95o-0003e3-Vi
 for 47596 <at> debbugs.gnu.org; Sun, 04 Apr 2021 16:11:33 -0400
X-Halon-Out: eeee1671-9581-11eb-a4a4-354a41e2f763
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=grimler.se; 
 s=default;
 h=Content-Transfer-Encoding:MIME-Version:Content-Type:References:
 In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To:Content-ID:
 Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
 :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=oU/oXhbyhltySj6q0/BM5qF6evgkK103HjOI8zwyej8=; b=HdgDfWTuisG+pOCBxcpscs9MGj
 7KUOe3Bkk0MHPvDM4GJL7a9GvOTCQ3/MP1/Kscnz+pRoXOEpQ5c89048xjh8WdiK72TGw721NULKU
 BCsWX0I+g6vZ5Aaf8nPLrfQ4qISbS51x2Xt+SGDZ7Uy78CXUpW0EJbWI3xk/MUzQZPTL/JY09BphG
 qFZmHSkwJTRDkby2qzINDMj/iTAWPw3/3VCd+3crvRjy1h5XZ4sY7cBOyfaOOBdPe5wANVkLX40Sk
 NkqcjT9QvanYU8OlruQILcuAZQITcC4mkd3IrQAZYnKrR/Sg609ZJzkOelBwyl845INU0oDiE53OT
 P2murpQg==;
Message-ID: <730dad3a54f0f53b22e9603879e949b60f5b2c00.camel@HIDDEN>
Subject: Re: bug#47596: File descriptor error when exiting emacs on android 11
From: Henrik Grimler <henrik@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Date: Sun, 04 Apr 2021 22:11:24 +0200
In-Reply-To: <83im51deye.fsf@HIDDEN>
References: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
 <83im51deye.fsf@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.38.4 
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-OutGoing-Spam-Status: No, score=-1.0
X-AntiAbuse: This header was added to track abuse,
 please include it with any abuse report
X-AntiAbuse: Primary Hostname - cpsrv07.misshosting.com
X-AntiAbuse: Original Domain - debbugs.gnu.org
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - grimler.se
X-Get-Message-Sender-Via: cpsrv07.misshosting.com: authenticated_id:
 henrik@HIDDEN
X-Authenticated-Sender: cpsrv07.misshosting.com: henrik@HIDDEN
X-Source: 
X-Source-Args: 
X-Source-Dir: 
X-Spam-Score: 2.0 (++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview:  Hi, > > Based on the backtrace it seem to be how stderr is
 opened (and > > closed) > > that is problematic somehow. > > Any idea what
 was "the other thread" involved in this situation? > Emacs is generall [...]
 Content analysis details:   (2.0 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
 -0.0 SPF_PASS               SPF: sender matches SPF record
 2.0 HAS_X_OUTGOING_SPAM_STAT Has header claiming outbound spam scan
 - why trust the results?
X-Debbugs-Envelope-To: 47596
Cc: 47596 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)


Hi,

> > Based on the backtrace it seem to be how stderr is opened (and
> > closed)
> > that is problematic somehow.
> 
> Any idea what was "the other thread" involved in this situation?
> Emacs is generally a single-threaded program.

I do not know unfortunately. I am not entirely certain the sanitizer is
trustworthy yet (but since it is active per default now I suppose it
should have been tested extensively). 

Tests so far show that optimisation level, and compiler, can influence
if these error occur or not, but for emacs it happens with -O0 as well
with clang-11. I opened an issue on the android issue tracker about the
fd sanitizer after investigating a fdsan error for texlive, since I do
not understand what the issue in the minimal example there is. We will
see what they say about it:
https://issuetracker.google.com/issues/184380442

Best regards,
Henrik Grimler





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47596; Package emacs. Full text available.

Message received at 47596 <at> debbugs.gnu.org:


Received: (at 47596) by debbugs.gnu.org; 4 Apr 2021 19:31:39 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 04 15:31:39 2021
Received: from localhost ([127.0.0.1]:36473 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lT8TD-0000Za-62
	for submit <at> debbugs.gnu.org; Sun, 04 Apr 2021 15:31:39 -0400
Received: from eggs.gnu.org ([209.51.188.92]:38286)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1lT8TB-0000ZO-Sn
 for 47596 <at> debbugs.gnu.org; Sun, 04 Apr 2021 15:31:38 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:44706)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1lT8T4-0001N5-IO; Sun, 04 Apr 2021 15:31:31 -0400
Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4730
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1lT8T3-0002Xw-NP; Sun, 04 Apr 2021 15:31:30 -0400
Date: Sun, 04 Apr 2021 22:31:21 +0300
Message-Id: <83im51deye.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Henrik Grimler <henrik@HIDDEN>
In-Reply-To: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
 (message from Henrik Grimler on Sun, 04 Apr 2021 21:20:35 +0200)
Subject: Re: bug#47596: File descriptor error when exiting emacs on android 11
References: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 47596
Cc: 47596 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

> From: Henrik Grimler <henrik@HIDDEN>
> Date: Sun, 04 Apr 2021 21:20:35 +0200
> 
> Debugging these issues are very tedious in my experience so far
> (probably easier for actual android apps). I will try to boil down the
> relevant emacs code into a smaller program that still reproduces the
> error.

Yes, please.

> Based on the backtrace it seem to be how stderr is opened (and closed)
> that is problematic somehow.

Any idea what was "the other thread" involved in this situation?
Emacs is generally a single-threaded program.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#47596; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 4 Apr 2021 19:20:54 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 04 15:20:54 2021
Received: from localhost ([127.0.0.1]:36466 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lT8In-0000H8-Va
	for submit <at> debbugs.gnu.org; Sun, 04 Apr 2021 15:20:54 -0400
Received: from lists.gnu.org ([209.51.188.17]:53452)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <henrik@HIDDEN>) id 1lT8Il-0000Gz-9R
 for submit <at> debbugs.gnu.org; Sun, 04 Apr 2021 15:20:52 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:58382)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <henrik@HIDDEN>) id 1lT8Ik-0003Nz-4W
 for bug-gnu-emacs@HIDDEN; Sun, 04 Apr 2021 15:20:50 -0400
Received: from h04mx15.reliablemail.org ([185.76.67.208]:42905)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <henrik@HIDDEN>) id 1lT8Id-0005L0-NO
 for bug-gnu-emacs@HIDDEN; Sun, 04 Apr 2021 15:20:47 -0400
X-Halon-Out: d5984a93-957a-11eb-a4a4-354a41e2f763
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=grimler.se; 
 s=default;
 h=Content-Transfer-Encoding:MIME-Version:Content-Type:Date:To:
 From:Subject:Message-ID:Sender:Reply-To:Cc:Content-ID:Content-Description:
 Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:
 In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
 List-Post:List-Owner:List-Archive;
 bh=RL0Wblv9r5SsLDik2j0DfmoFF0tDZIERpeGJOaevJK4=; b=o2rxHZgGR5q29trje7Z5rMsn/a
 9rMydmAQwyOu+VQqsazZrw6XkelAln+OC8BXL9N6TD9U2E3e1mb2N8IKLInujQJKE/cQBhnF5vjRY
 xQiZkhJqbAA6Snh3FEjqAPUGqLw/pdkJdclX9x7VvvNJ2QjBIBpecXTu57ByzN0bKQOUtz565yhDb
 d7F5ZcYdKjbs+L43fn6SWejP5H06ZJM3q7Juv9mg3pyp0BmwejJvl2KVINjfrN2RrX7ijZOTYwtKc
 hwOxCYhkD7lcka1REjzEx2HabLCUxkSA0mWZ69BkLYsGHUruSdl9A8GQzs6mscIxxYMeMI7v4aszz
 n8FGBMKA==;
Message-ID: <b87a71b429bedaa8117320121936703633afd0e0.camel@HIDDEN>
Subject: File descriptor error when exiting emacs on android 11
From: Henrik Grimler <henrik@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Date: Sun, 04 Apr 2021 21:20:35 +0200
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.38.4 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-OutGoing-Spam-Status: No, score=-1.0
X-AntiAbuse: This header was added to track abuse,
 please include it with any abuse report
X-AntiAbuse: Primary Hostname - cpsrv07.misshosting.com
X-AntiAbuse: Original Domain - gnu.org
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - grimler.se
X-Get-Message-Sender-Via: cpsrv07.misshosting.com: authenticated_id:
 henrik@HIDDEN
X-Authenticated-Sender: cpsrv07.misshosting.com: henrik@HIDDEN
X-Source: 
X-Source-Args: 
X-Source-Dir: 
Received-SPF: pass client-ip=185.76.67.208; envelope-from=henrik@HIDDEN;
 helo=h04mx15.reliablemail.org
X-Spam_score_int: 0
X-Spam_score: -0.1
X-Spam_bar: /
X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 HAS_X_OUTGOING_SPAM_STAT=1.998, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=no autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 2.3 (++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 
 Content preview:  Hi, Android 10 introduced a new "file descriptor sanitizer"
    (fdsan, see [1] for docs) which detects issues when opening and closing files
    across multiple threads. On android 10 warnings were given, while [...] 
 
 Content analysis details:   (2.3 points, 10.0 required)
 
  pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_HELO_PASS          SPF: HELO matches SPF record
  1.0 SPF_SOFTFAIL           SPF: sender does not match SPF record (softfail)
 -0.0 RCVD_IN_MSPIKE_H4      RBL: Very Good reputation (+4)
                             [209.51.188.17 listed in wl.mailspike.net]
 -2.3 RCVD_IN_DNSWL_MED      RBL: Sender listed at https://www.dnswl.org/,
                             medium trust
                             [209.51.188.17 listed in list.dnswl.org]
  1.7 URIBL_BLACK            Contains an URL listed in the URIBL blacklist
                             [URIs: libc.so]
 -0.0 RCVD_IN_MSPIKE_WL      Mailspike good senders
  2.0 HAS_X_OUTGOING_SPAM_STAT Has header claiming outbound spam scan
                             - why trust the results?
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.6 (/)

Hi,

Android 10 introduced a new "file descriptor sanitizer" (fdsan, see [1]
for docs) which detects issues when opening and closing files across
multiple threads. On android 10 warnings were given, while on android
11 programs are killed instantly if issues are detected. 

Starting and then exiting emacs, or simply just running for example
`emacs --version`, gives an error. `gdb --args emacs --version` gives
this backtrace:

```
Starting program: /data/data/com.termux/files/usr/bin/emacs --version
GNU Emacs 27.2
Copyright (C) 2021 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
fdsan: attempted to close file descriptor 2, expected to be unowned,
actually owned by FILE* 0xb6c8800c

Program received signal SIGABRT, Aborted.
0xb63789e8 in fdsan_error(char const*, ...) ()
   from /apex/com.android.runtime/lib/bionic/libc.so
(gdb) bt full
#0  0xb63789e8 in fdsan_error(char const*, ...) ()
   from /apex/com.android.runtime/lib/bionic/libc.so
No symbol table info available.
#1  0xb63786fe in android_fdsan_close_with_tag ()
   from /apex/com.android.runtime/lib/bionic/libc.so
No symbol table info available.
#2  0xb63b83c0 in __sclose () from
/apex/com.android.runtime/lib/bionic/libc.so
No symbol table info available.
#3  0xb63b8f24 in __FILE_close(__sFILE*) ()
   from /apex/com.android.runtime/lib/bionic/libc.so
No symbol table info available.
#4  0x7f7e6a76 in close_stream (stream=0xb63cde44 <__sF+168>)
    at /home/builder/.termux-build/emacs/src/lib/close-stream.c:61
        some_pending = false
        prev_fail = false
        fclose_fail = 243
#5  0x7f68a872 in close_output_streams ()
    at /home/builder/.termux-build/emacs/src/src/sysdep.c:2840
        err = false
#6  0xb63c10d6 in __cxa_finalize ()
   from /apex/com.android.runtime/lib/bionic/libc.so
No symbol table info available.
#7  0xb63bc7b8 in exit () from
/apex/com.android.runtime/lib/bionic/libc.so
No symbol table info available.
#8  0x7f655d92 in main (argc=2, argv=0xbefff504)
    at /home/builder/.termux-build/emacs/src/src/emacs.c:1132
        version = 0xb5e68133 "27.2"
        copyright = 0xb5e68138 "Copyright (C) 2021 Free Software
Foundation, Inc."
        stack_bottom_variable = 0x7f655a61 <main>
        do_initial_setlocale = false
        no_loadup = false
        junk = 0x0
        dname_arg = 0x0
        ch_to_dir = 0x0
        original_pwd = 0x0
        dump_mode = 0x0
        skip_args = 1
        temacs = 0x0
        attempt_load_pdump = true
        sockfd = -1225460908
        module_assertions = 244
```

The emacs here was a debug build from the 27.2 tag, configured with:


 'configure --disable-dependency-tracking
 --prefix=/data/data/com.termux/files/usr
 --libdir=/data/data/com.termux/files/usr/lib
 --sbindir=/data/data/com.termux/files/usr/bin --disable-rpath
 --disable-rpath-hack --host=arm-linux-androideabi --disable-autodepend
 --with-gif=no --with-gnutls --with-jpeg=no --without-gconf
 --without-gsettings --without-lcms2 --without-x --with-png=no
 --with-tiff=no --with-xml2 --with-xpm=no --without-dbus
 --without-selinux --with-modules --with-pdumper=yes --with-
dumping=none
 --enable-checking=yes,glyphs --enable-check-lisp-object-type
 emacs_cv_sanitize_address=yes emacs_cv_prog_cc_no_pie=no
 ac_cv_lib_elf_elf_begin=no gl_cv_func_dup2_works=no
 ac_cv_func_setrlimit=no emacs_cv_func__setjmp=no
 emacs_cv_func_sigsetjmp=no --disable-nls --enable-shared
 --enable-static --libexecdir=/data/data/com.termux/files/usr/libexec
 'CFLAGS= -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb
 -fstack-protector-strong -g3 -O0 -Wall -gdwarf-4' 'CPPFLAGS=
 -D_FORTIFY_SOURCE=2 -D__USE_FORTIFY_LEVEL=2
 -I/data/data/com.termux/files/usr/include'
 'LDFLAGS=-L/data/data/com.termux/files/usr/lib
 -Wl,-rpath=/data/data/com.termux/files/usr/lib -march=armv7-a -fopenmp
 -static-openmp -Wl,--enable-new-dtags -Wl,--as-needed
 -Wl,-z,relro,-z,now''

Debugging these issues are very tedious in my experience so far
(probably easier for actual android apps). I will try to boil down the
relevant emacs code into a smaller program that still reproduces the
error.

Based on the backtrace it seem to be how stderr is opened (and closed)
that is problematic somehow.

Please let me know if you have any insights, or if I can provide
additional useful information.

Best regards,
Henrik Grimler

[1]
https://android.googlesource.com/platform/bionic/+/master/docs/fdsan.md





Acknowledgement sent to Henrik Grimler <henrik@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#47596; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Thu, 6 May 2021 11:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.