GNU bug report logs - #73100
Regarding a bug in suspend-emacs

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: Riza Dindir <riza.dindir@HIDDEN>; merged with #73101; dated Sat, 7 Sep 2024 14:44:03 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

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


Received: (at 73100) by debbugs.gnu.org; 7 Sep 2024 18:22:00 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Sep 07 14:21:59 2024
Received: from localhost ([127.0.0.1]:57598 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sn04N-0004Fh-0X
	for submit <at> debbugs.gnu.org; Sat, 07 Sep 2024 14:21:59 -0400
Received: from mail-oa1-f54.google.com ([209.85.160.54]:61854)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <riza.dindir@HIDDEN>) id 1smy3J-0005On-Ju
 for 73100 <at> debbugs.gnu.org; Sat, 07 Sep 2024 12:12:46 -0400
Received: by mail-oa1-f54.google.com with SMTP id
 586e51a60fabf-277cfd3f07aso1410520fac.3
 for <73100 <at> debbugs.gnu.org>; Sat, 07 Sep 2024 09:12:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1725725499; x=1726330299; darn=debbugs.gnu.org;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:from:to:cc:subject:date:message-id:reply-to;
 bh=wkpdHm1DhdR+OUZwSFSsdGHrKf60/yX1bq84mvyfP8Q=;
 b=ayxadLPpkqNP8vGNfQjZ57FwDSKVrp92QkAZ1DAMdcraYUn9jdghOOO1RznKu/L7N2
 8hNNm4nSmgM1H44rY3NNZOwh1Vn/DilY56jAwr5Kl06sOQojV5PVpMVZQDiPfFblWx/+
 seljn2333BVQyg9eUbmvi8u1v8R2fkWwOvs/UElue45JDWrRcNQzIQTRMBnm5zGmVI/3
 Gy5oNZsKx5AoI3YZof9neE7Q4pxMKbOC5e6wadztUqHZibg6hZX2+fZ19Mz/5v2XjxPL
 YI26VHWkCXq2Cp1XaEbR0CFC5Zv1Y4aakIdW7fbXolUTdSnaOlDumuraC1/+nEHYXb/U
 lmIg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1725725499; x=1726330299;
 h=cc:to:subject:message-id:date:from:in-reply-to:references
 :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=wkpdHm1DhdR+OUZwSFSsdGHrKf60/yX1bq84mvyfP8Q=;
 b=Hyf6aG7FlIzoTAzwSE8C18l2Tuc2VV/M1D94MZASqlr2WwvfCY36k22+xgRTgjvP2A
 9lLmjtfXlXamZtwMnsKocaAsc5N8kPPMmcZGH+9GPuqdf1muKWj4CnD8XeFNLqmCLyJG
 UuEcwVP9OJN4Nsu5pJD3LTbgN2Nsj0hMfadHNJdsVMer8vxyVEgiQUjdc8zx/HZdLliu
 E5REp+J31tiSe/kf8MUV+UqCl6ysAl3xN/TaSunvYprRg2TN5fmVFt0vGTuE3yBVla92
 yx9sZIN2oKGrUMToPOtQQos8MgCxEXQp/a6epJm+LZS/yFt/gSMgbFhpJWP0zgofOO9A
 fbdQ==
X-Gm-Message-State: AOJu0Yz6YssTCkuR6w6mANR0mk/7P2DTTeTDlG2dbekqi2iEJ54vThrm
 ZIk0gT6lHA3aqJjW9DdNQjPprOhYaVoECBJxji+eTulLLVFWZet+dfOHaG6Nlj+AVDdDeJm5Si7
 5hqGM6+VvG0yK8FfOD7uXwMZYVXp8Y+2sCa0=
X-Google-Smtp-Source: AGHT+IHHTC+vNV+pj2mTiRjyUS6WeBdrgzrcxTMhycvjRy2J8AHC4Tt1PqZ5oJ/Cr6hTX5zT3Q2KtXYhl4gbWY7u2+4=
X-Received: by 2002:a05:6870:c1cb:b0:278:252d:9ac9 with SMTP id
 586e51a60fabf-27b9dc9fb8dmr1075573fac.45.1725725498967; Sat, 07 Sep 2024
 09:11:38 -0700 (PDT)
MIME-Version: 1.0
References: <CA+ek4BEgxpOHn-_1dV9VMTAyLenej9VkFQCMX_La-JWTwWKj=w@HIDDEN>
 <867cbnxzft.fsf@HIDDEN>
