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-Url: https://git.exim.org/exim.git/commitdiff_plain/f1ff8cb17d215a94986d0bc9e8bd4bec73333838 Store the initial working directory, expand $initial_cwd. Bug 1805 (cherry picked from commit 3615fa9a06356891367c66ed284cef9db5cefca3) --- diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt index 22ccf86e9..9c4f78a1f 100644 --- a/doc/doc-docbook/spec.xfpt +++ b/doc/doc-docbook/spec.xfpt @@ -11276,6 +11276,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$&" diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff index d308f0485..9d07a2d70 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.82 ------------ diff --git a/src/src/exim.c b/src/src/exim.c index 807f1ea87..e3318f70c 100644 --- a/src/src/exim.c +++ b/src/src/exim.c @@ -3655,6 +3655,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) @@ -3931,9 +3938,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 5a764d3df..8bf84b946 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -487,6 +487,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 }, diff --git a/src/src/globals.c b/src/src/globals.c index e5ac8d679..09bc5934d 100644 --- a/src/src/globals.c +++ b/src/src/globals.c @@ -733,6 +733,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 9c7238212..bca1eadac 100644 --- a/src/src/globals.h +++ b/src/src/globals.h @@ -466,6 +466,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 */