Store the initial working directory, expand $initial_cwd. Bug 1805
authorHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Wed, 9 Mar 2016 10:13:42 +0000 (11:13 +0100)
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Sat, 12 Mar 2016 22:21:48 +0000 (23:21 +0100)
(cherry picked from commit 3615fa9a06356891367c66ed284cef9db5cefca3)
(cherry picked from commit fae3a611be53dbf58cbb7c2c4846081ecb87606e)

doc/doc-docbook/spec.xfpt
doc/doc-txt/NewStuff
src/src/exim.c
src/src/expand.c
src/src/globals.c
src/src/globals.h

index dd68ed56041a08390ee9125a8e7b0b11ef7ab59f..3c4a2723640e7d0baae1faeab7a6168e0bb21133 100644 (file)
@@ -11012,6 +11012,12 @@ the result, the name is not accepted, and &$host_lookup_deferred$& is set to
 .vindex "&$host_lookup_failed$&"
 See &$host_lookup_deferred$&.
 
+.vitem &$initial_cwd$&
+.vindex "&$initial_cwd$&
+This variable contains the full path name of the initial working
+directory of the current Exim process. This may differ from the current
+working directory, as Exim changes this to "/" during early startup, and
+to &$spool_directory$& later.
 
 .vitem &$inode$&
 .vindex "&$inode$&"
index 4b9142238b85e4536aac2fad9255b7f5e814068f..1353d5c2c9d602df227997f85e519f91ddd15677 100644 (file)
@@ -6,6 +6,8 @@ Before a formal release, there may be quite a lot of detail so that people can
 test from the snapshots or the CVS before the documentation is updated. Once
 the documentation is updated, this file is reduced to a short list.
 
+ 9. New $initial_cwd expansion variable.
+
 Version 4.80
 ------------
 
index 0c030f5be59bee82405e86f17b827c68d622f680..453165f830d629dd37166118beee003c8a93cd29 100644 (file)
@@ -3500,6 +3500,13 @@ if (Uchdir("/") < 0)
     exit(EXIT_FAILURE);
   }
 
+/* Store the initial cwd before we change directories */
+if ((initial_cwd = getcwd(NULL, 0)) == NULL)
+  {
+  perror("exim: can't get the current working directory");
+  exit(EXIT_FAILURE);
+  }
+
 readconf_main();
 
 if (cleanup_environment() == FALSE)
@@ -3698,8 +3705,10 @@ if (((debug_selector & D_any) != 0 || (log_extra_selector & LX_arguments) != 0)
   {
   int i;
   uschar *p = big_buffer;
-  Ustrcpy(p, "cwd=");
   (void)getcwd(CS p+4, big_buffer_size - 4);
+
+  Ustrncpy(p + 4, initial_cwd, big_buffer_size-5);
+
   while (*p) p++;
   (void)string_format(p, big_buffer_size - (p - big_buffer), " %d args:", argc);
   while (*p) p++;
index 84167b688d60c756ac0eac726622e7c7c99963b8..271d9639352930a3ab521ca4cd680e725b53cfee 100644 (file)
@@ -458,6 +458,7 @@ static var_entry var_table[] = {
   { "host_data",           vtype_stringptr,   &host_data },
   { "host_lookup_deferred",vtype_int,         &host_lookup_deferred },
   { "host_lookup_failed",  vtype_int,         &host_lookup_failed },
+  { "initial_cwd",         vtype_stringptr,   &initial_cwd },
   { "inode",               vtype_ino,         &deliver_inode },
   { "interface_address",   vtype_stringptr,   &interface_address },
   { "interface_port",      vtype_int,         &interface_port },
index 008880265e4a4043e0dab49dc624718a7245a9bf..6bbb43bc484b009bd26f04caefd9c185263e9a47 100644 (file)
@@ -667,6 +667,7 @@ BOOL    ignore_fromline_local  = FALSE;
 uschar *ignore_fromline_hosts  = NULL;
 BOOL    inetd_wait_mode        = FALSE;
 int     inetd_wait_timeout     = -1;
+uschar *initial_cwd            = NULL;
 uschar *interface_address      = NULL;
 int     interface_port         = -1;
 BOOL    is_inetd               = FALSE;
index 8159bda32e94ed3fa9e4890f312382399ba09840..7560bd07eb96d085c517768bddac8490e392c2d5 100644 (file)
@@ -429,6 +429,7 @@ extern BOOL    ignore_fromline_local;  /* Local SMTP ignore fromline */
 extern uschar *ignore_fromline_hosts;  /* Hosts permitted to send "From " */
 extern BOOL    inetd_wait_mode;        /* Whether running in inetd wait mode */
 extern int     inetd_wait_timeout;     /* Timeout for inetd wait mode */
+extern uschar *initial_cwd;            /* The directory we where in at startup */
 extern BOOL    is_inetd;               /* True for inetd calls */
 extern uschar *iterate_item;           /* Item from iterate list */