From: Heiko Schlittermann (HS12-RIPE) Date: Wed, 9 Mar 2016 10:13:42 +0000 (+0100) Subject: Store the initial working directory, expand $initial_cwd. Bug 1805 X-Git-Tag: exim-4_87_RC7~22 X-Git-Url: https://git.exim.org/exim.git/commitdiff_plain/3615fa9a06356891367c66ed284cef9db5cefca3?ds=sidebyside Store the initial working directory, expand $initial_cwd. Bug 1805 --- 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 */