1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

common: Support gpgconf.ctl also for BSDs.

* common/homedir.c (MYPROC_SELF_EXE): New.
(unix_rootdir): Use it here.  Also support GNUPG_BUILD_ROOT as
fallback.
--

In addition this adds a fallback method for AIX etc which do not have
an easy way to get the info.
This commit is contained in:
Werner Koch 2021-10-01 14:40:39 +02:00
parent ec847cf17f
commit dbe1b237a6
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 31 additions and 10 deletions

View File

@ -59,13 +59,20 @@
#include <sys/stat.h> /* for stat() */ #include <sys/stat.h> /* for stat() */
#endif #endif
#include "util.h" #include "util.h"
#include "sysutils.h" #include "sysutils.h"
#include "i18n.h" #include "i18n.h"
#include "zb32.h" #include "zb32.h"
/* The name of the symbolic link to the file from which the process
* text was read. */
#if __linux__
# define MYPROC_SELF_EXE "/proc/self/exe"
#else /* Assume *BSD*/
# define MYPROC_SELF_EXE "/proc/curproc/file"
#endif
/* The GnuPG homedir. This is only accessed by the functions /* The GnuPG homedir. This is only accessed by the functions
* gnupg_homedir and gnupg_set_homedir. Malloced. */ * gnupg_homedir and gnupg_set_homedir. Malloced. */
static char *the_gnupg_homedir; static char *the_gnupg_homedir;
@ -456,9 +463,9 @@ w32_rootdir (void)
* This file is parsed for keywords describing the actually to be used * This file is parsed for keywords describing the actually to be used
* root directory. There is no solid standard on Unix to locate the * root directory. There is no solid standard on Unix to locate the
* binary used to create the process, thus we support this currently * binary used to create the process, thus we support this currently
* only on Linux where we can look this info up using the proc file * only on Linux and BSD where we can look this info up using the proc
* system. If WANT_SYSCONFDIR is true the optional sysconfdir entry * file system. If WANT_SYSCONFDIR is true the optional sysconfdir
* is returned. */ * entry is returned. */
static const char * static const char *
unix_rootdir (int want_sysconfdir) unix_rootdir (int want_sysconfdir)
{ {
@ -484,13 +491,21 @@ unix_rootdir (int want_sysconfdir)
for (;;) for (;;)
{ {
buffer = xmalloc (bufsize+1); buffer = xmalloc (bufsize+1);
nread = readlink ("/proc/self/exe", buffer, bufsize); nread = readlink (MYPROC_SELF_EXE, buffer, bufsize);
if (nread < 0) if (nread < 0)
{ {
err = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
log_info ("error reading symlink '/proc/self/exe': %s\n", log_info ("error reading symlink '%s': %s\n",
gpg_strerror (err)); MYPROC_SELF_EXE, gpg_strerror (err));
buffer[0] = 0; buffer[0] = 0;
if ((name = getenv ("GNUPG_BUILD_ROOT")) && *name == '/')
{
/* Try a fallback for systems w/o a supported /proc
* file system. */
xfree (buffer);
buffer = xstrconcat (name, "/bin/gpgconf", NULL);
log_info ("trying fallback '%s'\n", buffer);
}
break; break;
} }
else if (nread < bufsize) else if (nread < bufsize)
@ -501,8 +516,8 @@ unix_rootdir (int want_sysconfdir)
else if (bufsize >= 4095) else if (bufsize >= 4095)
{ {
buffer[0] = 0; buffer[0] = 0;
log_info ("error reading symlink '/proc/self/exe': %s\n", log_info ("error reading symlink '%s': %s\n",
"value too large"); MYPROC_SELF_EXE, "value too large");
break; break;
} }
xfree (buffer); xfree (buffer);

View File

@ -3912,6 +3912,12 @@ Operation is further controlled by a few environment variables:
loaded the Registry is tried and as last resort the native Windows loaded the Registry is tried and as last resort the native Windows
locale system is used. locale system is used.
@item GNUPG_BUILD_ROOT
@efindex GNUPG_BUILD_ROOT
This variable is only used by the regression test suite as a helper
under operating systems without proper support to figure out the
name of a process' text file.
@end table @end table
When calling the gpg-agent component @command{@gpgname} sends a set of When calling the gpg-agent component @command{@gpgname} sends a set of