aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.c22
-rw-r--r--main.c22
2 files changed, 44 insertions, 0 deletions
diff --git a/client.c b/client.c
index 7624e7db..2a802d16 100644
--- a/client.c
+++ b/client.c
@@ -408,6 +408,28 @@ main(int argc, char *const *argv)
cwd = _cwd;
}
+ const char *pwd = getenv("PWD");
+ if (pwd != NULL) {
+ char *resolved_path_cwd = realpath(cwd, NULL);
+ char *resolved_path_pwd = realpath(pwd, NULL);
+
+ if (resolved_path_cwd != NULL &&
+ resolved_path_pwd != NULL &&
+ strcmp(resolved_path_cwd, resolved_path_pwd) == 0)
+ {
+ /*
+ * The resolved path of $PWD matches the resolved path of
+ * the *actual* working directory - use $PWD.
+ *
+ * This makes a difference when $PWD refers to a symlink.
+ */
+ cwd = pwd;
+ }
+
+ free(resolved_path_cwd);
+ free(resolved_path_pwd);
+ }
+
if (client_environment) {
for (char **e = environ; *e != NULL; e++) {
if (!push_string(&envp, *e, &total_len))
diff --git a/main.c b/main.c
index 4617a3c7..a3ae579d 100644
--- a/main.c
+++ b/main.c
@@ -594,6 +594,28 @@ main(int argc, char *const *argv)
cwd = _cwd;
}
+ const char *pwd = getenv("PWD");
+ if (pwd != NULL) {
+ char *resolved_path_cwd = realpath(cwd, NULL);
+ char *resolved_path_pwd = realpath(pwd, NULL);
+
+ if (resolved_path_cwd != NULL &&
+ resolved_path_pwd != NULL &&
+ strcmp(resolved_path_cwd, resolved_path_pwd) == 0)
+ {
+ /*
+ * The resolved path of $PWD matches the resolved path of
+ * the *actual* working directory - use $PWD.
+ *
+ * This makes a difference when $PWD refers to a symlink.
+ */
+ cwd = pwd;
+ }
+
+ free(resolved_path_cwd);
+ free(resolved_path_pwd);
+ }
+
shm_set_max_pool_size(conf.tweak.max_shm_pool_size);
if ((fdm = fdm_init()) == NULL)