41#include <mach-o/ldsyms.h>
42#include <mach-o/dyld.h>
46#define LOG(kind, ...) \
47 GNUNET_log_from (kind, "util-os-installation", __VA_ARGS__)
49#define LOG_STRERROR_FILE(kind, syscall, filename) \
50 GNUNET_log_from_strerror_file (kind, \
51 "util-os-installation", \
62 .project_dirname =
"gnunet",
63 .binary_name =
"gnunet-arm",
64 .version = PACKAGE_VERSION
" " VCS_VERSION,
65 .env_varname =
"GNUNET_PREFIX",
66 .base_config_varname =
"GNUNET_BASE_CONFIG",
67 .bug_email =
"gnunet-developers@gnu.org",
68 .homepage =
"http://www.gnu.org/s/gnunet/",
69 .config_file =
"gnunet.conf",
70 .user_config_file =
"~/.config/gnunet.conf",
72 .gettext_domain =
"gnunet",
146get_path_from_proc_maps (
void)
160 if (NULL == (
f = fopen (fn,
"r")))
162 while (NULL != fgets (
line,
sizeof(
line),
f))
164 if ((1 == sscanf (
line,
165 "%*p-%*p %*c%*c%*c%*c %*x %*x:%*x %*u%*[ ]%1023s",
167 (NULL != (lgu = strstr (
dir,
186get_path_from_proc_exe (
void)
194 size = readlink (fn, lnk,
sizeof(lnk) - 1);
202 while ((lnk[
size] !=
'/') && (
size > 0))
206 if ((((
size_t)
size) > strlen (lep)) &&
207 (0 == strcmp (lep, &lnk[
size - strlen (lep)])))
208 size -= strlen (lep) - 1;
210 if ((
size < 4) || (lnk[
size - 4] !=
'/'))
231typedef int (*MyNSGetExecutablePathProto) (
char *buf,
size_t *bufsize);
240get_path_from_NSGetExecutablePath (
void)
242 static char zero =
'\0';
245 MyNSGetExecutablePathProto func;
249 (func = (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT,
250 "_NSGetExecutablePath")))
255 (void) func (path, &len);
259 if (0 != func (path, &len))
265 while ((path[len] !=
'/') && (len > 0))
278get_path_from_dyld_image (
void)
286 c = _dyld_image_count ();
287 for (i = 0; i < c; i++)
289 if (((
const void *) _dyld_get_image_header (i)) !=
290 ((
const void *) &_mh_dylib_header))
292 path = _dyld_get_image_name (i);
293 if ((NULL == path) || (0 == strlen (path)))
297 while ((s >
p) && (
'/' != *s))
326 if (NULL == (
p =
getenv (
"PATH")))
331 buf =
GNUNET_malloc (strlen (path) + strlen (binary) + 1 + 1);
336 sprintf (buf,
"%s/%s", pos, binary);
346 sprintf (buf,
"%s/%s", pos, binary);
395 if (NULL != (
ret = get_path_from_proc_maps ()))
401 if (NULL != (
ret = get_path_from_proc_exe ()))
405 if (NULL != (
ret = get_path_from_dyld_image ()))
407 if (NULL != (
ret = get_path_from_NSGetExecutablePath ()))
416 "Could not determine installation path for %s. Set `%s' environment variable.\n"),
433 if (NULL != (
ret = get_path_from_proc_exe ()))
437 if (NULL != (
ret = get_path_from_NSGetExecutablePath ()))
455 char *execpath = NULL;
467 if (NULL == execpath)
469 if (NULL == execpath)
472 n = strlen (execpath);
481 execpath[--n] =
'\0';
484 if ((n > 6) && ((0 == strcasecmp (&execpath[n - 6],
"/lib32")) ||
485 (0 == strcasecmp (&execpath[n - 6],
"/lib64"))))
491 execpath[n - 6] =
'\0';
497 else if ((n > 4) && ((0 == strcasecmp (&execpath[n - 4],
"/bin")) ||
498 (0 == strcasecmp (&execpath[n - 4],
"/lib"))))
501 execpath[n - 4] =
'\0';
505 if (NULL != (libdir = strstr (execpath,
"/lib/")))
509 multiarch = &libdir[5];
510 if (NULL == strchr (multiarch,
'/'))
519 execpath[--n] =
'\0';
539 (NULL != multiarch) ? multiarch :
"",
551 if (4 ==
sizeof(
void *))
559 if (8 ==
sizeof(
void *))
619 (NULL != multiarch) ? multiarch :
"",
630 if (4 ==
sizeof(
void *))
639 if (8 ==
sizeof(
void *))
698 if (NULL == libexecdir)
720 const char *progname)
739 if ((NULL == path) || (0 == strlen (path)))
746 path_len = strlen (path);
769 (0 == strncmp (binary,
"./", 2)))
787 _ (
"Could not find binary `%s' in PATH!\n"),
791 if (0 != access (
p, X_OK))
805 if (0 != stat (
p, &statbuf))
814 if ((0 != (statbuf.st_mode & S_ISUID)) && (0 == statbuf.st_uid))
820 _ (
"Binary `%s' exists, but is not SUID\n"),
#define bindtextdomain(Domainname, Dirname)
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static char * dir
Set to the directory where runtime files are stored.
static int end
Set if we are to shutdown all services (including ARM).
static char * line
Desired phone line (string to be converted to a hash).
static const struct GNUNET_CRYPTO_PrivateKey zero
Public key of all zeros.
static struct GNUNET_OS_Process * p
Helper process we started.
#define GNUNET_AGPL_URL
NOTE: You MUST adjust this URL to point to the location of a publicly accessible repository (or TGZ) ...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
char * GNUNET_OS_get_suid_binary_path(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *progname)
Given the name of a helper, service or daemon binary construct the full path to the binary using the ...
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_default(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_OS_check_helper_binary(const char *binary, bool check_suid, const char *params)
Check whether an executable exists and possibly if the suid bit is set on the file.
void GNUNET_OS_init(const struct GNUNET_OS_ProjectData *pd)
Setup OS subsystem with project data.
GNUNET_OS_InstallationPathKind
Possible installation paths to request.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get()
@ GNUNET_OS_IPK_SELF_PREFIX
Return the installation directory of this application, not the one of the overall GNUnet installation...
@ GNUNET_OS_IPK_ICONDIR
Return the prefix of the path with application icons (share/icons/).
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
@ GNUNET_OS_IPK_DOCDIR
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
@ GNUNET_OS_IPK_LIBDIR
Return the directory where libraries are installed.
@ GNUNET_OS_IPK_PREFIX
Return the "PREFIX" directory given to configure.
@ GNUNET_OS_IPK_BINDIR
Return the directory where the program binaries are installed.
@ GNUNET_OS_IPK_LIBEXECDIR
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
enum GNUNET_GenericReturnValue GNUNET_STRINGS_path_is_absolute(const char *filename, int can_be_uri, int *r_is_uri, char **r_uri_scheme)
Check whether filename is absolute or not, and if it's an URI.
static const struct GNUNET_OS_ProjectData * gettextinit
PD for which gettext has been initialized last.
#define LOG_STRERROR_FILE(kind, syscall, filename)
static char * os_get_gnunet_path(void)
get the path to GNUnet bin/ or lib/, preferring the lib/ path
static const struct GNUNET_OS_ProjectData default_pd
Default project data used for installation path detection for GNUnet (core).
static char * get_path_from_GNUNET_PREFIX(void)
Try to obtain the installation path using the "GNUNET_PREFIX" environment variable.
static char * os_get_exec_path()
get the path to current app's bin/
static char * get_path_from_PATH(const char *binary)
Return the actual path to a file found in the current PATH environment variable.
static const struct GNUNET_OS_ProjectData * current_pd
Which project data do we currently use for installation path detection? Never NULL.
static unsigned int size
Size of the "table".
Project-specific data used to help the OS subsystem find installation paths.
const char * binary_name
Name of a project-specific binary that should be in "$PREFIX/bin/".
const char * env_varname
Name of an environment variable that can be used to override installation path detection,...
const char * env_varname_alt
Alternative name of an environment variable that can be used to override installation path detection,...
const char * libname
Name of a library that is installed in the "lib/" directory of the project, such as "libgnunetutil".
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".