summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>2016-03-09 11:13:42 +0100
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>2016-03-09 11:46:21 +0100
commit3615fa9a06356891367c66ed284cef9db5cefca3 (patch)
tree53e0d0886fc58378deb435454c0061d884f90a2c
parentd8b70640f81ea7af8d04c94c0cb5bcceb8163c39 (diff)
Store the initial working directory, expand $initial_cwd. Bug 1805
-rw-r--r--doc/doc-docbook/spec.xfpt6
-rw-r--r--doc/doc-txt/NewStuff2
-rw-r--r--src/src/exim.c8
-rw-r--r--src/src/expand.c1
-rw-r--r--src/src/globals.c1
-rw-r--r--src/src/globals.h1
6 files changed, 17 insertions, 2 deletions
diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt
index fdb318b89..cf5c30c6b 100644
--- a/doc/doc-docbook/spec.xfpt
+++ b/doc/doc-docbook/spec.xfpt
@@ -11735,6 +11735,12 @@ See &$host_lookup_deferred$&.
This variable is set to the remote host's TCP port whenever &$host$& is set
for an outbound connection.
+.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$&"
diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff
index 01bd0111e..80c92a536 100644
--- a/doc/doc-txt/NewStuff
+++ b/doc/doc-txt/NewStuff
@@ -35,6 +35,8 @@ Version 4.87
avoid oversize bodies in bounces. The dafault value matches RFC
limits.
+ 9. New $initial_cwd expansion variable.
+
Version 4.86
------------
diff --git a/src/src/exim.c b/src/src/exim.c
index 02fda6756..574e7804b 100644
--- a/src/src/exim.c
+++ b/src/src/exim.c
@@ -3747,6 +3747,9 @@ NOTE: immediatly after opening the configuration file we change the working
directory to "/"! Later we change to $spool_directory. We do it there, because
during readconf_main() some expansion takes place already. */
+/* Store the initial cwd before we change directories */
+initial_cwd = getcwd(NULL, 0);
+
readconf_main();
/* Now in directory "/" */
@@ -4042,9 +4045,10 @@ if (((debug_selector & D_any) != 0 || LOGGING(arguments))
{
int i;
uschar *p = big_buffer;
- char * dummy;
Ustrcpy(p, "cwd= (failed)");
- dummy = /* quieten compiler */ 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++;
diff --git a/src/src/expand.c b/src/src/expand.c
index cc22e65fb..99d2ffc00 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -543,6 +543,7 @@ static var_entry var_table[] = {
{ "host_lookup_deferred",vtype_int, &host_lookup_deferred },
{ "host_lookup_failed", vtype_int, &host_lookup_failed },
{ "host_port", vtype_int, &deliver_host_port },
+ { "initial_cwd", vtype_stringptr, &initial_cwd },
{ "inode", vtype_ino, &deliver_inode },
{ "interface_address", vtype_stringptr, &interface_address },
{ "interface_port", vtype_int, &interface_port },
diff --git a/src/src/globals.c b/src/src/globals.c
index e5bbb8340..da6e4b31d 100644
--- a/src/src/globals.c
+++ b/src/src/globals.c
@@ -797,6 +797,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;
diff --git a/src/src/globals.h b/src/src/globals.h
index 1919d8c1f..b7f9c3489 100644
--- a/src/src/globals.h
+++ b/src/src/globals.h
@@ -512,6 +512,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 */