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-16 00:07:37 +0100
commit251e433f77625814bb88c8274cb047a55bfedc66 (patch)
tree70bd2ae607ed0da4f79272ca993d4830a67ad408
parent29f9808015576a9a1f391f4c6b80c7c606a4d99f (diff)
downloadexim4-251e433f77625814bb88c8274cb047a55bfedc66.tar.gz
Store the initial working directory, expand $initial_cwd. Bug 1805
(cherry picked from commit 3615fa9a06356891367c66ed284cef9db5cefca3) (cherry picked from commit fae3a611be53dbf58cbb7c2c4846081ecb87606e)
-rw-r--r--doc/doc-docbook/spec.xfpt6
-rw-r--r--doc/doc-txt/NewStuff2
-rw-r--r--src/src/exim.c12
-rw-r--r--src/src/expand.c1
-rw-r--r--src/src/globals.c1
-rw-r--r--src/src/globals.h1
6 files changed, 21 insertions, 2 deletions
diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt
index 6a1963043..046a17f3b 100644
--- a/doc/doc-docbook/spec.xfpt
+++ b/doc/doc-docbook/spec.xfpt
@@ -11612,6 +11612,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 a0002b620..0f164c301 100644
--- a/doc/doc-txt/NewStuff
+++ b/doc/doc-txt/NewStuff
@@ -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.86
------------
diff --git a/src/src/exim.c b/src/src/exim.c
index beb5abc25..022b840fb 100644
--- a/src/src/exim.c
+++ b/src/src/exim.c
@@ -3730,6 +3730,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)
@@ -4017,9 +4024,10 @@ if (((debug_selector & D_any) != 0 || (log_extra_selector & LX_arguments) != 0)
{
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 89e0ac779..6f07f2203 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -533,6 +533,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 1dbc015f0..1d5752d33 100644
--- a/src/src/globals.c
+++ b/src/src/globals.c
@@ -783,6 +783,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 f3e884b8e..bb1c0edcb 100644
--- a/src/src/globals.h
+++ b/src/src/globals.h
@@ -508,6 +508,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 */