In-Reply-To: <867cbnxzft.fsf@HIDDEN>
From: Riza Dindir <riza.dindir@HIDDEN>
Date: Sat, 7 Sep 2024 19:11:02 +0300
Message-ID: <CA+ek4BGBhpQX1b-A13ov7Ts7MOke7nEzVa1+C=p3b5oJrkagpA@HIDDEN>
Subject: Re: bug#73100: Regarding a bug in suspend-emacs
To: Eli Zaretskii <eliz@HIDDEN>
Content-Type: multipart/alternative; boundary="00000000000058905e062189c71f"
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 73100
X-Mailman-Approved-At: Sat, 07 Sep 2024 14:21:52 -0400
Cc: 73100 <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 (-)

--00000000000058905e062189c71f
Content-Type: text/plain; charset="UTF-8"

Hello Eli,

I am new to the code base, and it was just a suggestion to check for the
ioctl call for any failures and take precautions, maybe inform the user of
the issue that the suspend-emacs command did not run correctly. Since the
command was not printing out anything when called with 'M-: (suspend-emacs
"pwd")' I was not sure what was happening.

For users that use the linux kernel 6.2+ the ioctl command does not work
correctly. When the STUFFSTRING is passed to the suspend-emacs command, it
does nothing. The problem with kernel 6.2+ is that it requires CAP_SYS_ADMIN
capability (https://www.man7.org/linux/man-pages/man2/TIOCSTI.2const.html).

In the code at some point suspend-emacs command calls stuff_char, which
uses ioctl (code snippet below, from
https://git.savannah.gnu.org/cgit/emacs.git/tree/src/sysdep.c#n403). The
ioctl call fails. But in the code there is no check for that, that might
confuse people that use linux kernel 6.2+. I wanted to use suspend-emacs
with "pwd" as the string (as shown in the example in the documentation in
https://www.gnu.org/software/emacs/manual/html_node/elisp/Suspending-Emacs.html).
But the "pwd" command was not displaying anything. Because it was not being
sent/stuffed to the superior process.

/* Should perhaps error if in batch mode */#ifdef TIOCSTI
  ioctl (fileno (CURTTY()->input), TIOCSTI, &c);#else /* no TIOCSTI */
  error ("Cannot stuff terminal input characters in this version of
Unix");#endif /* no TIOCSTI */


I have downloaded the code for emacs 29.4 and compiled it with a simple
error check and the ioctl call failed on my system silently (with kernel
6.6.47).

To add a check is of course for the people who develop emacs to decide. I
have seen the code today, and am not in a position to suggest anything at
this stage. Maybe there would be a better way of handling this error.

Adding an error check would be one of the solutions.

The other solution might be to add a piece of information to the
documentation for suspend-emacs, (and maybe to the documentation string for
suspend-emacs) regarding this problem. So that people that use linux kernel
6.2+ would be aware of this issue.

The issue is fixable by just setting the dev.tty.legacy_tiocsti sysctl
variable to 1. This variable was set to 0 on my system. Hence the ioctl
call for TIOCSTI was failing, and no indication of the error was given.
After I have read the man page for TIOCSTI, and set the sysctl
variable dev.tty.legacy_tiocsti to 1 was I able to call suspend-emacs with
a STUFFSTRING and it worked. It was displaying the output of the "pwd"
command.

Regards
Riza


On Sat, Sep 7, 2024, 18:20 Eli Zaretskii <eliz@HIDDEN> wrote:

> > From: Riza Dindir <riza.dindir@HIDDEN>
> > Date: Sat, 7 Sep 2024 15:37:17 +0300
> >
> > I am running Linux with kernel 6.6.47 and am running emacs in xterm,
> using the -nw command line argument.
> >
> > I am new to emacs and was experimenting with the suspend-emacs command.
> Following the example on
> >
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Suspending-Emacs.html
> .
> >
> > When following the example, I added the suspend-resume-hook to my
> .emacs.d/init.el file. When I run M-:
> > (suspend-emacs "pwd") it does not show the current working directory.
> But when I do fg from the terminal that I
> > got into, I see the "Resumed!" message.
> >
> > I asked in the libera chat about that, and also in the gnu-help-emacs
> list. I have been talking to wasamasa on
> > libera chat (#emacs-beginners) and we pinpointed the problem to the
> stuff_char function (in
> > https://git.savannah.gnu.org/cgit/emacs.git/tree/src/sysdep.c#n403). We
> came to this point from
> > stuff_buffered_input (
> https://git.savannah.gnu.org/cgit/emacs.git/tree/src/keyboard.c#n11963),
> and from
> > suspend-emacs function definition (in
> https://git.savannah.gnu.org/cgit/emacs.git/tree/src/keyboard.c#n11908).
> >
> > The stuff_char function is using ioctl with TIOCSTI. TIOCSTI requires
> CAP_SYS_ADMIN capability. You can set
> > this capability using sysctl setting dev.tty.legacy_tiocsti to 1.
> >
> > Unless I had set "dev.tty.legacy_tiocsti" to 1 I could not run the
> suspend-emacs command with an argument
> > string.
> >
> > Either emacs can check the return value of ioctl in stuff_char and if
> there return value is EPERM, then handle
> > this accordingly, with a message regarding the problem.
>
> You mean, you want suspend-emacs signal an error if it is called with
> STUFFSTRING argument, but fails to stuff the string into the
> terminal's input buffer?
>

--00000000000058905e062189c71f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"auto"><div>Hello Eli,<br></div><div><br></div>=
<div>I am new to the code base, and it was just a suggestion to check for t=
he ioctl call for any failures and take precautions, maybe inform the user =
of the issue that the suspend-emacs command did not run correctly. Since th=
e command was not printing out anything when called with &#39;M-: (suspend-=
emacs &quot;pwd&quot;)&#39; I was not sure what was happening.<br></div><di=
v><br></div><div>For users that use the linux kernel 6.2+ the ioctl command=
 does not work correctly. When the STUFFSTRING is passed to the suspend-ema=
cs command, it does nothing. The problem with kernel 6.2+ is that it requir=
es <span class=3D"gmail-im">CAP_SYS_ADMIN capability (</span><a href=3D"htt=
ps://www.man7.org/linux/man-pages/man2/TIOCSTI.2const.html">https://www.man=
7.org/linux/man-pages/man2/TIOCSTI.2const.html</a>).</div><div><br></div><d=
iv>In the code at some point suspend-emacs command calls stuff_char, which =
uses ioctl (code snippet below, from <a href=3D"https://git.savannah.gnu.or=
g/cgit/emacs.git/tree/src/sysdep.c#n403">https://git.savannah.gnu.org/cgit/=
emacs.git/tree/src/sysdep.c#n403</a>). The ioctl call fails. But in the cod=
e there is no check for that, that might confuse people that use linux kern=
el 6.2+. I wanted to use suspend-emacs with &quot;pwd&quot; as the string (=
as shown in the example in the documentation in <a href=3D"https://www.gnu.=
org/software/emacs/manual/html_node/elisp/Suspending-Emacs.html">https://ww=
w.gnu.org/software/emacs/manual/html_node/elisp/Suspending-Emacs.html</a>).=
 But the &quot;pwd&quot; command was not displaying anything. Because it wa=
s not being sent/stuffed to the superior process.<br></div><div><div><br></=
div><div><pre><code><span class=3D"gmail-hl gmail-com">/* Should perhaps er=
ror if in batch mode */</span>
<span class=3D"gmail-hl gmail-ppc">#ifdef TIOCSTI</span>
  <span class=3D"gmail-hl gmail-kwd">ioctl</span> <span class=3D"gmail-hl g=
mail-opt">(</span><span class=3D"gmail-hl gmail-kwd">fileno</span> <span cl=
ass=3D"gmail-hl gmail-opt">(</span><span class=3D"gmail-hl gmail-kwd">CURTT=
Y</span><span class=3D"gmail-hl gmail-opt">()-&gt;</span>input<span class=
=3D"gmail-hl gmail-opt">),</span> TIOCSTI<span class=3D"gmail-hl gmail-opt"=
>, &amp;</span>c<span class=3D"gmail-hl gmail-opt">);</span>
<span class=3D"gmail-hl gmail-ppc">#else</span> <span class=3D"gmail-hl gma=
il-com">/* no TIOCSTI */</span><span class=3D"gmail-hl gmail-ppc"></span>
  <span class=3D"gmail-hl gmail-kwd">error</span> <span class=3D"gmail-hl g=
mail-opt">(</span><span class=3D"gmail-hl gmail-str">&quot;Cannot stuff ter=
minal input characters in this version of Unix&quot;</span><span class=3D"g=
mail-hl gmail-opt">);</span>
<span class=3D"gmail-hl gmail-ppc">#endif</span> <span class=3D"gmail-hl gm=
ail-com">/* no TIOCSTI */</span></code></pre></div><div dir=3D"auto"><br></=
div></div>I have downloaded the code for emacs 29.4 and compiled it with a =
simple error check and the ioctl call failed on my system silently (with ke=
rnel 6.6.47).<br></div><div dir=3D"auto"><br></div><div>To add a check is o=
f course for the people who develop emacs to decide. I have seen the code t=
oday, and am not in a position to suggest anything at this stage. Maybe the=
re would be a better way of handling this error.</div><div><br></div><div>A=
dding an error check would be one of the solutions.<br></div><div><br></div=
><div>The other solution might be to add a piece of information to the docu=
mentation for suspend-emacs, (and maybe to the documentation string for sus=
pend-emacs) regarding this problem. So that people that use linux kernel 6.=
2+ would be aware of this issue.</div><div><br></div><div>The issue is fixa=
ble by just setting the dev.tty.legacy_tiocsti sysctl variable to 1. This v=
ariable was set to 0 on my system. Hence the ioctl call for TIOCSTI was fai=
ling, and no indication of the error was given. After I have read the man p=
age for TIOCSTI, and set the sysctl variable=C2=A0dev.tty.legacy_tiocsti to=
 1 was I able to call suspend-emacs with a STUFFSTRING and it worked. It wa=
s displaying the output of the &quot;pwd&quot; command.<br></div><div><br><=
/div><div>Regards</div><div>Riza<br></div><div dir=3D"auto"><br></div></div=
><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sa=
t, Sep 7, 2024, 18:20 Eli Zaretskii &lt;<a href=3D"mailto:eliz@HIDDEN" tar=
get=3D"_blank">eliz@HIDDEN</a>&gt; wrote:<br></div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,=
204,204);padding-left:1ex">&gt; From: Riza Dindir &lt;<a href=3D"mailto:riz=
a.dindir@HIDDEN" rel=3D"noreferrer" target=3D"_blank">riza.dindir@gmail.=
com</a>&gt;<br>
&gt; Date: Sat, 7 Sep 2024 15:37:17 +0300<br>
&gt; <br>
&gt; I am running Linux with kernel 6.6.47 and am running emacs in xterm, u=
sing the -nw command line argument.<br>
&gt; <br>
&gt; I am new to emacs and was experimenting with the suspend-emacs command=
. Following the example on<br>
&gt; <a href=3D"https://www.gnu.org/software/emacs/manual/html_node/elisp/S=
uspending-Emacs.html" rel=3D"noreferrer noreferrer" target=3D"_blank">https=
://www.gnu.org/software/emacs/manual/html_node/elisp/Suspending-Emacs.html<=
/a>.<br>
&gt; <br>
&gt; When following the example, I added the suspend-resume-hook to my .ema=
cs.d/init.el file. When I run M-:<br>
&gt; (suspend-emacs &quot;pwd&quot;) it does not show the current working d=
irectory. But when I do fg from the terminal that I<br>
&gt; got into, I see the &quot;Resumed!&quot; message.<br>
&gt; <br>
&gt; I asked in the libera chat about that, and also in the gnu-help-emacs =
list. I have been talking to wasamasa on<br>
&gt; libera chat (#emacs-beginners) and we pinpointed the problem to the st=
uff_char function (in<br>
&gt; <a href=3D"https://git.savannah.gnu.org/cgit/emacs.git/tree/src/sysdep=
.c#n403" rel=3D"noreferrer noreferrer" target=3D"_blank">https://git.savann=
ah.gnu.org/cgit/emacs.git/tree/src/sysdep.c#n403</a>). We came to this poin=
t from<br>
&gt; stuff_buffered_input (<a href=3D"https://git.savannah.gnu.org/cgit/ema=
cs.git/tree/src/keyboard.c#n11963" rel=3D"noreferrer noreferrer" target=3D"=
_blank">https://git.savannah.gnu.org/cgit/emacs.git/tree/src/keyboard.c#n11=
963</a>), and from <br>
&gt; suspend-emacs function definition (in <a href=3D"https://git.savannah.=
gnu.org/cgit/emacs.git/tree/src/keyboard.c#n11908" rel=3D"noreferrer norefe=
rrer" target=3D"_blank">https://git.savannah.gnu.org/cgit/emacs.git/tree/sr=
c/keyboard.c#n11908</a>).<br>
&gt; <br>
&gt; The stuff_char function is using ioctl with TIOCSTI. TIOCSTI requires =
CAP_SYS_ADMIN capability. You can set<br>
&gt; this capability using sysctl setting dev.tty.legacy_tiocsti to 1.<br>
&gt; <br>
&gt; Unless I had set &quot;dev.tty.legacy_tiocsti&quot; to 1 I could not r=
un the suspend-emacs command with an argument<br>
&gt; string.<br>
&gt; <br>
&gt; Either emacs can check the return value of ioctl in stuff_char and if =
there return value is EPERM, then handle<br>
&gt; this accordingly, with a message regarding the problem.<br>
<br>
You mean, you want suspend-emacs signal an error if it is called with<br>
STUFFSTRING argument, but fails to stuff the string into the<br>
terminal&#39;s input buffer?<br>
</blockquote></div>

--00000000000058905e062189c71f--




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

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


Received: (at 73100) by debbugs.gnu.org; 7 Sep 2024 16:30:07 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Sep 07 12:30:07 2024
Received: from localhost ([127.0.0.1]:57330 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1smyK6-0006JZ-MO
	for submit <at> debbugs.gnu.org; Sat, 07 Sep 2024 12:30:07 -0400
Received: from eggs.gnu.org ([209.51.188.92]:34482)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1smyK3-0006GX-P6
 for 73100 <at> debbugs.gnu.org; Sat, 07 Sep 2024 12:30:05 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1smyJx-00064a-Cu; Sat, 07 Sep 2024 12:29:57 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=J0aCf6NC+9Q3Ao6LlqnjU0CcuP1HQJsK5uzk99Ap/no=; b=PQTNhq08BYJu
 TzgaauEGOHXgFhLtusiIwhsNCtDFvGtB4o2b/G1ddpfiozF9Nv1MWKwnvoe4A63y3ypPxjfDQfXOZ
 RsloFyWQm22739VWRwWtgqMTRqToCvbMOC5LVuEWeukObQlEgwOKYRrvGr+s4IfWJi6FgGflu2HA1
 H2hNQ8R4c3W9RtZzWdHRDHYrRxVHZRHgv4fvwGXyf89pnz2wF8Gu8tDEFMElxDNayzOeZchS8IG1w
 HHutFQaimuZrN33e/NjEcaZpufYsmtEX0UIRA2QRtzCAc1fUVeu1SR2pS1Ycb/74W197j7u+FPZRm
 WA9WYUosTvUIvsDBrtYHow==;
Date: Sat, 07 Sep 2024 19:29:53 +0300
Message-Id: <8634mbxw8u.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Riza Dindir <riza.dindir@HIDDEN>
In-Reply-To: <CA+ek4BGBhpQX1b-A13ov7Ts7MOke7nEzVa1+C=p3b5oJrkagpA@HIDDEN>
 (message from Riza Dindir on Sat, 7 Sep 2024 19:11:02 +0300)
Subject: Re: bug#73100: Regarding a bug in suspend-emacs
References: <CA+ek4BEgxpOHn-_1dV9VMTAyLenej9VkFQCMX_La-JWTwWKj=w@HIDDEN>
 <867cbnxzft.fsf@HIDDEN>
 <CA+ek4BGBhpQX1b-A13ov7Ts7MOke7nEzVa1+C=p3b5oJrkagpA@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 73100
Cc: 73100 <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 (---)

> From: Riza Dindir <riza.dindir@HIDDEN>
> Date: Sat, 7 Sep 2024 19:11:02 +0300
> Cc: 73100 <at> debbugs.gnu.org
> 
> I am new to the code base, and it was just a suggestion to check for the ioctl call for any failures and take
> precautions, maybe inform the user of the issue that the suspend-emacs command did not run correctly. Since
> the command was not printing out anything when called with 'M-: (suspend-emacs "pwd")' I was not sure what
> was happening.

I was asking for your user's expectations, not how to do that in the
code.

> For users that use the linux kernel 6.2+ the ioctl command does not work correctly. When the STUFFSTRING is
> passed to the suspend-emacs command, it does nothing. The problem with kernel 6.2+ is that it requires
> CAP_SYS_ADMIN capability (https://www.man7.org/linux/man-pages/man2/TIOCSTI.2const.html).
> 
> In the code at some point suspend-emacs command calls stuff_char, which uses ioctl (code snippet below, from
> https://git.savannah.gnu.org/cgit/emacs.git/tree/src/sysdep.c#n403). The ioctl call fails. But in the code there is
> no check for that, that might confuse people that use linux kernel 6.2+. I wanted to use suspend-emacs with
> "pwd" as the string (as shown in the example in the documentation in
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Suspending-Emacs.html). But the "pwd" command
> was not displaying anything. Because it was not being sent/stuffed to the superior process.

Does ioctl return -1 in that case?  (I don't have access to a system
where it fails, it works for me on GNU/Linux.)

> Adding an error check would be one of the solutions.

Assuming we can check that (see above), the question is what to do if
we do detect a failure.

> The other solution might be to add a piece of information to the documentation for suspend-emacs, (and
> maybe to the documentation string for suspend-emacs) regarding this problem. So that people that use linux
> kernel 6.2+ would be aware of this issue.

That is already done, except that the documentation cannot be too
specific regarding when and under what conditions it could happen.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#73100; Package emacs. Full text available.
Merged 73100 73101. Request was from Eli Zaretskii <eliz@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

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


Received: (at 73100) by debbugs.gnu.org; 7 Sep 2024 15:21:08 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Sep 07 11:21:07 2024
Received: from localhost ([127.0.0.1]:57224 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1smxFL-0002aS-Hy
	for submit <at> debbugs.gnu.org; Sat, 07 Sep 2024 11:21:07 -0400
Received: from eggs.gnu.org ([209.51.188.92]:47232)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1smxFH-0002ZZ-26
 for 73100 <at> debbugs.gnu.org; Sat, 07 Sep 2024 11:21:05 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1smxFA-0007cx-HC; Sat, 07 Sep 2024 11:20:56 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=FcjixUUuVQ0a91fX2NvdQVFR8sqtIVmfWmHb+Nj4ifI=; b=ElWOv6wdQ3gv
 mj3MyI349B4aD286OCfUs7x90QTacRi4hQeykcEUygTG5qZv3kglK5/3DqqRl4xR4jA7s0dGXywbx
 R1k4CLjToDeQ0t9iPBHQ0NxuCrw9y5ZpFpa5UvOg3gufewU0UZLLFRyxIQlnrjSl5VrZ1pitKuNfP
 RW3p9qMUDJWKR2vk8GI5ypGKojmMqw9DsgpffmHCBG8vbQEI89pHiS8zIACTeN0wqLZVeEJ/ok3TS
 WoJo3KO+uIOTgAxR7WR8oYCqBb+vZ79V3TXmZfw/vBYt8QMmzIjUeIdEeFGNqyeKTxkxeiDUgYW9b
 aCXG7/UrVLBxlow3NY9xTg==;
Date: Sat, 07 Sep 2024 18:20:54 +0300
Message-Id: <867cbnxzft.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Riza Dindir <riza.dindir@HIDDEN>
In-Reply-To: <CA+ek4BEgxpOHn-_1dV9VMTAyLenej9VkFQCMX_La-JWTwWKj=w@HIDDEN>
 (message from Riza Dindir on Sat, 7 Sep 2024 15:37:17 +0300)
Subject: Re: bug#73100: Regarding a bug in suspend-emacs
References: <CA+ek4BEgxpOHn-_1dV9VMTAyLenej9VkFQCMX_La-JWTwWKj=w@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 73100
Cc: 73100 <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 (---)

> From: Riza Dindir <riza.dindir@HIDDEN>
> Date: Sat, 7 Sep 2024 15:37:17 +0300
> 
> I am running Linux with kernel 6.6.47 and am running emacs in xterm, using the -nw command line argument.
> 
> I am new to emacs and was experimenting with the suspend-emacs command. Following the example on
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Suspending-Emacs.html.
> 
> When following the example, I added the suspend-resume-hook to my .emacs.d/init.el file. When I run M-:
> (suspend-emacs "pwd") it does not show the current working directory. But when I do fg from the terminal that I
> got into, I see the "Resumed!" message.
> 
> I asked in the libera chat about that, and also in the gnu-help-emacs list. I have been talking to wasamasa on
> libera chat (#emacs-beginners) and we pinpointed the problem to the stuff_char function (in
> https://git.savannah.gnu.org/cgit/emacs.git/tree/src/sysdep.c#n403). We came to this point from
> stuff_buffered_input (https://git.savannah.gnu.org/cgit/emacs.git/tree/src/keyboard.c#n11963), and from 
> suspend-emacs function definition (in https://git.savannah.gnu.org/cgit/emacs.git/tree/src/keyboard.c#n11908).
> 
> The stuff_char function is using ioctl with TIOCSTI. TIOCSTI requires CAP_SYS_ADMIN capability. You can set
> this capability using sysctl setting dev.tty.legacy_tiocsti to 1.
> 
> Unless I had set "dev.tty.legacy_tiocsti" to 1 I could not run the suspend-emacs command with an argument
> string.
> 
> Either emacs can check the return value of ioctl in stuff_char and if there return value is EPERM, then handle
> this accordingly, with a message regarding the problem.

You mean, you want suspend-emacs signal an error if it is called with
STUFFSTRING argument, but fails to stuff the string into the
terminal's input buffer?




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

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


Received: (at submit) by debbugs.gnu.org; 7 Sep 2024 14:43:39 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Sep 07 10:43:39 2024
Received: from localhost ([127.0.0.1]:57169 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1smwf4-0000Sy-6u
	for submit <at> debbugs.gnu.org; Sat, 07 Sep 2024 10:43:38 -0400
Received: from lists.gnu.org ([209.51.188.17]:40234)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <riza.dindir@HIDDEN>) id 1smuhS-0001Da-7l
 for submit <at> debbugs.gnu.org; Sat, 07 Sep 2024 08:37:58 -0400
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 <riza.dindir@HIDDEN>)
 id 1smuhR-0000u3-0V; Sat, 07 Sep 2024 08:37:57 -0400
Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <riza.dindir@HIDDEN>)
 id 1smuhP-0006uQ-B7; Sat, 07 Sep 2024 08:37:56 -0400
Received: by mail-oa1-x2b.google.com with SMTP id
 586e51a60fabf-277df202ca9so1651152fac.0; 
 Sat, 07 Sep 2024 05:37:54 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1725712673; x=1726317473; darn=gnu.org;
 h=to:subject:message-id:date:from:mime-version:from:to:cc:subject
 :date:message-id:reply-to;
 bh=zsMU3oMmja4U1QnCOJ2ZKoLD+1tTkcMvBWF7vYTMK3I=;
 b=aXQVTsuFlS6tLABqj58YBQZmq/rmpY+A0cL21SyGsyaEyPzme1qpTI8ymuOzSLIL5G
 yDvWvP34hRkyRJLulHzPdji7QHbpZ4lY+0+KabiN7R4SubBCyRwW2pz+0Jqy2A+B4BBe
 x/pCB0l+RR/VAqC3lgJrMg8YGJDH4IowSewfxGdb8ItGHRjaxZGBM20fUIIdVhsqf4/X
 u10yjHIM55FsziHAvRyfXUdIJ7Yhzq3bp1EUbcVTI3pUAKqgNtCcjj7xkmSxCVkR5SoW
 p5ZsvAKhn+yG2Jw99MhZ5OoBjw6YqFVvfwcrNhF9y1qE9JBDE2ztgy9PFs7v5CNS3Fb+
 dD9Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1725712673; x=1726317473;
 h=to:subject:message-id:date:from:mime-version:x-gm-message-state
 :from:to:cc:subject:date:message-id:reply-to;
 bh=zsMU3oMmja4U1QnCOJ2ZKoLD+1tTkcMvBWF7vYTMK3I=;
 b=ZZHiXnLYTfUW+q7ekAysqDlKC6Tll3WmjD3bOxJaQR66d7pAHldZileJntyU98n121
 eYGPlspJPoFQqm03piHtLSlXJZkSHJwP3zWjYgTBWqDgcTVILsUWMzZ8AjmNTrJ8piIU
 D+PA88NgDbsoqn1IJnMQYC/7asmU5XUrrzw9zwd/iU3Z9b7+KciVgFLnJZWVZ7+txcnv
 tAn/c0ghblbtEbWYg2oTAG38AE4UuZDOd0zKJbIvxlM2iGRQf9e3tLF/C0+Qjj5iQwEo
 t5oh3sB4tu8ThLsKSzuz6G46ggh8FSkzJPdy14ByXdQ0cdGKvcGPuKhsLAE64s6WR+2t
 PdQA==
X-Forwarded-Encrypted: i=1;
 AJvYcCWU2ZR/1n30kxi87gRqRIinSTt6qIq1OxgJ4prbWUs2EcIUZ6STxPrjlrSYdyQrvF5OuyQIsNcMZMPoqesCMw==@gnu.org
X-Gm-Message-State: AOJu0YyL0I1jL1LXLiPIZwmjHK7ieE1YRyv3LARi34YtH3e2TnyOnruJ
 eZTKDNqRpe3xNrz1Fca3cv7LviTDqvc3XLV8rH23+W2jmeVOzJ0gOHmjFDbHBE6isL8wYKf0i1N
 ALWPHOX82GMWsR5aN4eW5SCvQqS5TxNeN0h0=
X-Google-Smtp-Source: AGHT+IHqHWxP7eeu0V1ul7xjCxXM5boSgZjMst0w9SngemP0ZlIUm9GaDZJfBmhs0vif5MWPyXeuxQU1XTy0F+fg55Q=
X-Received: by 2002:a05:6870:3646:b0:27b:55af:ca2b with SMTP id
 586e51a60fabf-27b9d7f81c9mr971325fac.11.1725712673453; Sat, 07 Sep 2024
 05:37:53 -0700 (PDT)
MIME-Version: 1.0
From: Riza Dindir <riza.dindir@HIDDEN>
Date: Sat, 7 Sep 2024 15:37:17 +0300
Message-ID: <CA+ek4BEgxpOHn-_1dV9VMTAyLenej9VkFQCMX_La-JWTwWKj=w@HIDDEN>
Subject: Regarding a bug in suspend-emacs
To: bug-gnu-emacs@HIDDEN, help-gnu-emacs@HIDDEN
Content-Type: multipart/alternative; boundary="000000000000e2beaf062186ca62"
Received-SPF: pass client-ip=2001:4860:4864:20::2b;
 envelope-from=riza.dindir@HIDDEN; helo=mail-oa1-x2b.google.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.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, FREEMAIL_FROM=0.001,
 HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Sat, 07 Sep 2024 10:43:33 -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 (--)

--000000000000e2beaf062186ca62
Content-Type: text/plain; charset="UTF-8"

Hello

I am running Linux with kernel 6.6.47 and am running emacs in xterm, using
the -nw command line argument.

I am new to emacs and was experimenting with the suspend-emacs command.
Following the example on
https://www.gnu.org/software/emacs/manual/html_node/elisp/Suspending-Emacs.html
.

When following the example, I added the suspend-resume-hook to my
.emacs.d/init.el file. When I run M-: (suspend-emacs "pwd") it does not
show the current working directory. But when I do fg from the terminal that
I got into, I see the "Resumed!" message.

I asked in the libera chat about that, and also in the gnu-help-emacs list.
I have been talking to wasamasa on libera chat (#emacs-beginners) and we
pinpointed the problem to the stuff_char function (in
https://git.savannah.gnu.org/cgit/emacs.git/tree/src/sysdep.c#n403). We
came to this point from stuff_buffered_input (
https://git.savannah.gnu.org/cgit/emacs.git/tree/src/keyboard.c#n11963),
and from  suspend-emacs function definition (in
https://git.savannah.gnu.org/cgit/emacs.git/tree/src/keyboard.c#n11908).

The stuff_char function is using ioctl with TIOCSTI. TIOCSTI requires
CAP_SYS_ADMIN capability. You can set this capability using sysctl setting
dev.tty.legacy_tiocsti to 1.

Unless I had set "dev.tty.legacy_tiocsti" to 1 I could not run the
suspend-emacs command with an argument string.

Either emacs can check the return value of ioctl in stuff_char and if there
return value is EPERM, then handle this accordingly, with a message
regarding the problem.

Or the information relating to the kernel version and CAP_SYS_ADMIN can be
added to the infor page os suspend_emacs, along with the information on how
to set this capability using sysctl.

Kind Regards
Riza Dindir

--000000000000e2beaf062186ca62
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hello</div><div><br></div><div>I am running Linux wit=
h kernel 6.6.47 and am running emacs in xterm, using the -nw command line a=
rgument.<br></div><div><br></div><div>I am new to emacs and was experimenti=
ng with the suspend-emacs command. Following the example on <a href=3D"http=
s://www.gnu.org/software/emacs/manual/html_node/elisp/Suspending-Emacs.html=
" target=3D"_blank">https://www.gnu.org/software/emacs/manual/html_node/eli=
sp/Suspending-Emacs.html</a>.</div><div><br></div><div>When following the e=
xample, I added the suspend-resume-hook to my .emacs.d/init.el file. When I=
 run <span style=3D"font-weight:bold">M-: (suspend-emacs &quot;pwd&quot;)</=
span> it does not show the current working directory. But when I do fg from=
 the terminal that I got into, I see the &quot;Resumed!&quot; message.</div=
><div><br></div><div>I asked in the libera chat about that, and also in the=
 gnu-help-emacs list. I have been talking to wasamasa on libera chat (#emac=
s-beginners) and we pinpointed the problem to the stuff_char function (in <=
a href=3D"https://git.savannah.gnu.org/cgit/emacs.git/tree/src/sysdep.c#n40=
3" target=3D"_blank">https://git.savannah.gnu.org/cgit/emacs.git/tree/src/s=
ysdep.c#n403</a>). We came to this point from stuff_buffered_input (<a href=
=3D"https://git.savannah.gnu.org/cgit/emacs.git/tree/src/keyboard.c#n11963"=
 target=3D"_blank">https://git.savannah.gnu.org/cgit/emacs.git/tree/src/key=
board.c#n11963</a>), and from=C2=A0 suspend-emacs function definition (in <=
a href=3D"https://git.savannah.gnu.org/cgit/emacs.git/tree/src/keyboard.c#n=
11908" target=3D"_blank">https://git.savannah.gnu.org/cgit/emacs.git/tree/s=
rc/keyboard.c#n11908</a>).</div><div><br></div><div>The stuff_char function=
 is using<span style=3D"font-family:arial,sans-serif"> ioctl </span>with TI=
OCSTI. TIOCSTI requires CAP_SYS_ADMIN capability. You can set this capabili=
ty using sysctl setting dev.tty.legacy_tiocsti to 1.</div><div><br></div><d=
iv>Unless I had set &quot;dev.tty.legacy_tiocsti&quot;  to 1 I could not ru=
n the suspend-emacs command with an argument string.</div><div><br></div><d=
iv>Either emacs can check the return value of ioctl in stuff_char and if th=
ere return value is EPERM, then handle this accordingly, with a message reg=
arding the problem.</div><div><br></div><div>Or the information relating to=
 the kernel version and CAP_SYS_ADMIN can be added to the infor page os sus=
pend_emacs, along with the information on how to set this capability using =
sysctl.</div><div><br></div><div>Kind Regards</div><div>Riza Dindir<br></di=
v></div>

--000000000000e2beaf062186ca62--




Acknowledgement sent to Riza Dindir <riza.dindir@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#73100; 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, 12 Jan 2025 05:45:02 UTC

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