GNU bug report logs - #48940
27.2; regression: "emacs --script /dev/stdin" parses the script incorrectly when /dev/stdin is a pipe

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: "Bryan C. Mills" <bcmills@HIDDEN>; dated Wed, 9 Jun 2021 22:47:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

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


Received: (at 48940) by debbugs.gnu.org; 13 Jun 2021 10:26:37 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jun 13 06:26:37 2021
Received: from localhost ([127.0.0.1]:42712 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lsNK8-0004PM-Sp
	for submit <at> debbugs.gnu.org; Sun, 13 Jun 2021 06:26:37 -0400
Received: from eggs.gnu.org ([209.51.188.92]:44004)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1lsNK7-0004P6-AU
 for 48940 <at> debbugs.gnu.org; Sun, 13 Jun 2021 06:26:35 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:39070)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1lsNK1-0000a7-UO; Sun, 13 Jun 2021 06:26:29 -0400
Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2339
 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1lsNK1-0004Tf-I0; Sun, 13 Jun 2021 06:26:29 -0400
Date: Sun, 13 Jun 2021 13:26:23 +0300
Message-Id: <83pmwq6oxc.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: "Bryan C. Mills" <bcmills@HIDDEN>
In-Reply-To: <CAKWVi_S959chK+wSCG6wr8Fq2qKwxjy=16Cf=TkZH+Kog78z9w@HIDDEN>
 (bug-gnu-emacs@HIDDEN)
Subject: Re: bug#48940: 27.2;
 regression: "emacs --script /dev/stdin" parses the script incorrectly
 when /dev/stdin is a pipe
References: <CAKWVi_S959chK+wSCG6wr8Fq2qKwxjy=16Cf=TkZH+Kog78z9w@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 48940
Cc: 48940 <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: -3.3 (---)

> Date: Wed, 9 Jun 2021 16:31:36 -0400
> From:  "Bryan C. Mills" via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN>
> 
> `emacs --script /dev/stdin` worked reliably for me on Emacs 24 through 26.
> 
> As of Emacs 27, it no longer works reliably — depending on the script contents,
> it either fails with spurious errors or silently exits without
> finishing the script.
> 
> 
> In the following bash interaction, all three emacs invocations
> *should* run the same script.
> The third invocation demonstrates the bug: when /dev/stdin is a pipe from `cat`
> (instead of the script.el file directly), the script is no longer interpreted.
> With other scripts, I get various errors, seemingly due to `;` or `"`
> characters being
> dropped or ignored from the input.
> 
> ```
> $ cat script.el | cat /dev/stdin
> (print "Hello emacs!")
> 
> $ emacs --no-init-file --no-site-file --script script.el
> 
> "Hello emacs!"
> 
> $ emacs --no-init-file --no-site-file --script /dev/stdin <script.el
> 
> "Hello emacs!"
> 
> $ cat script.el | emacs --no-init-file --no-site-file --script /dev/stdin
> 
> $ echo $?
> 0
> 
> $
> ```
> 
> This reproduces with the GNU Emacs 27.1 currently packaged on Debian Testing,
> as well as the Google build of GNU Emacs 27.2 from which I produced
> the report below.

I see the problem, but it happens for me in Emacs 26 and Emacs 25 as
well, so I'm not sure this is new, or why it works for you in older
versions.  Maybe Debian included some local patches in those older
versions?  (My old Emacs versions were built from the unmodified
upstream sources.)

AFAICS, the problem seems to be that load-with-code-conversion calls
insert-file-contents, and the latter comes up with an empty buffer in
the problematic case.

It is notoriously hard to debug a program whose standard input was
redirected from a pipe of another program, so I couldn't see why the
above happens.  If someone could step in a debugger through
insert-file-contents in this case and describe what's going on there,
or tell how to do that when Emacs is invoked like this, maybe we
could make some progress.

Thanks.




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

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


Received: (at submit) by debbugs.gnu.org; 9 Jun 2021 22:46:20 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jun 09 18:46:20 2021
Received: from localhost ([127.0.0.1]:34844 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1lr6xm-0007HR-79
	for submit <at> debbugs.gnu.org; Wed, 09 Jun 2021 18:46:20 -0400
Received: from lists.gnu.org ([209.51.188.17]:36768)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <bcmills@HIDDEN>) id 1lr4s7-00086w-61
 for submit <at> debbugs.gnu.org; Wed, 09 Jun 2021 16:32:19 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:51254)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <bcmills@HIDDEN>)
 id 1lr4s6-000097-St
 for bug-gnu-emacs@HIDDEN; Wed, 09 Jun 2021 16:32:18 -0400
