GNUnet 0.22.2
os_installation.c File Reference
#include "platform.h"
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <unistr.h>
#include "gnunet_util_lib.h"
Include dependency graph for os_installation.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)    GNUNET_log_from (kind, "util-os-installation", __VA_ARGS__)
 
#define LOG_STRERROR_FILE(kind, syscall, filename)
 

Functions

const struct GNUNET_OS_ProjectDataGNUNET_OS_project_data_gnunet (void)
 Return default project data used by 'libgnunetutil' for GNUnet. More...
 
void GNUNET_OS_init (const char *package_name, const struct GNUNET_OS_ProjectData *pd)
 Setup OS subsystem for the given project data and package. More...
 
static char * get_path_from_PATH (const char *binary)
 Return the actual path to a file found in the current PATH environment variable. More...
 
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. More...
 
static char * os_get_gnunet_path (const struct GNUNET_OS_ProjectData *pd)
 get the path to GNUnet bin/ or lib/, preferring the lib/ path More...
 
static char * os_get_exec_path (const struct GNUNET_OS_ProjectData *pd)
 get the path to current app's bin/ More...
 
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, the current running apps installation directory. More...
 
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 libexec/-directory to get the full path. More...
 
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 SUID_BINARY_PATH in the PATHS section of the configuration. More...
 
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. More...
 

Variables

static const struct GNUNET_OS_ProjectData default_pd
 Default project data used for installation path detection for GNUnet (core). More...
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)     GNUNET_log_from (kind, "util-os-installation", __VA_ARGS__)

Definition at line 46 of file os_installation.c.

◆ LOG_STRERROR_FILE

#define LOG_STRERROR_FILE (   kind,
  syscall,
  filename 
)
Value:
"util-os-installation", \
syscall, \
static char * filename
#define GNUNET_log_from_strerror_file(level, component, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...

Definition at line 49 of file os_installation.c.

Function Documentation

◆ get_path_from_PATH()

static char * get_path_from_PATH ( const char *  binary)
static

Return the actual path to a file found in the current PATH environment variable.

Parameters
binarythe name of the file to find
Returns
path to binary, NULL if not found

Definition at line 295 of file os_installation.c.

