GNU bug report logs -
#73100
Regarding a bug in suspend-emacs
Previous Next
To reply to this bug, email your comments to 73100 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73100
; Package
emacs
.
(Sat, 07 Sep 2024 14:44:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Riza Dindir <riza.dindir <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sat, 07 Sep 2024 14:44:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73100
; Package
emacs
.
(Sat, 07 Sep 2024 15:22:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 73100 <at> debbugs.gnu.org (full text, mbox):
> From: Riza Dindir <riza.dindir <at> gmail.com>
> 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?
Merged 73100 73101.
Request was from
Eli Zaretskii <eliz <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Sat, 07 Sep 2024 15:23:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#73100
; Package
emacs
.
(Sat, 07 Sep 2024 16:31:02 GMT)
Full text and
rfc822 format available.
Message #13 received at 73100 <at> debbugs.gnu.org (full text, mbox):
> From: Riza Dindir <riza.dindir <at> gmail.com>
> 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 <at> gnu.org
:
bug#73100
; Package
emacs
.
(Sat, 07 Sep 2024 18:22:03 GMT)
Full text and
rfc822 format available.
Message #16 received at 73100 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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 <at> gnu.org> wrote:
> > From: Riza Dindir <riza.dindir <at> gmail.com>
> > 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?
>
[Message part 2 (text/html, inline)]
This bug report was last modified 1 year and 13 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.