Received: from mail-vs1-xe2b.google.com ([2607:f8b0:4864:20::e2b]:33709)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <bcmills@HIDDEN>)
 id 1lr4s3-0003F4-CC
 for bug-gnu-emacs@HIDDEN; Wed, 09 Jun 2021 16:32:17 -0400
Received: by mail-vs1-xe2b.google.com with SMTP id 126so703436vsi.0
 for <bug-gnu-emacs@HIDDEN>; Wed, 09 Jun 2021 13:32:14 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to
 :content-transfer-encoding;
 bh=8sn7vsZOHg90lQy5W/GrHziR/UCCQWoVNREJcxOXMF4=;
 b=VFyrFAkj2FcocUieyuqo5gc9Pta92zVarch/87I/QDp+501qQlboOjYCqqi69z/nh3
 Ev2fte3osCOtpwZ6Ety0ORZZVhNc7qK9IlPXh8BHqUJ2FXfJG4KfNo8u/9ZrveoSZSII
 4vzNHhDEjhhEeZta8zAQ6GrYVgTXYF79wOA7gZc7r35X6IAA9bYRkAFkEdOpgLvnvEPC
 QuujQg9qH8GbrA2xds5NC8z+LcFmNGmeWGDEvG0zYMWp9Odlgw+tdx0BTXntrnqY9wYe
 HS0PIReENGbQpdC8Ly0rkahYbXa3qDoQN/Uao5KAfLP79IZZJCmVJffg3XqUERRp7lAf
 LS2w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to
 :content-transfer-encoding;
 bh=8sn7vsZOHg90lQy5W/GrHziR/UCCQWoVNREJcxOXMF4=;
 b=oWo3DO46SbsUNUbKfojfkqjQBVGm5l/KxNqAOINg3i9OUolZdPzKhLMnKh2bYFVQ/l
 bkDXGYp1M0BQt0DqEO2eTRZCkq/cO1yGsd7F/pubZ2jl34NABJ2tAgwM9oK0V2RDZCbU
 ZlbXqTfnujBaFLqJt2xnKF61/TzQ7q/x5qYkjpvHfu6eVQmTlDGyXN+TiM9TrgoRoJ1M
 lIz8s3UwweHGTAn5XGdyfzwY3E4m6esYS3RH5rEk4lcHAXqpUuwt6daci9hBOjdLfImT
 aZs/gn7xeQRwO25YpIC+MZ2M3O1rKZPBwUbcG8EHq00tA3h/A1k9hPS+y3xhhAaa4966
 8xIw==
X-Gm-Message-State: AOAM532229fU36VOJRPTemqu71E2Q9ZNFJKywyUx4D6IOa3VsoJ6Hw3D
 A/TlYEXWhizMaJoxgues+mbmmkHPPISwPallJxg9+Wom7Knv4w==
X-Google-Smtp-Source: ABdhPJxBrGFcOjhfN+jRPWUcGOUPBEHUJoP/WboHTF02pnW5VkCbWr1P+5JQvhaVcbQHv47EeoKavaJZI1OhIf85V1Q=
X-Received: by 2002:a67:6505:: with SMTP id z5mr2223495vsb.43.1623270733002;
 Wed, 09 Jun 2021 13:32:13 -0700 (PDT)
MIME-Version: 1.0
From: "Bryan C. Mills" <bcmills@HIDDEN>
Date: Wed, 9 Jun 2021 16:31:36 -0400
Message-ID: <CAKWVi_S959chK+wSCG6wr8Fq2qKwxjy=16Cf=TkZH+Kog78z9w@HIDDEN>
Subject: 27.2; regression: "emacs --script /dev/stdin" parses the script
 incorrectly when /dev/stdin is a pipe
To: bug-gnu-emacs@HIDDEN
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Received-SPF: pass client-ip=2607:f8b0:4864:20::e2b;
 envelope-from=bcmills@HIDDEN; helo=mail-vs1-xe2b.google.com