296{
297 char *path;
298 char *pos;
299 char *end;
300 char *buf;
301 const char *p;
302
303 if (NULL == (p = getenv ("PATH")))
304 return NULL;
305
306 path = GNUNET_strdup (p); /* because we write on it */
307 buf = GNUNET_malloc (strlen (path) + strlen (binary) + 1 + 1);
308 pos = path;
309 while (NULL != (end = strchr (pos,
311 {
312 *end = '\0';
313 sprintf (buf,
314 "%s/%s",
315 pos,
316 binary);
317 if (GNUNET_YES ==
319 {
320 pos = GNUNET_strdup (pos);
321 GNUNET_free (buf);
322 GNUNET_free (path);
323 return pos;
324 }
325 pos = end + 1;
326 }
327 sprintf (buf,
328 "%s/%s",
329 pos,
330 binary);
331 if (GNUNET_YES ==
333 {
334 pos = GNUNET_strdup (pos);
335 GNUNET_free (buf);
336 GNUNET_free (path);
337 return pos;
338 }
339 GNUNET_free (buf);
340 GNUNET_free (path);
341 return NULL;
342}
char * getenv()
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:33
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
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).
Definition: disk.c:506
@ GNUNET_YES
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define PATH_SEPARATOR
Definition: platform.h:167

References end, getenv(), GNUNET_DISK_file_test(), GNUNET_free, GNUNET_malloc, GNUNET_strdup, GNUNET_YES, p, and PATH_SEPARATOR.

Referenced by GNUNET_OS_check_helper_binary(), and os_get_gnunet_path().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_path_from_GNUNET_PREFIX()

static char * get_path_from_GNUNET_PREFIX ( const struct GNUNET_OS_ProjectData pd)
static

Try to obtain the installation path using the "GNUNET_PREFIX" environment variable.

Parameters
pdproject data to use to determine paths
Returns
NULL on error (environment variable not set)

Definition at line 353 of file os_installation.c.

354{
355 const char *p;
356
357 if ((NULL != pd->env_varname) &&
358 (NULL != (p = getenv (pd->env_varname))))
359 return GNUNET_strdup (p);
360 if ((NULL != pd->env_varname_alt) &&
361 (NULL != (p = getenv (pd->env_varname_alt))))
362 return GNUNET_strdup (p);
363 return NULL;
364}
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,...

References GNUNET_OS_ProjectData::env_varname, GNUNET_OS_ProjectData::env_varname_alt, getenv(), GNUNET_strdup, and p.

Referenced by os_get_gnunet_path().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ os_get_gnunet_path()

static char * os_get_gnunet_path ( const struct GNUNET_OS_ProjectData pd)
static

get the path to GNUnet bin/ or lib/, preferring the lib/ path

Author
Milan
Parameters
pdproject data to use to determine paths
Returns
a pointer to the executable path, or NULL on error

Definition at line 375 of file os_installation.c.

376{
377 char *ret;
378
379 if (NULL != (ret = get_path_from_GNUNET_PREFIX (pd)))
380 return ret;
381#ifdef __linux__
382 if (NULL != (ret = get_path_from_proc_maps (pd)))
383 return ret;
384 /* try path *first*, before /proc/exe, as /proc/exe can be wrong */
385 if ((NULL != pd->binary_name) &&
386 (NULL != (ret = get_path_from_PATH (pd->binary_name))))
387 return ret;
388 if (NULL != (ret = get_path_from_proc_exe (pd)))
389 return ret;
390#endif
391#if DARWIN
392 if (NULL != (ret = get_path_from_dyld_image ()))
393 return ret;
394 if (NULL != (ret = get_path_from_NSGetExecutablePath ()))
395 return ret;
396#endif
397 if ((NULL != pd->binary_name) &&
398 (NULL != (ret = get_path_from_PATH (pd->binary_name))))
399 return ret;
400 /* other attempts here */
402 "Could not determine installation path for %s. Set `%s' environment variable.\n",
403 pd->project_dirname,
404 pd->env_varname);
405 return NULL;
406}
static int ret
Final status code.
Definition: gnunet-arm.c:93
@ GNUNET_ERROR_TYPE_ERROR
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 * get_path_from_PATH(const char *binary)
Return the actual path to a file found in the current PATH environment variable.
#define LOG(kind,...)
const char * binary_name
Name of a project-specific binary that should be in "$PREFIX/bin/".
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".

References GNUNET_OS_ProjectData::binary_name, GNUNET_OS_ProjectData::env_varname, get_path_from_GNUNET_PREFIX(), get_path_from_PATH(), GNUNET_ERROR_TYPE_ERROR, LOG, GNUNET_OS_ProjectData::project_dirname, and ret.

Referenced by GNUNET_OS_installation_get_path().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ os_get_exec_path()

static char * os_get_exec_path ( const struct GNUNET_OS_ProjectData pd)
static

get the path to current app's bin/

Parameters
pdproject data to use to determine paths
Returns
a pointer to the executable path, or NULL on error

Definition at line 416 of file os_installation.c.

417{
418 char *ret = NULL;
419
420#ifdef __linux__
421 if (NULL != (ret = get_path_from_proc_exe (pd)))
422 return ret;
423#endif
424#if DARWIN
425 if (NULL != (ret = get_path_from_NSGetExecutablePath ()))
426 return ret;
427#endif
428 /* other attempts here */
429 return ret;
430}

References ret.

Referenced by GNUNET_OS_installation_get_path().

Here is the caller graph for this function:

Variable Documentation

◆ default_pd

const struct GNUNET_OS_ProjectData default_pd
static
Initial value:
= {
.libname = "libgnunetutil",
.project_dirname = "gnunet",
.binary_name = "gnunet-arm",
.version = PACKAGE_VERSION " " VCS_VERSION,
.env_varname = "GNUNET_PREFIX",
.base_config_varname = "GNUNET_BASE_CONFIG",
.bug_email = "gnunet-developers@gnu.org",
.homepage = "http://www.gnu.org/s/gnunet/",
.config_file = "gnunet.conf",
.user_config_file = "~/.config/gnunet.conf",
.is_gnu = 1,
.gettext_domain = "gnunet",
.gettext_path = NULL,
.agpl_url = GNUNET_AGPL_URL,
}
#define GNUNET_AGPL_URL
NOTE: You MUST adjust this URL to point to the location of a publicly accessible repository (or TGZ) ...

Default project data used for installation path detection for GNUnet (core).

Definition at line 60 of file os_installation.c.

Referenced by GNUNET_OS_project_data_gnunet().