aboutsummaryrefslogtreecommitdiffstats
path: root/common/homedir.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2017-07-25 10:24:01 +0000
committerWerner Koch <[email protected]>2017-07-25 10:43:37 +0000
commit226f143ca01cf335c7c4e3e94c96fb9d271eccc9 (patch)
treebf998fd0bb8459a74fe5ca339c4fa114fcd79f36 /common/homedir.c
parentRevert "w32: Change directory on daemon startup." (diff)
downloadgnupg-226f143ca01cf335c7c4e3e94c96fb9d271eccc9.tar.gz
gnupg-226f143ca01cf335c7c4e3e94c96fb9d271eccc9.zip
common: New functions gnupg_daemon_rootdir and gnupg_chdir.
* common/sysutils.c (gnupg_chdir): New. * common/homedir.c (gnupg_daemon_rootdir): New. * agent/gpg-agent.c (main): Use these functions instead chdir("/"). * dirmngr/dirmngr.c (main): Ditto. * scd/scdaemon.c (main): Ditto. -- Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/homedir.c')
-rw-r--r--common/homedir.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/common/homedir.c b/common/homedir.c
index fce6d44be..a30e8dc76 100644
--- a/common/homedir.c
+++ b/common/homedir.c
@@ -433,6 +433,34 @@ gnupg_default_homedir_p (void)
}
+/* Return the directory name used by daemons for their current working
+ * directory. */
+const char *
+gnupg_daemon_rootdir (void)
+{
+#ifdef HAVE_W32_SYSTEM
+ static char *name;
+
+ if (!name)
+ {
+ char path[MAX_PATH];
+ size_t n;
+
+ n = GetSystemDirectoryA (path, sizeof path);
+ if (!n || n >= sizeof path)
+ name = xstrdup ("/"); /* Error - use the curret top dir instead. */
+ else
+ name = xstrdup (path);
+ }
+
+ return name;
+
+#else /*!HAVE_W32_SYSTEM*/
+ return "/";
+#endif /*!HAVE_W32_SYSTEM*/
+}
+
+
/* Helper for gnupg-socketdir. This is a global function, so that
* gpgconf can use it for its --create-socketdir command. If
* SKIP_CHECKS is set permission checks etc. are not done. The