From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwsqL-0002SN-Qs for guix-patches@gnu.org; Sat, 08 Apr 2017 12:04:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwsqI-0003sX-LY for guix-patches@gnu.org; Sat, 08 Apr 2017 12:04:05 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:40141) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwsqI-0003sS-Hi for guix-patches@gnu.org; Sat, 08 Apr 2017 12:04:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cwsqI-0004Ma-Ac for guix-patches@gnu.org; Sat, 08 Apr 2017 12:04:02 -0400 Subject: bug#26341: [PATCH 1/5] build: syscalls: Add reboot. Resent-Message-ID: From: Mathieu Othacehe Date: Sat, 8 Apr 2017 18:03:25 +0200 Message-Id: <20170408160329.4068-2-m.othacehe@gmail.com> In-Reply-To: <20170408160329.4068-1-m.othacehe@gmail.com> References: <20170408160329.4068-1-m.othacehe@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 26341@debbugs.gnu.org * guix/build/syscalls.scm (static-or-ffi): New macro. Used to dispatch between static Guile core implementation and FFI version. (reboot): New export procedure. Reimplemented from guile-linux-syscalls.patch. (RB_AUTOBOOT, ..., RB_KEXEC): New exported flags replacing static Guile flags. --- guix/build/syscalls.scm | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index 4bcb2a871..af5ec4b6a 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès ;;; Copyright © 2015 David Thompson ;;; Copyright © 2015 Mark H Weaver +;;; Copyright © 2017 Mathieu Othacehe ;;; ;;; This file is part of GNU Guix. ;;; @@ -144,7 +145,15 @@ utmpx-address login-type utmpx-entries - (read-utmpx-from-port . read-utmpx))) + (read-utmpx-from-port . read-utmpx)) + #:replace (RB_AUTOBOOT + RB_HALT_SYSTEM + RB_ENABLED_CAD + RB_DISABLE_CAD + RB_POWER_OFF + RB_SW_SUSPEND + RB_KEXEC + reboot)) ;;; Commentary: ;;; @@ -409,6 +418,13 @@ the returned procedure is called." (error (format #f "~a: syscall->procedure failed: ~s" name args)))))) +(define-syntax-rule (static-or-ffi symbol ffi-procedure) + "If SYMBOL is defined in the core Guile module, return the associated +procedure, otherwise return FFI-PROCEDURE." + (if (module-defined? the-scm-module symbol) + (module-ref the-scm-module symbol) + ffi-procedure)) + ;;; ;;; File systems. @@ -547,6 +563,24 @@ constants from ." (list device (strerror err)) (list err))))))) +(define RB_AUTOBOOT #x01234567) +(define RB_HALT_SYSTEM #xcdef0123) +(define RB_ENABLED_CAD #x89abcdef) +(define RB_DISABLE_CAD 0) +(define RB_POWER_OFF #x4321fedc) +(define RB_SW_SUSPEND #xd000fce2) +(define RB_KEXEC #x45584543) + +(define reboot + (static-or-ffi + 'reboot + (let ((proc (syscall->procedure int "reboot" (list int)))) + (lambda* (#:optional (cmd RB_AUTOBOOT)) + (let-values (((ret err) (proc cmd))) + (unless (zero? ret) + (throw 'system-error "reboot" "~S: ~A" + (list cmd (strerror err)) + (list err)))))))) (define (kernel? pid) "Return #t if PID designates a \"kernel thread\" rather than a normal user-land process." -- 2.12.2