From: Jean Louis <bugs@gnu.support>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Control of fan-speed on Lenovo Thinkpads
Date: Wed, 31 Mar 2021 08:35:52 +0300 [thread overview]
Message-ID: <YGQKOLOSic1HuxaE@protected.localdomain> (raw)
In-Reply-To: <jwvim58ced8.fsf-monnier+emacs@gnu.org>
* Stefan Monnier <monnier@iro.umontreal.ca> [2021-03-31 04:24]:
> > You probably mean process-file? There is no file-process.
>
> Indeed, sorry.
>
> > There is practical burden to use call-process, and it is with &rest
> > ARGS, as those have to be given all separately.
>
> There is no such extra burden. Arguments always have to be given
> separately. If you forget about that, you get bugs and associated
> security holes. Executing a process is not the same as executing an
> `shell` command. The first is a fairly simple and safe operation
> (assuming you trust the executable you're launching), whereas the second
> is tricky and risky unless you're extra careful to quote everything just
> right and you're sure the shell is really the one you expect, etc...
Yes, and I follow the advise.
This works well:
(shell-command "sudo su -c -- root -c \"echo level full-speed > /proc/acpi/ibm/fan\"")
While the argument after last "-c" has to be full line, which again
defeats the principle of being extra carefull and quoting everything
in this "sudo" example. Other commands are fine. Following line works.
(call-process "sudo" nil (get-buffer-create "*sudo*") t "su" "-c" "--" "root" "-c" "echo level auto > /proc/acpi/ibm/fan")
Thus based on that line, it become clear that "sudo" command that
shall be able to redirect output must be made in such way to defeat
the purpose of quoting and being careful.
Thus the following line works with the function below without
problems. I have now implemented your advise but probably not in the
spirit how it was meant. but I do not know how to add the command to
below call-process line without making macro and using eval.
(sudo "echo level full-speed > /proc/acpi/ibm/fan")
(defun sudo (command)
"Execute COMMAND with system command `sudo'."
(let ((not-remote (not (file-remote-p default-directory)))
(sudo-buffer (get-buffer-create "*sudo*"))
(current-buffer (current-buffer)))
(switch-to-buffer sudo-buffer)
(erase-buffer)
(switch-to-buffer current-buffer)
(if not-remote
(let* ((sudo `(call-process "sudo" nil ,sudo-buffer t "su" "-c" "--" "root" "-c" ,command))
(status (eval sudo))
(status (if (= 0 status) "Success" status))
(current-buffer (current-buffer))
(output (progn
(switch-to-buffer sudo-buffer)
(buffer-string))))
(switch-to-buffer current-buffer)
(message "%sStatus: %s" output status))
(message "This `sudo' does not work on remote directory: %s" default-directory))))
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
next prev parent reply other threads:[~2021-03-31 5:35 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-29 20:36 Control of fan-speed on Lenovo Thinkpads Jean Louis
2021-03-30 8:12 ` Michael Albinus
2021-03-30 9:42 ` Jean Louis
2021-03-30 9:44 ` Jean Louis
2021-03-30 10:13 ` Michael Albinus
2021-03-30 10:23 ` Finding simpler better sudo for Emacs Jean Louis
2021-03-30 10:34 ` Michael Albinus
2021-03-30 10:43 ` Jean Louis
2021-03-30 10:52 ` Michael Albinus
2021-03-30 11:05 ` Jean Louis
2021-03-30 11:13 ` Michael Albinus
2021-03-30 11:40 ` Jean Louis
2021-03-30 15:01 ` Control of fan-speed on Lenovo Thinkpads Stefan Monnier
2021-03-30 20:06 ` Jean Louis
2021-03-31 1:23 ` Stefan Monnier
2021-03-31 5:35 ` Jean Louis [this message]
2021-03-31 14:23 ` Stefan Monnier
2021-03-31 20:02 ` Jean Louis
2021-03-31 20:19 ` Stefan Monnier
2021-04-01 9:46 ` Jean Louis
[not found] <8735wcogti.fsf@gmail.com>
[not found] ` <YGNq8IGh12I+QL9I@protected.localdomain>
2021-03-31 5:49 ` Utkarsh Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YGQKOLOSic1HuxaE@protected.localdomain \
--to=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).