diff options
author | Mathieu Lirzin <mthl@gnu.org> | 2015-09-05 21:01:49 +0200 |
---|---|---|
committer | Mathieu Lirzin <mthl@gnu.org> | 2016-05-07 16:17:52 +0200 |
commit | c2a1d931a6533679d0d1a7e1f9416d44078bd236 (patch) | |
tree | 9653c101c87c244b84434102488fd0e561a7d4e2 | |
parent | 960f6e18170b77bd8b4ae999257105cac11264b6 (diff) | |
download | mcron-c2a1d931a6533679d0d1a7e1f9416d44078bd236.tar.gz mcron-c2a1d931a6533679d0d1a7e1f9416d44078bd236.tar.bz2 mcron-c2a1d931a6533679d0d1a7e1f9416d44078bd236.zip |
environment: Redefine 'modify-environment'.
* scm/mcron/environment.scm (modify-environment): Add docstring.
Compute 'passwd:dir' and 'passwd:name' only once.
(impose-default-environment): Merge it into 'modify-environment'.
-rw-r--r-- | scm/mcron/environment.scm | 54 |
1 files changed, 23 insertions, 31 deletions
diff --git a/scm/mcron/environment.scm b/scm/mcron/environment.scm index 9f694f1..b563d55 100644 --- a/scm/mcron/environment.scm +++ b/scm/mcron/environment.scm @@ -1,3 +1,4 @@ +;; Copyright (C) 2015, 2016 Mathieu Lirzin ;; Copyright (C) 2003 Dale Mellor ;; ;; This file is part of GNU mcron. @@ -36,37 +37,6 @@ append-environment-mods get-current-environment-mods-copy)) - - - -;; The env-alist is an association list of variable names and values. Variables -;; later in the list will take precedence over variables before. We return a -;; fixed-up version in which some variables are given specific default values -;; (which the user can override), and two variables which the user is not -;; allowed to control are added at the end of the list. - -(define (impose-default-environment env-alist passwd-entry) - (append `(("HOME" . ,(passwd:dir passwd-entry)) - ("CWD" . ,(passwd:dir passwd-entry)) - ("SHELL" . ,(passwd:shell passwd-entry)) - ("TERM" . #f) - ("TERMCAP" . #f)) - env-alist - `(("LOGNAME" . ,(passwd:name passwd-entry)) - ("USER" . ,(passwd:name passwd-entry))))) - - - - -;; Modify the UNIX environment for the current process according to the given -;; association list of variables, with the default variable values imposed. - -(define (modify-environment env-alist passwd-entry) - (for-each (lambda (variable) - (setenv (car variable) (cdr variable))) - (impose-default-environment env-alist passwd-entry))) - - ;; As we parse configuration files, we build up an alist of environment @@ -103,3 +73,25 @@ (set! current-environment-mods (append current-environment-mods (list (cons name value)))) #t) + +(define (modify-environment env passwd-entry) + "Modify the environment (in the UNIX sense) by setting the variables from +ENV and some default ones which are modulated by PASSWD-ENTRY. \"LOGNAME\" +and \"USER\" environment variables can't be overided by ENV. ENV must be an +alist which associate environment variables to their value. PASSWD-ENTRY must +be an object representing user information which corresponds to a valid entry +in /etc/passwd. The return value is not specified." + (for-each (lambda (pair) (setenv (car pair) (cdr pair))) + (let ((home-dir (passwd:dir passwd-entry)) + (user-name (passwd:name passwd-entry))) + (append + ;; Default environment variables which can be overided by ENV. + `(("HOME" . ,home-dir) + ("CWD" . ,home-dir) + ("SHELL" . ,(passwd:shell passwd-entry)) + ("TERM" . #f) + ("TERMCAP" . #f)) + env + ;; Environment variables with imposed values. + `(("LOGNAME" . ,user-name) + ("USER" . ,user-name)))))) |