SummaryRefsLogTreeCommitDiffStats
path: root/scm/mcron/environment.scm
diff options
context:
space:
mode:
authorMathieu Lirzin <mthl@gnu.org>2017-09-27 23:10:29 +0200
committerMathieu Lirzin <mthl@gnu.org>2017-09-27 23:10:29 +0200
commit41b427e1b220389eccd65e436fc3452e2bc0215d (patch)
tree431584749084f7b041d406153cfcf1ad1f043737 /scm/mcron/environment.scm
parentc0a6eb14c257a47e9573631e5ac09e6528fba377 (diff)
downloadmcron-41b427e1b220389eccd65e436fc3452e2bc0215d.tar.gz
mcron-41b427e1b220389eccd65e436fc3452e2bc0215d.tar.bz2
mcron-41b427e1b220389eccd65e436fc3452e2bc0215d.zip
Revert "Taken on board suggestions of Mathieu Lirzin as per e-mails to the bug-mcron@gnu.org mailing list around September 2015."
This reverts commit c0a6eb14c257a47e9573631e5ac09e6528fba377.
Diffstat (limited to 'scm/mcron/environment.scm')
-rw-r--r--scm/mcron/environment.scm55
1 files changed, 32 insertions, 23 deletions
diff --git a/scm/mcron/environment.scm b/scm/mcron/environment.scm
index f364a38..9f694f1 100644
--- a/scm/mcron/environment.scm
+++ b/scm/mcron/environment.scm
@@ -1,4 +1,4 @@
-;; Copyright (C) 2003, 2015 Dale Mellor
+;; Copyright (C) 2003 Dale Mellor
;;
;; This file is part of GNU mcron.
;;
@@ -31,12 +31,42 @@
(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
@@ -73,24 +103,3 @@
(set! current-environment-mods (append current-environment-mods
(list (cons name value))))
#t)
-
-
-
-;; 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 (a) (setenv (car a) (cdr a)))
- (let ((home-dir (passwd:dir passwd-entry))
- (user-name (passwd:name passwd-entry)))
- (append
- ;; Default environment variables which can be overidden by ENV.
- `(("HOME" . ,home-dir)
- ("CWD" . ,home-dir)
- ("SHELL" . ,(passwd:shell passwd-entry))
- ("TERM" . #f)
- ("TERMCAP" . #f))
- env-alist
- ;; Environment variables with imposed values.
- `(("LOGNAME" . ,user-name)
- ("USER" . ,user-name))))))