From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Control of fan-speed on Lenovo Thinkpads Date: Wed, 31 Mar 2021 08:35:52 +0300 Message-ID: References: <87blb13vr8.fsf@gmx.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16333"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.6 (2021-03-06) Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 31 07:37:42 2021 Return-path: Envelope-to: geh-help-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 1lRTXy-00049i-A1 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 31 Mar 2021 07:37:42 +0200 Original-Received: from localhost ([::1]:47418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRTXx-0002oD-CE for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 31 Mar 2021 01:37:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRTXe-0002o6-Gq for help-gnu-emacs@gnu.org; Wed, 31 Mar 2021 01:37:22 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:50467) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRTXb-0005I4-NR for help-gnu-emacs@gnu.org; Wed, 31 Mar 2021 01:37:22 -0400 Original-Received: from localhost ([::ffff:41.202.241.58]) (AUTH: PLAIN securesender, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000001E1D1.0000000060640A8B.000060E6; Tue, 30 Mar 2021 22:37:14 -0700 Mail-Followup-To: Stefan Monnier , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:128779 Archived-At: * Stefan Monnier [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