Import Debian patch 4.84.2-2+deb8u3
[hcoop/debian/exim4.git] / debian / patches / 89_02_Store-the-initial-working-directory.diff
CommitLineData
493d55f6
AM
1Description: Store the initial working directory, expand $initial_cwd.
2 Bug 1805 https://bugs.exim.org/show_bug.cgi?id=1805
3Origin: upstream
4
5--- a/src/globals.c
6+++ b/src/globals.c
7@@ -759,6 +759,7 @@ BOOL ignore_fromline_local = FALSE;
8 uschar *ignore_fromline_hosts = NULL;
9 BOOL inetd_wait_mode = FALSE;
10 int inetd_wait_timeout = -1;
11+uschar *initial_cwd = NULL;
12 uschar *interface_address = NULL;
13 int interface_port = -1;
14 BOOL is_inetd = FALSE;
15--- a/src/exim.c
16+++ b/src/exim.c
17@@ -3689,6 +3689,13 @@ NOTE: immediatly after opening the confi
18 directory to "/"! Later we change to $spool_directory. We do it there, because
19 during readconf_main() some expansion takes place already. */
20
21+/* Store the initial cwd before we change directories */
22+if ((initial_cwd = getcwd(NULL, 0)) == NULL)
23+ {
24+ perror("exim: can't get the current working directory");
25+ exit(EXIT_FAILURE);
26+ }
27+
28 readconf_main();
29
30 /* Now in directory "/" */
31@@ -3967,9 +3974,10 @@ if (((debug_selector & D_any) != 0 || (l
32 {
33 int i;
34 uschar *p = big_buffer;
35- char * dummy;
36 Ustrcpy(p, "cwd= (failed)");
37- dummy = /* quieten compiler */ getcwd(CS p+4, big_buffer_size - 4);
38+
39+ Ustrncpy(p + 4, initial_cwd, big_buffer_size-5);
40+
41 while (*p) p++;
42 (void)string_format(p, big_buffer_size - (p - big_buffer), " %d args:", argc);
43 while (*p) p++;
44--- a/src/globals.h
45+++ b/src/globals.h
46@@ -486,6 +486,7 @@ extern BOOL ignore_fromline_local; /
47 extern uschar *ignore_fromline_hosts; /* Hosts permitted to send "From " */
48 extern BOOL inetd_wait_mode; /* Whether running in inetd wait mode */
49 extern int inetd_wait_timeout; /* Timeout for inetd wait mode */
50+extern uschar *initial_cwd; /* The directory we where in at startup */
51 extern BOOL is_inetd; /* True for inetd calls */
52 extern uschar *iterate_item; /* Item from iterate list */
53
54--- a/src/expand.c
55+++ b/src/expand.c
56@@ -501,6 +501,7 @@ static var_entry var_table[] = {
57 { "host_data", vtype_stringptr, &host_data },
58 { "host_lookup_deferred",vtype_int, &host_lookup_deferred },
59 { "host_lookup_failed", vtype_int, &host_lookup_failed },
60+ { "initial_cwd", vtype_stringptr, &initial_cwd },
61 { "inode", vtype_ino, &deliver_inode },
62 { "interface_address", vtype_stringptr, &interface_address },
63 { "interface_port", vtype_int, &interface_port },
64--- a/doc/spec.txt
65+++ b/doc/spec.txt
66@@ -10426,6 +10426,13 @@ $host_lookup_failed
67
68 See $host_lookup_deferred.
69
70+$initial_cwd
71+
72+ This variable contains the full path name of the initial working
73+ directory of the current Exim process. This may differ from the current
74+ working directory, as Exim changes this to "/" during early startup, and
75+ to $spool_directory later.
76+
77 $inode
78
79 The only time this variable is set is while expanding the directory_file