[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-mcron] [PATCH 29/33] environment: Redefine 'modify-environment'.
From: |
Mathieu Lirzin |
Subject: |
[Bug-mcron] [PATCH 29/33] environment: Redefine 'modify-environment'. |
Date: |
Sun, 27 Sep 2015 23:00:40 +0200 |
* scm/mcron/environment.scm (modify-environment): Add docstring.
Compute 'passwd:dir' and 'passwd:name' only once.
(impose-default-environment): Delete variable.
---
scm/mcron/environment.scm | 55 +++++++++++++++++++++--------------------------
1 file changed, 24 insertions(+), 31 deletions(-)
diff --git a/scm/mcron/environment.scm b/scm/mcron/environment.scm
index 9f694f1..e9f8bac 100644
--- a/scm/mcron/environment.scm
+++ b/scm/mcron/environment.scm
@@ -1,3 +1,4 @@
+;; Copyright (C) 2015 Mathieu Lirzin
;; Copyright (C) 2003 Dale Mellor
;;
;; This file is part of GNU mcron.
@@ -31,42 +32,12 @@
(define-module (mcron environment)
+ #:use-module (srfi srfi-26)
#:export (modify-environment
clear-environment-mods
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 +74,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 a valid entry in /etc/passwd. The return value is not specified."
+ (for-each (cut apply setenv <>)
+ (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))))))
+
- [Bug-mcron] [PATCH 09/33] build: Generate 'ChangeLog' upon 'make dist'., (continued)
- [Bug-mcron] [PATCH 09/33] build: Generate 'ChangeLog' upon 'make dist'., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 10/33] build: Fix prerequisite of the man page target., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 11/33] main: Import the modules used in one time., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 12/33] main: Use 'when' and 'unless' special forms., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 14/33] main: Make 'catch-mcron-error' macro hygienic., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 16/33] main: Add cron-file-descriptors., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 27/33] main: Improve 'process-user-file' definition., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 15/33] main: Add docstrings., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 26/33] mcron: Make functions 'static'., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 29/33] environment: Redefine 'modify-environment'.,
Mathieu Lirzin <=
- [Bug-mcron] [PATCH 17/33] main: Add main., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 21/33] main: Remove obsolete debug option., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 22/33] redirect: Use module (ice-9 regex)., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 23/33] mcron: Add forward declarations., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 28/33] main: Remove unused 'regular-file?' procedure., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 24/33] mcron: Use symbolic constants., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 25/33] mcron: Rework comments., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 20/33] build: Enable silent rules by default., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 13/33] main: Turn 'command-name' into a thunk., Mathieu Lirzin, 2015/09/27
- [Bug-mcron] [PATCH 19/33] build: Compile and install '.go' files., Mathieu Lirzin, 2015/09/27