X-Spam_score_int: -175
X-Spam_score: -17.6
X-Spam_bar: -----------------
X-Spam_report: (-17.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001,
 DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5,
 USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Wed, 09 Jun 2021 18:46:16 -0400
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: -2.3 (--)

`emacs --script /dev/stdin` worked reliably for me on Emacs 24 through 26.

As of Emacs 27, it no longer works reliably =E2=80=94 depending on the scri=
pt contents,
it either fails with spurious errors or silently exits without
finishing the script.


In the following bash interaction, all three emacs invocations
*should* run the same script.
The third invocation demonstrates the bug: when /dev/stdin is a pipe from `=
cat`
(instead of the script.el file directly), the script is no longer interpret=
ed.
With other scripts, I get various errors, seemingly due to `;` or `"`
characters being
dropped or ignored from the input.

```
$ cat script.el | cat /dev/stdin
(print "Hello emacs!")

$ emacs --no-init-file --no-site-file --script script.el

"Hello emacs!"

$ emacs --no-init-file --no-site-file --script /dev/stdin <script.el

"Hello emacs!"

$ cat script.el | emacs --no-init-file --no-site-file --script /dev/stdin

$ echo $?
0

$
```

This reproduces with the GNU Emacs 27.1 currently packaged on Debian Testin=
g,
as well as the Google build of GNU Emacs 27.2 from which I produced
the report below.

(My apologies if this is a duplicate report. I tried to send it
earlier using M-x report-emacs-bug,
but the resulting email appears to have gotten stuck or rejected somewhere.=
)


In GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24,
cairo version 1.16.0)
 of 2021-03-29, modified by Debian built on kokoro-ubuntu
System Description: Debian GNU/Linux rodete

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
<f6> is undefined [2 times]
Making completion list... [2 times]

Configured using:
 'configure --build x86_64-linux-gnu --build x86_64-linux-gnu
 --prefix=3D/usr --sharedstatedir=3D/var/lib --libexecdir=3D/usr/lib
 --localstatedir=3D/var/lib --infodir=3D/usr/share/info
 --mandir=3D/usr/share/man --enable-libsystemd --with-pop=3Dyes
 --enable-locallisppath=3D/etc/google-emacs:/usr/local/share/google-emacs/2=
7.2+gg3+1.20210329.053400.rc147/site-lisp:/usr/local/share/google-emacs/sit=
e-lisp:/usr/share/google-emacs/27.2+gg3+1.20210329.053400.rc147/site-lisp:/=
usr/share/google-emacs/site-lisp
 --with-sound=3Dalsa --without-gconf --with-mailutils
 --program-prefix=3Dgoogle- --disable-silent-rules
 GOOGLE_VERSION=3D27.2+gg3+1.20210329.053400.rc147 --with-cairo
 --with-x=3Dyes --with-x-toolkit=3Dgtk3 --with-toolkit-scroll-bars
 build_alias=3Dx86_64-linux-gnu 'CFLAGS=3D-g -O2
 -ffile-prefix-map=3D/build/google-emacs-avRD2q/google-emacs-27.2+gg3+1.202=
10329.053400.rc147=3D.
-fstack-protector-strong
 -Wformat -Werror=3Dformat-security -Wall' LDFLAGS=3D-Wl,-z,relro
 'CPPFLAGS=3D-Wdate-time -D_FORTIFY_SOURCE=3D2' 'OBJCFLAGS=3D-g -O2
 -ffile-prefix-map=3D/build/google-emacs-avRD2q/google-emacs-27.2+gg3+1.202=
10329.053400.rc147=3D.
-fstack-protector-strong
 -Wformat -Werror=3Dformat-security''

Configured features:
XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY
INOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF
ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD
JSON PDUMPER LCMS2 GMP

Important settings:
  value of $LC_ALL: en_US.UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Text

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
format-spec rfc822 mml mml-sec password-cache epa derived epg epg-config
gnus-util rmail rmail-loaddefs text-property-search time-date subr-x seq
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils vc-git diff-mode easymenu easy-mmode cl-loaddefs cl-lib
term/tmux term/xterm xterm byte-opt gv bytecomp byte-compile cconv
tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type
mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode
lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch
timer select scroll-bar mouse jit-lock font-lock syntax facemenu
font-core term/tty-colors frame minibuffer cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 53224 7924)
 (symbols 48 6747 1)
 (strings 32 17548 1920)
 (string-bytes 1 565159)
 (vectors 16 8089)
 (vector-slots 8 89351 7266)
 (floats 8 29 624)
 (intervals 56 241 3)
 (buffers 1000 13))




Acknowledgement sent to "Bryan C. Mills" <bcmills@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#48940; 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: Sun, 13 Jun 2021 10:30:02 UTC

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