Re: [exim-dev] wishlist? $config_dir

Góra strony
Delete this message
Reply to this message
Autor: Heiko Schlittermann
Data:  
Dla: exim-dev
Temat: Re: [exim-dev] wishlist? $config_dir
Heiko Schlichting <exim-dev@???> (Mo 17 Nov 2014 17:26:08 CET):
> Heiko Schlittermann wrote:
> > to ease testing and configuration: what about having a
> >
> >     $config_dir

> >
> > expansion item? This item should contain the name of the directory
> > where the running configuration was found.
>
> +1
>
> Also useful:
>
>     $config_file

>
> Should be the same as the last line in "exim -bV" output. $config_dir could
> be generated by stripping the filename but not vice versa.


Attached you'll find a patch for the most current version.
I'm not sure about the naming.

    -bP configure_file


vs the new

    $config_file
    $config_dir


And - what about included files, should the '$config_file' contain the
name of the file Exim is currently processing?

I thought about the following naming:

    $config_file - the main config file
    $this_config_file - the config file, Exim is currently processing


(samit with dirs).

Or

    $config_main_file - the main config - according to the internal naming
    $config_file - the file, Exim is currently processing. (For me it's
                   confusing)



    Best regards from Dresden/Germany
    Viele Grüße aus Dresden
    Heiko Schlittermann
-- 
 SCHLITTERMANN.de ---------------------------- internet & unix support -
 Heiko Schlittermann, Dipl.-Ing. (TU) - {fon,fax}: +49.351.802998{1,3} -
 gnupg encrypted messages are welcome --------------- key ID: 7CBF764A -
 gnupg fingerprint: 9288 F17D BBF9 9625 5ABC  285C 26A9 687E 7CBF 764A -
(gnupg fingerprint: 3061 CFBF 2D88 F034 E8D2  7E92 EE4E AC98 48D0 359B)-

diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt
index 0ed867f..770351f 100644
--- a/doc/doc-docbook/spec.xfpt
+++ b/doc/doc-docbook/spec.xfpt
@@ -11259,6 +11259,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/src/src/expand.c b/src/src/expand.c
index ae901d6..5ea75d7 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 fb705d9..a9cf844 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 40af940..8b22cb1 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
   {