From ccd579237ce83e2c72ea2fa8fe4d7161f8a58453 Mon Sep 17 00:00:00 2001 From: "Heiko Schlittermann (HS12-RIPE)" Date: Wed, 9 Mar 2016 11:13:42 +0100 Subject: [PATCH] Store the initial working directory, expand $initial_cwd. Bug 1805 (cherry picked from commit 3615fa9a06356891367c66ed284cef9db5cefca3) (cherry picked from commit fae3a611be53dbf58cbb7c2c4846081ecb87606e) --- doc/doc-docbook/spec.xfpt | 6 ++++++ doc/doc-txt/NewStuff | 2 ++ src/src/exim.c | 11 ++++++++++- src/src/expand.c | 1 + src/src/globals.c | 1 + src/src/globals.h | 1 + 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt index dd68ed560..3c4a27236 100644 --- a/doc/doc-docbook/spec.xfpt +++ b/doc/doc-docbook/spec.xfpt @@ -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$&" diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff index 4b9142238..1353d5c2c 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.80 ------------ diff --git a/src/src/exim.c b/src/src/exim.c index 0c030f5be..453165f83 100644 --- a/src/src/exim.c +++ b/src/src/exim.c @@ -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++; diff --git a/src/src/expand.c b/src/src/expand.c index 84167b688..271d96393 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -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 }, diff --git a/src/src/globals.c b/src/src/globals.c index 008880265..6bbb43bc4 100644 --- a/src/src/globals.c +++ b/src/src/globals.c @@ -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; diff --git a/src/src/globals.h b/src/src/globals.h index 8159bda32..7560bd07e 100644 --- a/src/src/globals.h +++ b/src/src/globals.h @@ -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 */ -- 2.30.2