[exim-cvs] New variable $config_dir, $config_file. Bug 1553

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Exim Git Commits Mailing List
Datum:  
To: exim-cvs
Betreff: [exim-cvs] New variable $config_dir, $config_file. Bug 1553
Gitweb: http://git.exim.org/exim.git/commitdiff/98b8312fe7bf50e38c4a6dbc9f7592d2db134f36
Commit:     98b8312fe7bf50e38c4a6dbc9f7592d2db134f36
Parent:     e8bc7fca1bef99f0b14fe791594be95cfed134f2
Author:     Heiko Schlittermann <hs+exim@???>
AuthorDate: Sat Nov 29 19:39:58 2014 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Mon Jan 12 18:58:34 2015 +0000


    New variable $config_dir, $config_file.  Bug 1553
---
 doc/doc-docbook/spec.xfpt    |   11 +++++++++++
 doc/doc-txt/NewStuff         |    3 +++
 src/src/expand.c             |    2 ++
 src/src/globals.c            |    1 +
 src/src/globals.h            |    1 +
 src/src/readconf.c           |    5 +++++
 test/scripts/0000-Basic/0002 |    2 ++
 test/stdout/0002             |    2 ++
 8 files changed, 27 insertions(+), 0 deletions(-)


diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt
index b786621..8ef56d1 100644
--- a/doc/doc-docbook/spec.xfpt
+++ b/doc/doc-docbook/spec.xfpt
@@ -11254,6 +11254,17 @@ The building process for Exim keeps a count of the number
of times it has been compiled. This serves to distinguish different
compilations of the same version of the program.

+.vitem &$config_dir$&
+.vindex "&$config_dir$&"
+The directory name of the main configuration file. That is, the content of
+&$config_file$& with the last component stripped. The value does not
+contain the trailing slash. If &$config_file$& does not contain a slash,
+&$config_dir$& is ".".
+
+.vitem &$config_file$&
+.vindex "&$config_file$&"
+The name of the main configuration file Exim is using.
+
 .vitem &$demime_errorlevel$&
 .vindex "&$demime_errorlevel$&"
 This variable is available when Exim is compiled with
diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff
index 7694730..f40fbed 100644
--- a/doc/doc-txt/NewStuff
+++ b/doc/doc-txt/NewStuff
@@ -25,6 +25,9 @@ Version 4.85
     server certs used for TLS match the result of the MX lookup. It does
     not use the same mechanism as DANE.


+ 4. New expansion items $config_file, $config_dir, containing the file
+    and directory name of the main configuration file. 
+


 Version 4.84
 ------------
diff --git a/src/src/expand.c b/src/src/expand.c
index d2f215d..0e9dff2 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -446,6 +446,8 @@ static var_entry var_table[] = {
   { "caller_uid",          vtype_uid,         &real_uid },
   { "compile_date",        vtype_stringptr,   &version_date },
   { "compile_number",      vtype_stringptr,   &version_cnumber },
+  { "config_dir",          vtype_stringptr,   &config_main_directory },
+  { "config_file",         vtype_stringptr,   &config_main_filename },
   { "csa_status",          vtype_stringptr,   &csa_status },
 #ifdef EXPERIMENTAL_DCC
   { "dcc_header",          vtype_stringptr,   &dcc_header },
diff --git a/src/src/globals.c b/src/src/globals.c
index 1b09008..5cd738b 100644
--- a/src/src/globals.c
+++ b/src/src/globals.c
@@ -496,6 +496,7 @@ gid_t   config_gid             = CONFIGURE_GROUP;
 uschar *config_main_filelist   = US CONFIGURE_FILE
                          "\0<-----------Space to patch configure_filename->";
 uschar *config_main_filename   = NULL;
+uschar *config_main_directory  = NULL;


 #ifdef CONFIGURE_OWNER
 uid_t   config_uid             = CONFIGURE_OWNER;
diff --git a/src/src/globals.h b/src/src/globals.h
index f4baa0b..5746167 100644
--- a/src/src/globals.h
+++ b/src/src/globals.h
@@ -282,6 +282,7 @@ extern gid_t   config_gid;             /* Additional group owner */
 extern int     config_lineno;          /* Line number */
 extern uschar *config_main_filelist;   /* List of possible config files */
 extern uschar *config_main_filename;   /* File name actually used */
+extern uschar *config_main_directory;  /* Directory where the main config file was found */
 #ifdef CONFIGURE_OWNER
 extern uid_t   config_uid;             /* Additional owner */
 #endif
diff --git a/src/src/readconf.c b/src/src/readconf.c
index f0d08d0..df4cbb2 100644
--- a/src/src/readconf.c
+++ b/src/src/readconf.c
@@ -3008,7 +3008,12 @@ file is a serious disaster. */


 if (config_file != NULL)
   {
+  uschar *p;
   config_filename = config_main_filename = string_copy(filename);
+
+  p = strrchr(filename, '/');
+  config_main_directory = p ? string_copyn(filename, p - filename) 
+                            : string_copy(".");
   }
 else
   {
diff --git a/test/scripts/0000-Basic/0002 b/test/scripts/0000-Basic/0002
index bcfacde..11fa1cd 100644
--- a/test/scripts/0000-Basic/0002
+++ b/test/scripts/0000-Basic/0002
@@ -15,6 +15,8 @@ exim -be
 # Some fixed variables


exim_path: $exim_path
+config_dir: $config_dir
+config_file: $config_file
primary_hostname: $primary_hostname
primary_hostname: ${primary_hostname}
qualify_domain: $qualify_domain
diff --git a/test/stdout/0002 b/test/stdout/0002
index a3706ee..00ac02a 100644
--- a/test/stdout/0002
+++ b/test/stdout/0002
@@ -6,6 +6,8 @@
> # Some fixed variables
>
> exim_path: TESTSUITE/eximdir/exim

+> config_dir: TESTSUITE
+> config_file: TESTSUITE/test-config
> primary_hostname: myhost.test.ex
> primary_hostname: myhost.test.ex
> qualify_domain: myhost.test.ex