From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#65156: 29.1; Reading from pipe with --insert or insert-file-contents no longer supported Date: Wed, 09 Aug 2023 10:47:41 +0800 Message-ID: <87o7jhx776.fsf@yahoo.com> References: <4b873c29-e8ca-403c-bd37-a531d93661f3@lucaswerkmeister.de> <83fs4tmlik.fsf@gnu.org> <83cyzxmj1g.fsf@gnu.org> Reply-To: Po Lu Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3740"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: larsi@gnus.org, eggert@cs.ucla.edu, 65156@debbugs.gnu.org, mail@lucaswerkmeister.de To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 09 04:49:26 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qTZGI-0000gz-1j for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 09 Aug 2023 04:49:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTZFw-0004Zs-W1; Tue, 08 Aug 2023 22:49:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTZFv-0004Zf-KO for bug-gnu-emacs@gnu.org; Tue, 08 Aug 2023 22:49:03 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTZFu-0007VO-RL for bug-gnu-emacs@gnu.org; Tue, 08 Aug 2023 22:49:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qTZFu-0007he-Ej for bug-gnu-emacs@gnu.org; Tue, 08 Aug 2023 22:49:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 09 Aug 2023 02:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65156 X-GNU-PR-Package: emacs Original-Received: via spool by 65156-submit@debbugs.gnu.org id=B65156.169154928629273 (code B ref 65156); Wed, 09 Aug 2023 02:49:02 +0000 Original-Received: (at 65156) by debbugs.gnu.org; 9 Aug 2023 02:48:06 +0000 Original-Received: from localhost ([127.0.0.1]:38033 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qTZEz-0007c2-Rn for submit@debbugs.gnu.org; Tue, 08 Aug 2023 22:48:06 -0400 Original-Received: from sonic304-22.consmr.mail.ne1.yahoo.com ([66.163.191.148]:43894) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qTZEt-0007ax-I7 for 65156@debbugs.gnu.org; Tue, 08 Aug 2023 22:48:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1691549273; bh=V8wfnNVBUru4ZeDt+mlVm1oPit19KLlYDGgLPivd/A0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=GpDjkm0e08ruAmgvZKrhxH/D2IJ9seE0lx3ShdCh/UWAIwlX+RYqrdLBVkxj/gVEGxzhidU617vGhcaSqu3PnfRyWhlWs52uDo689DRSu1yi6yYSE3TexY0A2BuToIqYsy4AT77aVvSi8nzuGouu4ZE+g1I9C4pZgA/oiSa1N/pJKwBuJFVTWhIf9StYFTbAhBnvNR17lRzAXrwFWt9O/BghIPlMtECmE9i0GTnbXGbfUC2mRLBKpuz64wkC1gXkxF5f9ZsWDpAsnWIWw7YRlMirgD+bOTrefN6YErTb+LMhlslXeZLNUrn/e3IlozRTRcpkI7S+L0Mx2Ng9iqYQ+g== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1691549273; bh=aVWZLRlquAU1NwCSKvM2CY/M4JClnVksR8cvN+09Q6c=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=s0KUAkcdwJgA+eIb1BquWR54TWlZh5Rr9rbeiodDq05ai7jgD2dVuHwN73GbphmggW6zc/gBrOtXAeTz3lCrVj/Nu8+tIw4rBKOuKzpHjq3Xq4rDvSddLveaaLmetfINV5CTC/1iNscQXFy+nWUXWlpTRoax/xHJiUesb17+OlPzhq6JK/5bKERTQ9mIXiYJzByaV78jCGeKNlFS4xbNFTX64e4jCdJwH8NvsKJhSZdvRkMKvQJ5R/ker1n7kRoW86Mgl0FUmkL+vrPMoxl9W1v9hYF6hX5HmdMUx1kl3s8D75yAiPWHvE4J6GjvRRL4wb50o6Ink7EJGebwSKcRcw== X-YMail-OSG: 19bzzCwVM1mxKuO_NKjEv_C9BmdWtqBtBc34YC25ibdCGfPA70XEqhyZs1W0iWx fnZVz61vQuzzcM9uP_io.MTijxZFChkMoLQSCG.MRE9bjFnJduJeEJbWxeYt2MWxWsETrxwFzMgj 1NblRbpxoq8Oh_gmihmPkLx_fBUOm027G4B82NyIXe1MFHF_y7qZVYhw.1n74q2Se9j.Vrc9ZWT6 Egmn09ICuG5VKMwRnyi0lpMllZvU_1OoLGygVe0_D9SfdRjTRYC7bXMN07fC1vqQ0eiUXMxxzKsP HjjcoGtmpQXYsQPkLqGI7xL8fvr2hbd01CEmiONtn8Iapeg_mE0BMX.yQXX9SDpaFzT_pSxz0iZL cjcJPygBCp1VJ9yCNoyT8RT3GLvrc5.FozPr2QAt6_8LQUSYxCl5U2Q9jf4yrkOV22K4hpCfcbMo Y59Rs8jxsSyuQa84hWxgom15psow0gJ4Ohx0167Y54SRZex3d1RuoKy4wMaQQHiBO8IgwEM1AHHN QEQ0OqdeCSGpgJ7.YPUhV.XtejSajZhr.yGcXn52CC8layD7nTwDsirWlQsI6E2KuNQdx6f91Uda h.bCYEZC7BBk201ZN2zY0rusJGUgJeW11vd3_8iiRa6INyxnk6mmr4iBie7WLaruiyPkc3.8ohbK MERnvGhAHZMgKZBO6GXeqLuILLnxpmj_4Zx2IhnaLKDvEhWDuyKmA0i8OM_dT9VvS7i8GB_xJkUB oJvZ.mo_y7XqNUCXJUglqBu26q6D3PudyoW65yI82GVot7.NEvAG3owcIlt0Un0NjPkv99Y3WDSa AOQSCz8kRctA.OU1P_f6CCisACzEYIERJVFjuhbRWU X-Sonic-MF: X-Sonic-ID: 6d9afe10-6217-4aff-8cdc-23c0e90ffd8e Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Wed, 9 Aug 2023 02:47:53 +0000 Original-Received: by hermes--production-sg3-69654d8bd-l9pxw (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID a1381039e631424e4558eaa1088e129a; Wed, 09 Aug 2023 02:47:46 +0000 (UTC) In-Reply-To: <83cyzxmj1g.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 08 Aug 2023 22:27:23 +0300") X-Mailer: WebService/1.1.21695 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:267001 Archived-At: Eli Zaretskii writes: >> Cc: 65156@debbugs.gnu.org >> Date: Tue, 08 Aug 2023 21:33:55 +0300 >> From: Eli Zaretskii >>=20 >> > Date: Tue, 8 Aug 2023 20:20:23 +0200 >> > From: Lucas Werkmeister >> >=20 >> > Launch graphical Emacs with standard input attached to a pipe, then >> > attempt to insert /dev/stdin, for example: >> >=20 >> > echo test | emacs -Q --insert /dev/stdin >> > echo test | emacs -Q --eval '(insert-file-contents "/dev/stdin")' >> >=20 >> > This now results in an error (and nothing inserted into the buffer): >> > "Maximum buffer size exceeded". >>=20 >> The doc string says: >>=20 >> When inserting data from a special file (e.g., /dev/urandom), you >> can=E2=80=99t specify VISIT or BEG, and END should be specified to avo= id >> inserting unlimited data into the buffer. >>=20 >> > Previously, this used to work; git bisect identifies cb4579ed6b ("Allow >> > inserting parts of /dev/urandom with insert-file-contents", bug#18370) >> > as the first bad commit. >> >=20 >> > Other (non-stdin) pipes are also affected. Testing with a named pipe=20 >> > shows that the error only occurs after the pipe is first written to: >> >=20 >> > # first terminal: >> > mkfifo /tmp/fifo >> > emacs -Q >> > M-x insert-file /tmp/fifo >> > # second terminal: >> > { echo x; sleep 10; echo y; } > /tmp/fifo >> >=20 >> > Before you run the command in the second terminal, you can observe tha= t=20 >> > Emacs is just waiting for input from the pipe; as soon as you run the= =20 >> > other command, Emacs shows the error before the sleep finishes. >>=20 >> Lars, Paul, any suggestions? > > I installed the patch below on the emacs-29 branch; please see if it > solves your problems with reading from pipes. > > Paul, can there be a regular file that is not seekable? If regular > files are always seekable, the patch can be simplified. > > diff --git a/src/fileio.c b/src/fileio.c > index 995e414..55132f1 100644 > --- a/src/fileio.c > +++ b/src/fileio.c > @@ -4581,7 +4581,7 @@ because (1) it preserves some marker positions (in = unchanged portions > goto handled; > } >=20=20 > - if (seekable || !NILP (end)) > + if ((seekable && regular) || !NILP (end)) > total =3D end_offset - beg_offset; > else > /* For a special file, all we can do is guess. */ > @@ -4678,7 +4678,7 @@ because (1) it preserves some marker positions (in = unchanged portions > For a special file, where TOTAL is just a buffer size, > so don't bother counting in HOW_MUCH. > (INSERTED is where we count the number of characters inserted.) */ > - if (seekable || !NILP (end)) > + if ((seekable && regular) || !NILP (end)) > how_much +=3D this; > inserted +=3D this; > } Everyone, I fixed this on master yesterday, as part of a series of changes to enable visiting named pipes as files. The crux of the problem is this: seekable =3D emacs_fd_lseek (fd, 0, SEEK_CUR) < 0; <---------- if (!NILP (beg) && !seekable) xsignal2 (Qfile_error, where `seekable' is actually set to 1 if the file is NOT seekable, since lseek returns 0 upon success and -1 upon failure. Then, later: if (seekable || !NILP (end)) <------------------------ total =3D end_offset - beg_offset; else /* For a special file, all we can do is guess. */ total =3D READ_BUF_SIZE; total is set to end_offset - beg_offset (both -1 at that point), resulting in a call to buffer_overflow as the gap is extended beyond memory. The change presently in place on emacs-29 should be replaced with a one-line change that replaces: seekable =3D lseek (fd, 0, SEEK_CUR) < 0; with seekable =3D lseek (fd, 0, SEEK_CUR) !=3D (off_t) -1;