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",
125 if (NULL == (
f = fopen (fn,
"r")))
127 while (NULL != fgets (
line,
sizeof(
line),
f))
129 if ((1 == sscanf (
line,
130 "%*p-%*p %*c%*c%*c%*c %*x %*x:%*x %*u%*[ ]%1023s",
132 (NULL != (lgu = strstr (
dir,
175 while ((lnk[
size] !=
'/') && (
size > 0))
181 if ((((
size_t)
size) > strlen (lep)) &&
183 &lnk[
size - strlen (lep)])))
184 size -= strlen (lep) - 1;
186 if ((
size < 4) || (lnk[
size - 4] !=
'/'))
207typedef int (*MyNSGetExecutablePathProto) (
char *buf,
217get_path_from_NSGetExecutablePath (
void)
219 static char zero =
'\0';
222 MyNSGetExecutablePathProto func;
226 (func = (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT,
227 "_NSGetExecutablePath")))
232 (void) func (path, &len);
236 if (0 != func (path, &len))
242 while ((path[len] !=
'/') && (len > 0))
255get_path_from_dyld_image (
void)
263 c = _dyld_image_count ();
264 for (i = 0; i < c; i++)
266 if (((
const void *) _dyld_get_image_header (i)) !=
267 ((
const void *) &_mh_dylib_header))
269 path = _dyld_get_image_name (i);
270 if ((NULL == path) || (0 == strlen (path)))
274 while ((s >
p) && (
'/' != *s))
303 if (NULL == (
p =
getenv (
"PATH")))
307 buf =
GNUNET_malloc (strlen (path) + strlen (binary) + 1 + 1);
309 while (NULL != (
end = strchr (pos,
382 if (NULL != (
ret = get_path_from_proc_maps (pd)))
388 if (NULL != (
ret = get_path_from_proc_exe (pd)))
392 if (NULL != (
ret = get_path_from_dyld_image ()))
394 if (NULL != (
ret = get_path_from_NSGetExecutablePath ()))
402 "Could not determine installation path for %s. Set `%s' environment variable.\n",
421 if (NULL != (
ret = get_path_from_proc_exe (pd)))
425 if (NULL != (
ret = get_path_from_NSGetExecutablePath ()))
439 char *execpath = NULL;
451 if (NULL == execpath)
453 if (NULL == execpath)
456 n = strlen (execpath);
465 execpath[--n] =
'\0';
468 if ((n > 6) && ((0 == strcasecmp (&execpath[n - 6],
"/lib32")) ||
469 (0 == strcasecmp (&execpath[n - 6],
"/lib64"))))
475 execpath[n - 6] =
'\0';
481 else if ((n > 4) && ((0 == strcasecmp (&execpath[n - 4],
"/bin")) ||
482 (0 == strcasecmp (&execpath[n - 4],
"/lib"))))
485 execpath[n - 4] =
'\0';
489 if (NULL != (libdir = strstr (execpath,
"/lib/")))
493 multiarch = &libdir[5];
494 if (NULL == strchr (multiarch,
'/'))
503 execpath[--n] =
'\0';
523 (NULL != multiarch) ? multiarch :
"",
535 if (4 ==
sizeof(
void *))
546 if (8 ==
sizeof(
void *))
611 (NULL != multiarch) ? multiarch :
"",
624 if (4 ==
sizeof(
void *))
636 if (8 ==
sizeof(
void *))
682 const char *progname)
700 if (NULL == libexecdir)
714 const char *progname)
736 if ( (NULL == path) ||
737 (0 == strlen (path)) )
745 path_len = strlen (path);
771 (0 == strncmp (binary,
"./", 2)) )
792 _ (
"Could not find binary `%s' in PATH!\n"),
825 if ( (0 != (statbuf.st_mode & S_ISUID)) &&
826 (0 == statbuf.st_uid) )
832 _ (
"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.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
void GNUNET_OS_init(const char *package_name, const struct GNUNET_OS_ProjectData *pd)
Setup OS subsystem for the given project data and package.
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.
char * GNUNET_OS_get_suid_binary_path(const struct GNUNET_OS_ProjectData *pd, 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 ...
GNUNET_OS_InstallationPathKind
Possible installation paths to request.
char * GNUNET_OS_get_libexec_binary_path(const struct GNUNET_OS_ProjectData *pd, const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
@ 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 char * os_get_exec_path(const struct GNUNET_OS_ProjectData *pd)
get the path to current app's bin/
#define LOG_STRERROR_FILE(kind, syscall, filename)
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(const struct GNUNET_OS_ProjectData *pd)
Try to obtain the installation path using the "GNUNET_PREFIX" environment variable.
static char * os_get_gnunet_path(const struct GNUNET_OS_ProjectData *pd)
get the path to GNUnet bin/ or lib/, preferring the lib/ path
static char * get_path_from_PATH(const char *binary)
Return the actual path to a file found in the current PATH environment variable.
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".