GNUnet  0.11.x
Data Structures | Macros | Typedefs | Enumerations | Functions
OS library

Low level process routines. More...

Data Structures

struct  GNUNET_OS_ProjectData
 Project-specific data used to help the OS subsystem find installation paths. More...
 

Macros

#define GNUNET_OS_get_hostname_max_length()   255
 Get maximum string length returned by gethostname() More...
 

Typedefs

typedef int(* GNUNET_OS_NetworkInterfaceProcessor) (void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen)
 Callback function invoked for each interface found. More...
 
typedef void(* GNUNET_OS_LineProcessor) (void *cls, const char *line)
 Type of a function to process a line of output. More...
 

Enumerations

enum  GNUNET_OS_InheritStdioFlags {
  GNUNET_OS_INHERIT_STD_NONE = 0, GNUNET_OS_INHERIT_STD_IN = 1, GNUNET_OS_INHERIT_STD_OUT = 2, GNUNET_OS_INHERIT_STD_ERR = 4,
  GNUNET_OS_INHERIT_STD_OUT_AND_ERR = 6, GNUNET_OS_INHERIT_STD_ALL = 7
}
 Flags that determine which of the standard streams should be inherited by the child process. More...
 
enum  GNUNET_OS_InstallationPathKind {
  GNUNET_OS_IPK_PREFIX, GNUNET_OS_IPK_BINDIR, GNUNET_OS_IPK_LIBDIR, GNUNET_OS_IPK_DATADIR,
  GNUNET_OS_IPK_LOCALEDIR, GNUNET_OS_IPK_SELF_PREFIX, GNUNET_OS_IPK_ICONDIR, GNUNET_OS_IPK_DOCDIR,
  GNUNET_OS_IPK_LIBEXECDIR
}
 Possible installation paths to request. More...
 
enum  GNUNET_OS_ProcessStatusType {
  GNUNET_OS_PROCESS_UNKNOWN, GNUNET_OS_PROCESS_RUNNING, GNUNET_OS_PROCESS_STOPPED, GNUNET_OS_PROCESS_EXITED,
  GNUNET_OS_PROCESS_SIGNALED
}
 Process status types. More...
 

Functions

const struct GNUNET_OS_ProjectDataGNUNET_OS_project_data_default (void)
 Return default project data used by 'libgnunetutil' for GNUnet. More...
 
const struct GNUNET_OS_ProjectDataGNUNET_OS_project_data_get (void)
 
void GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd)
 Setup OS subsystem with project data. More...
 
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, the current running apps installation directory. More...
 
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 libexec/-directory to get the full path. More...
 
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 SUID_BINARY_PATH in the PATHS section of the configuration. More...
 
void GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
 Enumerate all network interfaces. More...
 
struct GNUNET_OS_ProcessGNUNET_OS_process_current (void)
 Get process structure for current process. More...
 
int GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
 Sends a signal to the process. More...
 
void GNUNET_OS_process_destroy (struct GNUNET_OS_Process *proc)
 Cleans up process structure contents (OS-dependent) and deallocates it. More...
 
pid_t GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc)
 Get the pid of the process in question. More...
 
struct GNUNET_OS_ProcessGNUNET_OS_start_process_vap (int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, char *const argv[])
 Start a process. More...
 
struct GNUNET_OS_ProcessGNUNET_OS_start_process (int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...)
 Start a process. More...
 
struct GNUNET_OS_ProcessGNUNET_OS_start_process_va (int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, va_list va)
 Start a process. More...
 
struct GNUNET_OS_ProcessGNUNET_OS_start_process_v (int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, const int *lsocks, const char *filename, char *const argv[])
 Start a process. More...
 
struct GNUNET_OS_ProcessGNUNET_OS_start_process_s (int pipe_control, unsigned int std_inheritance, const int *lsocks, const char *filename,...)
 Start a process. More...
 
void GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd)
 Stop/kill a command. More...
 
struct GNUNET_OS_CommandHandleGNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls, struct GNUNET_TIME_Relative timeout, const char *binary,...)
 Run the given command line and call the given function for each line of the output. More...
 
int GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
 Retrieve the status of a process, waiting on it if dead. More...
 
int GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc)
 Wait for a process to terminate. More...
 
int GNUNET_OS_process_wait_status (struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
 Retrieve the status of a process, waiting on it if dead. More...
 
void GNUNET_OS_install_parent_control_handler (void *cls)
 Connects this process to its parent via pipe; essentially, the parent control handler will read signal numbers from the GNUNET_OS_CONTROL_PIPE (as given in an environment variable) and raise those signals. More...
 
int GNUNET_OS_check_helper_binary (const char *binary, int check_suid, const char *params)
 Check whether an executable exists and possibly if the suid bit is set on the file. More...
 

Detailed Description

Low level process routines.

This code manages child processes. We can communicate with child processes using signals. Because signals are not supported on W32 and Java (at least not nicely), we can alternatively use a pipe to send signals to the child processes (if the child process is a full-blown GNUnet process that supports reading signals from a pipe, of course). Naturally, this also only works for 'normal' termination via signals, and not as a replacement for SIGKILL. Thus using pipes to communicate signals should only be enabled if the child is a Java process OR if we are on Windoze.

Macro Definition Documentation

◆ GNUNET_OS_get_hostname_max_length

#define GNUNET_OS_get_hostname_max_length ( )    255

Get maximum string length returned by gethostname()

Definition at line 399 of file gnunet_os_lib.h.

Referenced by GNUNET_RESOLVER_hostname_resolve(), GNUNET_RESOLVER_local_fqdn_get(), GST_stats_init(), logger_run(), and run().

Typedef Documentation

◆ GNUNET_OS_NetworkInterfaceProcessor

typedef int(* GNUNET_OS_NetworkInterfaceProcessor) (void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen)

Callback function invoked for each interface found.

Parameters
clsclosure
namename of the interface (can be NULL for unknown)
isDefaultis this presumably the default interface
addraddress of this interface (can be NULL for unknown or unassigned)
broadcast_addrthe broadcast address (can be NULL for unknown or unassigned)
netmaskthe network mask (can be NULL for unknown or unassigned)
addrlenlength of the address
Returns
GNUNET_OK to continue iteration, GNUNET_SYSERR to abort

Definition at line 370 of file gnunet_os_lib.h.

◆ GNUNET_OS_LineProcessor

typedef void(* GNUNET_OS_LineProcessor) (void *cls, const char *line)

Type of a function to process a line of output.

Parameters
clsclosure
lineline of output from a command, NULL for the end

Definition at line 568 of file gnunet_os_lib.h.

Enumeration Type Documentation

◆ GNUNET_OS_InheritStdioFlags

Flags that determine which of the standard streams should be inherited by the child process.

Enumerator
GNUNET_OS_INHERIT_STD_NONE 

No standard streams should be inherited.

GNUNET_OS_INHERIT_STD_IN 

When this flag is set, the child process will inherit stdin of the parent.

GNUNET_OS_INHERIT_STD_OUT 

When this flag is set, the child process will inherit stdout of the parent.

GNUNET_OS_INHERIT_STD_ERR 

When this flag is set, the child process will inherit stderr of the parent.

GNUNET_OS_INHERIT_STD_OUT_AND_ERR 

When these flags are set, the child process will inherit stdout and stderr of the parent.

GNUNET_OS_INHERIT_STD_ALL 

Use this option to have all of the standard streams (stdin, stdout and stderror) be inherited.

Definition at line 68 of file gnunet_os_lib.h.

69 {
74 
80 
86 
92 
98 
104 };
When this flag is set, the child process will inherit stderr of the parent.
Definition: gnunet_os_lib.h:91
When this flag is set, the child process will inherit stdin of the parent.
Definition: gnunet_os_lib.h:79
Use this option to have all of the standard streams (stdin, stdout and stderror) be inherited...
No standard streams should be inherited.
Definition: gnunet_os_lib.h:73
When this flag is set, the child process will inherit stdout of the parent.
Definition: gnunet_os_lib.h:85
When these flags are set, the child process will inherit stdout and stderr of the parent...
Definition: gnunet_os_lib.h:97

◆ GNUNET_OS_InstallationPathKind

Possible installation paths to request.

Enumerator
GNUNET_OS_IPK_PREFIX 

Return the "PREFIX" directory given to configure.

GNUNET_OS_IPK_BINDIR 

Return the directory where the program binaries are installed.

(bin/)

GNUNET_OS_IPK_LIBDIR 

Return the directory where libraries are installed.

(lib/gnunet/)

GNUNET_OS_IPK_DATADIR 

Return the directory where data is installed (share/gnunet/)

GNUNET_OS_IPK_LOCALEDIR 

Return the directory where translations are installed (share/locale/)

GNUNET_OS_IPK_SELF_PREFIX 

Return the installation directory of this application, not the one of the overall GNUnet installation (in case they are different).

GNUNET_OS_IPK_ICONDIR 

Return the prefix of the path with application icons (share/icons/).

GNUNET_OS_IPK_DOCDIR 

Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).

GNUNET_OS_IPK_LIBEXECDIR 

Return the directory where helper binaries are installed (lib/gnunet/libexec/)

Definition at line 116 of file gnunet_os_lib.h.

117 {
122 
127 
132 
137 
142 
149 
154 
160 
165 };
Return the directory where translations are installed (share/locale/)
Return the directory where libraries are installed.
Return the "PREFIX" directory given to configure.
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
Return the installation directory of this application, not the one of the overall GNUnet installation...
Return the directory where the program binaries are installed.
Return the prefix of the path with application icons (share/icons/).
Return the directory where data is installed (share/gnunet/)

◆ GNUNET_OS_ProcessStatusType

Process status types.

Enumerator
GNUNET_OS_PROCESS_UNKNOWN 

The process is not known to the OS (or at least not one of our children).

GNUNET_OS_PROCESS_RUNNING 

The process is still running.

GNUNET_OS_PROCESS_STOPPED 

The process is paused (but could be resumed).

GNUNET_OS_PROCESS_EXITED 

The process exited with a return code.

GNUNET_OS_PROCESS_SIGNALED 

The process was killed by a signal.

Definition at line 171 of file gnunet_os_lib.h.

172 {
178 
183 
188 
193 
198 };
The process exited with a return code.
The process was killed by a signal.
The process is still running.
The process is not known to the OS (or at least not one of our children).
The process is paused (but could be resumed).

Function Documentation

◆ GNUNET_OS_project_data_default()

const struct GNUNET_OS_ProjectData* GNUNET_OS_project_data_default ( void  )

Return default project data used by 'libgnunetutil' for GNUnet.

Definition at line 92 of file os_installation.c.

References default_pd.

93 {
94  return &default_pd;
95 }
static const struct GNUNET_OS_ProjectData default_pd
Default project data used for installation path detection for GNUnet (core).

◆ GNUNET_OS_project_data_get()

const struct GNUNET_OS_ProjectData* GNUNET_OS_project_data_get ( void  )
Returns
current (actual) project data.
current project data.

Definition at line 102 of file os_installation.c.

References bindtextdomain, current_pd, gettextinit, GNUNET_free, GNUNET_OS_installation_get_path(), and GNUNET_OS_IPK_LOCALEDIR.

Referenced by format_help(), GNUNET_CONFIGURATION_load(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), LEGACY_SERVICE_run(), run(), and set_cont().

103 {
104  if (0 == gettextinit)
105  {
107  if (NULL != path)
108  bindtextdomain (PACKAGE, path);
109  GNUNET_free (path);
110  gettextinit = 1;
111  }
112  return current_pd;
113 }
Return the directory where translations are installed (share/locale/)
#define bindtextdomain(Domainname, Dirname)
Definition: gettext.h:57
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, the current running apps installation directory
static const struct GNUNET_OS_ProjectData * current_pd
Which project data do we currently use for installation path detection? Never NULL.
static int gettextinit
Wether or not gettext has been initialized for the library.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_init()

void GNUNET_OS_init ( const struct GNUNET_OS_ProjectData pd)

Setup OS subsystem with project data.

Parameters
pdproject data used to determine paths.
pdproject data used to determine paths

Definition at line 122 of file os_installation.c.

References bindtextdomain, buf, dir, removetrailingwhitespace::f, fn, gettextinit, GNUNET_asprintf(), GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_malloc, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_LOCALEDIR, GNUNET_snprintf(), GNUNET_strdup, len, GNUNET_OS_ProjectData::libname, line, LOG_STRERROR_FILE, p, GNUNET_OS_ProjectData::project_dirname, size, and zero.

123 {
124  if (0 == gettextinit)
125  {
127  if (NULL != path)
128  bindtextdomain (PACKAGE, path);
129  GNUNET_free (path);
130  gettextinit = 1;
131  }
132  GNUNET_assert (NULL != pd);
133  current_pd = pd;
134 }
Return the directory where translations are installed (share/locale/)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define bindtextdomain(Domainname, Dirname)
Definition: gettext.h:57
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, the current running apps installation directory
static const struct GNUNET_OS_ProjectData * current_pd
Which project data do we currently use for installation path detection? Never NULL.
static int gettextinit
Wether or not gettext has been initialized for the library.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_OS_installation_get_path()

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, the current running apps installation directory.

Parameters
dirkindwhat kind of directory is desired?
Returns
a pointer to the dir path (to be freed by the caller)

Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation directory.

Returns
a pointer to the dir path (to be freed by the caller)

Definition at line 443 of file os_installation.c.

References DIR_SEPARATOR, DIR_SEPARATOR_STR, GNUNET_asprintf(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_free_non_null, GNUNET_OS_IPK_BINDIR, GNUNET_OS_IPK_DATADIR, GNUNET_OS_IPK_DOCDIR, GNUNET_OS_IPK_ICONDIR, GNUNET_OS_IPK_LIBDIR, GNUNET_OS_IPK_LIBEXECDIR, GNUNET_OS_IPK_LOCALEDIR, GNUNET_OS_IPK_PREFIX, GNUNET_OS_IPK_SELF_PREFIX, GNUNET_strdup, GNUNET_YES, os_get_exec_path(), os_get_gnunet_path(), and GNUNET_OS_ProjectData::project_dirname.

Referenced by GNUNET_CONFIGURATION_load(), GNUNET_OS_get_libexec_binary_path(), GNUNET_OS_init(), GNUNET_OS_project_data_get(), GNUNET_PLUGIN_load_all(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), hostkeys_load(), load_keys(), plugin_init(), and run().

444 {
445  size_t n;
446  char *dirname;
447  char *execpath = NULL;
448  char *tmp;
449  char *multiarch;
450  char *libdir;
451  int isbasedir;
452 
453  /* if wanted, try to get the current app's bin/ */
454  if (dirkind == GNUNET_OS_IPK_SELF_PREFIX)
455  execpath = os_get_exec_path ();
456 
457  /* try to get GNUnet's bin/ or lib/, or if previous was unsuccessful some
458  * guess for the current app */
459  if (NULL == execpath)
460  execpath = os_get_gnunet_path ();
461 
462  if (NULL == execpath)
463  return NULL;
464 
465  n = strlen (execpath);
466  if (0 == n)
467  {
468  /* should never happen, but better safe than sorry */
469  GNUNET_free (execpath);
470  return NULL;
471  }
472  /* remove filename itself */
473  while ((n > 1) && (DIR_SEPARATOR == execpath[n - 1]))
474  execpath[--n] = '\0';
475 
476  isbasedir = 1;
477  if ((n > 6) && ((0 == strcasecmp (&execpath[n - 6], "/lib32")) ||
478  (0 == strcasecmp (&execpath[n - 6], "/lib64"))))
479  {
480  if ((GNUNET_OS_IPK_LIBDIR != dirkind) &&
481  (GNUNET_OS_IPK_LIBEXECDIR != dirkind))
482  {
483  /* strip '/lib32' or '/lib64' */
484  execpath[n - 6] = '\0';
485  n -= 6;
486  }
487  else
488  isbasedir = 0;
489  }
490  else if ((n > 4) && ((0 == strcasecmp (&execpath[n - 4], "/bin")) ||
491  (0 == strcasecmp (&execpath[n - 4], "/lib"))))
492  {
493  /* strip '/bin' or '/lib' */
494  execpath[n - 4] = '\0';
495  n -= 4;
496  }
497  multiarch = NULL;
498  if (NULL != (libdir = strstr (execpath, "/lib/")))
499  {
500  /* test for multi-arch path of the form "PREFIX/lib/MULTIARCH/";
501  here we need to re-add 'multiarch' to lib and libexec paths later! */
502  multiarch = &libdir[5];
503  if (NULL == strchr (multiarch, '/'))
504  libdir[0] =
505  '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */
506  else
507  multiarch =
508  NULL; /* maybe not, multiarch still has a '/', which is not OK */
509  }
510  /* in case this was a directory named foo-bin, remove "foo-" */
511  while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR))
512  execpath[--n] = '\0';
513  switch (dirkind)
514  {
517  dirname = GNUNET_strdup (DIR_SEPARATOR_STR);
518  break;
519 
522  break;
523 
525  if (isbasedir)
526  {
527  GNUNET_asprintf (&tmp,
528  "%s%s%s%s%s%s%s",
529  execpath,
530  DIR_SEPARATOR_STR "lib",
531  (NULL != multiarch) ? DIR_SEPARATOR_STR : "",
532  (NULL != multiarch) ? multiarch : "",
533  DIR_SEPARATOR_STR,
535  DIR_SEPARATOR_STR);
537  {
538  GNUNET_free (execpath);
539  return tmp;
540  }
541  GNUNET_free (tmp);
542  tmp = NULL;
543  dirname = NULL;
544  if (4 == sizeof(void *))
545  {
546  GNUNET_asprintf (&dirname,
547  DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR
548  "%s" DIR_SEPARATOR_STR,
550  GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
551  }
552  if (8 == sizeof(void *))
553  {
554  GNUNET_asprintf (&dirname,
555  DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR
556  "%s" DIR_SEPARATOR_STR,
558  GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
559  }
560 
561  if ((NULL != tmp) &&
563  {
564  GNUNET_free (execpath);
565  GNUNET_free_non_null (dirname);
566  return tmp;
567  }
568  GNUNET_free (tmp);
569  GNUNET_free_non_null (dirname);
570  }
571  GNUNET_asprintf (&dirname,
572  DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR,
574  break;
575 
577  GNUNET_asprintf (&dirname,
578  DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
579  "%s" DIR_SEPARATOR_STR,
581  break;
582 
584  dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
585  "locale" DIR_SEPARATOR_STR);
586  break;
587 
589  dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
590  "icons" DIR_SEPARATOR_STR);
591  break;
592 
594  GNUNET_asprintf (&dirname,
595  DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR
596  "doc" DIR_SEPARATOR_STR
597  "%s" DIR_SEPARATOR_STR,
599  break;
600 
602  if (isbasedir)
603  {
604  GNUNET_asprintf (&dirname,
605  DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR
606  "libexec" DIR_SEPARATOR_STR,
608  GNUNET_asprintf (&tmp,
609  "%s%s%s%s",
610  execpath,
611  DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR,
612  (NULL != multiarch) ? multiarch : "",
613  dirname);
615  {
616  GNUNET_free (execpath);
617  GNUNET_free (dirname);
618  return tmp;
619  }
620  GNUNET_free (tmp);
621  tmp = NULL;
622  dirname = NULL;
623  if (4 == sizeof(void *))
624  {
625  GNUNET_asprintf (&dirname,
626  DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR
627  "%s" DIR_SEPARATOR_STR
628  "libexec" DIR_SEPARATOR_STR,
630  GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
631  }
632  if (8 == sizeof(void *))
633  {
634  GNUNET_asprintf (&dirname,
635  DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR
636  "%s" DIR_SEPARATOR_STR
637  "libexec" DIR_SEPARATOR_STR,
639  GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
640  }
641  if ((NULL != tmp) &&
643  {
644  GNUNET_free (execpath);
645  GNUNET_free_non_null (dirname);
646  return tmp;
647  }
648  GNUNET_free (tmp);
649  GNUNET_free_non_null (dirname);
650  }
651  GNUNET_asprintf (&dirname,
652  DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR
653  "libexec" DIR_SEPARATOR_STR,
655  break;
656 
657  default:
658  GNUNET_free (execpath);
659  return NULL;
660  }
661  GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
662  GNUNET_free (dirname);
663  GNUNET_free (execpath);
664  return tmp;
665 }
Return the directory where translations are installed (share/locale/)
Return the directory where libraries are installed.
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".
static char * os_get_gnunet_path()
get the path to GNUnet bin/ or lib/, prefering the lib/ path
int GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:503
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
Return the "PREFIX" directory given to configure.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
#define DIR_SEPARATOR_STR
Definition: platform.h:168
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
#define DIR_SEPARATOR
Definition: platform.h:167
static char * os_get_exec_path()
get the path to current app's bin/
static const struct GNUNET_OS_ProjectData * current_pd
Which project data do we currently use for installation path detection? Never NULL.
Return the installation directory of this application, not the one of the overall GNUnet installation...
Return the directory where the program binaries are installed.
#define GNUNET_YES
Definition: gnunet_common.h:77
Return the prefix of the path with application icons (share/icons/).
Return the directory where data is installed (share/gnunet/)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_get_libexec_binary_path()

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 libexec/-directory to get the full path.

Parameters
prognamename of the binary
Returns
full path to the binary, if possible, otherwise copy of 'progname'

Definition at line 677 of file os_installation.c.

References cache, DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_NO, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_LIBEXECDIR, GNUNET_strdup, GNUNET_STRINGS_path_is_absolute(), and GNUNET_YES.

Referenced by communicator_start(), GNUNET_HELPER_start(), GNUNET_OS_get_suid_binary_path(), GNUNET_TESTBED_controller_start(), GNUNET_TESTBED_is_host_habitable(), GNUNET_TESTING_peer_configure(), GNUNET_TESTING_service_run(), LIBGNUNET_PLUGIN_TRANSPORT_INIT(), run(), start_arm_service(), start_process(), start_shared_service_instance(), test_icmp_client(), test_icmp_server(), and tokenizer_cb().

678 {
679  static char *cache;
680  char *libexecdir;
681  char *binary;
682 
683  if ((DIR_SEPARATOR == progname[0]) ||
684  (GNUNET_YES ==
685  GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL)))
686  return GNUNET_strdup (progname);
687  if (NULL != cache)
688  libexecdir = cache;
689  else
691  if (NULL == libexecdir)
692  return GNUNET_strdup (progname);
693  GNUNET_asprintf (&binary, "%s%s", libexecdir, progname);
694  cache = libexecdir;
695  return binary;
696 }
int 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.
Definition: strings.c:1108
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
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, the current running apps installation directory
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
#define DIR_SEPARATOR
Definition: platform.h:167
static struct GNUNET_CONTAINER_MultiHashMap32 * cache
Hashmap to maintain cache.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_get_suid_binary_path()

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 SUID_BINARY_PATH in the PATHS section of the configuration.

If that option is not present, fall back to GNUNET_OS_get_libexec_binary_path. If progname is an absolute path, a copy of this path is returned.

Parameters
cfgconfiguration to inspect
prognamename of the binary
Returns
full path to the binary, if possible, a copy of progname otherwise

Definition at line 712 of file os_installation.c.

References cache, DIR_SEPARATOR, DIR_SEPARATOR_STR, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_NO, GNUNET_OS_get_libexec_binary_path(), GNUNET_strdup, GNUNET_STRINGS_path_is_absolute(), and GNUNET_YES.

Referenced by GN_request_connection_reversal(), restart_nat_server(), and run().

714 {
715  static char *cache;
716  char *binary = NULL;
717  char *path = NULL;
718  size_t path_len;
719 
720  if (GNUNET_YES ==
721  GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL))
722  {
723  return GNUNET_strdup (progname);
724  }
725  if (NULL != cache)
726  path = cache;
727  else
729  "PATHS",
730  "SUID_BINARY_PATH",
731  &path);
732  if ((NULL == path) || (0 == strlen (path)))
733  return GNUNET_OS_get_libexec_binary_path (progname);
734  path_len = strlen (path);
735  GNUNET_asprintf (&binary,
736  "%s%s%s",
737  path,
738  (path[path_len - 1] == DIR_SEPARATOR) ? ""
740  progname);
741  cache = path;
742  return binary;
743 }
int 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.
Definition: strings.c:1108
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define DIR_SEPARATOR_STR
Definition: platform.h:168
int 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.
#define DIR_SEPARATOR
Definition: platform.h:167
static struct GNUNET_CONTAINER_MultiHashMap32 * cache
Hashmap to maintain cache.
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 ...
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_network_interfaces_list()

void GNUNET_OS_network_interfaces_list ( GNUNET_OS_NetworkInterfaceProcessor  proc,
void *  proc_cls 
)

Enumerate all network interfaces.

Parameters
procthe callback function
proc_clsclosure for proc

Definition at line 396 of file os_network.c.

References GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_WARNING, GNUNET_OK, LOG, try_ifconfig(), and try_ip().

Referenced by do_broadcast(), get_addresses(), GNUNET_NT_scanner_init(), host_habitable_cb(), run_scan(), setup_broadcast(), and test_local_ip().

398 {
399 #if HAVE_GETIFADDRS && HAVE_FREEIFADDRS
400  struct ifaddrs *ifa_first;
401  struct ifaddrs *ifa_ptr;
402  socklen_t alen;
403 
404  if (getifaddrs (&ifa_first) == 0)
405  {
406  for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next)
407  {
408  if ((ifa_ptr->ifa_name != NULL) && (ifa_ptr->ifa_addr != NULL) &&
409  ( (ifa_ptr->ifa_flags & IFF_UP) != 0) )
410  {
411  if ((ifa_ptr->ifa_addr->sa_family != AF_INET) &&
412  (ifa_ptr->ifa_addr->sa_family != AF_INET6))
413  continue;
414  if (ifa_ptr->ifa_addr->sa_family == AF_INET)
415  alen = sizeof(struct sockaddr_in);
416  else
417  alen = sizeof(struct sockaddr_in6);
418  if (GNUNET_OK !=
419  proc (proc_cls, ifa_ptr->ifa_name,
420  (0 == strcmp (ifa_ptr->ifa_name, GNUNET_DEFAULT_INTERFACE)),
421  ifa_ptr->ifa_addr, ifa_ptr->ifa_broadaddr,
422  ifa_ptr->ifa_netmask, alen))
423  break;
424  }
425  }
426  freeifaddrs (ifa_first);
427  }
428 #else
429  if (GNUNET_OK ==
430  try_ip (proc,
431  proc_cls))
432  return;
433  if (GNUNET_OK ==
434  try_ifconfig (proc,
435  proc_cls))
436  return;
438  "Failed to enumerate network interfaces\n");
439 #endif
440 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define LOG(kind,...)
Definition: os_network.c:34
static int try_ip(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Try to enumerate all network interfaces using 'ip'.
Definition: os_network.c:244
static int try_ifconfig(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Try to enumerate all network interfaces using 'ifconfig'.
Definition: os_network.c:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_process_current()

struct GNUNET_OS_Process* GNUNET_OS_process_current ( void  )

Get process structure for current process.

The pointer it returns points to static memory location and must not be deallocated/closed

Returns
pointer to the process sturcutre for this process

The pointer it returns points to static memory location and must not be deallocated/closed.

Returns
pointer to the process sturcutre for this process

Definition at line 210 of file os_priority.c.

References current_process, and GNUNET_OS_Process::pid.

211 {
212  current_process.pid = 0;
213  return &current_process;
214 }
pid_t pid
PID of the process.
Definition: os_priority.c:48
static struct GNUNET_OS_Process current_process
Handle for 'this' process.
Definition: os_priority.c:62

◆ GNUNET_OS_process_kill()

int GNUNET_OS_process_kill ( struct GNUNET_OS_Process proc,
int  sig 
)

Sends a signal to the process.

Parameters
procpointer to process structure
sigsignal
Returns
0 on success, -1 on error

Definition at line 225 of file os_priority.c.

References GNUNET_OS_Process::control_pipe, GNUNET_DISK_file_write(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_TERM_SIG, LOG, GNUNET_OS_Process::pid, and ret.

Referenced by do_stop_task(), GN_stop_gnunet_nat_server_(), GNUNET_HELPER_kill(), GNUNET_NAT_mini_get_external_ipv4_cancel_(), GNUNET_OS_command_stop(), GNUNET_TESTBED_is_host_habitable_cancel(), GNUNET_TESTING_peer_kill(), handle_stop(), maint_child_death(), nat_server_read(), shutdown_communicator(), shutdown_task(), stop_shared_service_instance(), and terminate_task().

226 {
227  int ret;
228  char csig;
229 
230  csig = (char) sig;
231  if (NULL != proc->control_pipe)
232  {
234  "Sending signal %d to pid: %u via pipe\n",
235  sig,
236  proc->pid);
237  ret = GNUNET_DISK_file_write (proc->control_pipe, &csig, sizeof(csig));
238  if (sizeof(csig) == ret)
239  return 0;
240  }
241  /* pipe failed or non-existent, try other methods */
242  switch (sig)
243  {
244  case SIGHUP:
245  case SIGINT:
246  case SIGKILL:
247  case SIGTERM:
248 #if (SIGTERM != GNUNET_TERM_SIG)
249  case GNUNET_TERM_SIG:
250 #endif
252  "Sending signal %d to pid: %u via system call\n",
253  sig,
254  proc->pid);
255  return kill (proc->pid, sig);
256  default:
258  "Sending signal %d to pid: %u via system call\n",
259  sig,
260  proc->pid);
261  return kill (proc->pid, sig);
262  }
263 }
pid_t pid
PID of the process.
Definition: os_priority.c:48
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:820
struct GNUNET_DISK_FileHandle * control_pipe
Pipe we use to signal the process.
Definition: os_priority.c:55
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:242
#define LOG(kind,...)
Definition: os_priority.c:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_process_destroy()

void GNUNET_OS_process_destroy ( struct GNUNET_OS_Process proc)

Cleans up process structure contents (OS-dependent) and deallocates it.

Parameters
procpointer to process structure

Definition at line 287 of file os_priority.c.

References GNUNET_OS_Process::control_pipe, GNUNET_DISK_file_close(), and GNUNET_free.

Referenced by child_death_task(), GN_request_connection_reversal(), GN_stop_gnunet_nat_server_(), GNUNET_HELPER_wait(), GNUNET_NAT_mini_get_external_ipv4_cancel_(), GNUNET_OS_command_stop(), GNUNET_TESTBED_is_host_habitable_cancel(), GNUNET_TESTING_peer_wait(), habitability_check(), maint_child_death(), nat_server_read(), server_log(), shutdown_communicator(), shutdown_task(), start_arm_service(), and stop_shared_service_instance().

288 {
289  if (NULL != proc->control_pipe)
291 
292  GNUNET_free (proc);
293 }
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1345
struct GNUNET_DISK_FileHandle * control_pipe
Pipe we use to signal the process.
Definition: os_priority.c:55
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_process_get_pid()

pid_t GNUNET_OS_process_get_pid ( struct GNUNET_OS_Process proc)

Get the pid of the process in question.

Parameters
procthe process to get the pid of
Returns
the current process id

Definition at line 274 of file os_priority.c.

References GNUNET_OS_Process::pid.

Referenced by maint_child_death().

275 {
276  return proc->pid;
277 }
pid_t pid
PID of the process.
Definition: os_priority.c:48
Here is the caller graph for this function:

◆ GNUNET_OS_start_process_vap()

struct GNUNET_OS_Process* GNUNET_OS_start_process_vap ( int  pipe_control,
enum GNUNET_OS_InheritStdioFlags  std_inheritance,
struct GNUNET_DISK_PipeHandle pipe_stdin,
struct GNUNET_DISK_PipeHandle pipe_stdout,
struct GNUNET_DISK_PipeHandle pipe_stderr,
const char *  filename,
char *const  argv[] 
)

Start a process.

Parameters
pipe_controlshould a pipe be used to send signals to the child?
std_inheritancea set of GNUNET_OS_INHERIT_STD_* flags
pipe_stdinpipe to use to send input to child process (or NULL)
pipe_stdoutpipe to use to get output from child process (or NULL)
pipe_stderrpipe to use to get error output from child process (or NULL)
filenamename of the binary
argvNULL-terminated array of arguments to the process
Returns
pointer to process structure of the new process, NULL on error
Parameters
pipe_controlshould a pipe be used to send signals to the child?
std_inheritancea set of GNUNET_OS_INHERIT_STD_* flags
pipe_stdinpipe to use to send input to child process (or NULL)
pipe_stdoutpipe to use to get output from child process (or NULL)
pipe_stderrpipe to use to get output from child process (or NULL)
filenamename of the binary
argvNULL-terminated array of arguments to the process
Returns
pointer to process structure of the new process, NULL on error

Definition at line 607 of file os_priority.c.

References start_process().

Referenced by GNUNET_OS_start_process_va(), GNUNET_TESTBED_is_host_habitable(), main(), run(), start_helper(), and work().

614 {
615  return start_process (pipe_control,
616  std_inheritance,
617  pipe_stdin,
618  pipe_stdout,
619  pipe_stderr,
620  NULL,
621  filename,
622  argv);
623 }
static struct GNUNET_OS_Process * start_process(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const int *lsocks, const char *filename, char *const argv[])
Start a process.
Definition: os_priority.c:344
static char * filename
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_start_process()

struct GNUNET_OS_Process* GNUNET_OS_start_process ( int  pipe_control,
enum GNUNET_OS_InheritStdioFlags  std_inheritance,
struct GNUNET_DISK_PipeHandle pipe_stdin,
struct GNUNET_DISK_PipeHandle pipe_stdout,
struct GNUNET_DISK_PipeHandle pipe_stderr,
const char *  filename,
  ... 
)

Start a process.

Parameters
pipe_controlshould a pipe be used to send signals to the child?
std_inheritancea set of GNUNET_OS_INHERIT_STD_* flags
pipe_stdinpipe to use to send input to child process (or NULL)
pipe_stdoutpipe to use to get output from child process (or NULL)
pipe_stderrpipe to use to get error output from child process (or NULL)
filenamename of the binary
...NULL-terminated list of arguments to the process
Returns
pointer to process structure of the new process, NULL on error
Parameters
pipe_controlshould a pipe be used to send signals to the child?
std_inheritancea set of GNUNET_OS_INHERIT_STD_* flags
pipe_stdinpipe to use to send input to child process (or NULL)
pipe_stdoutpipe to use to get output from child process (or NULL)
filenamename of the binary
...NULL-terminated list of arguments to the process
Returns
pointer to process structure of the new process, NULL on error

Definition at line 687 of file os_priority.c.

References GNUNET_OS_start_process_va(), and ret.

Referenced by communicator_start(), GN_request_connection_reversal(), GNUNET_NAT_mini_get_external_ipv4_(), gnunet_uri(), restart_nat_server(), run(), server_log(), start_shared_service_instance(), and tokenizer_cb().

694 {
695  struct GNUNET_OS_Process *ret;
696  va_list ap;
697 
698  va_start (ap, filename);
699  ret = GNUNET_OS_start_process_va (pipe_control,
700  std_inheritance,
701  pipe_stdin,
702  pipe_stdout,
703  pipe_stderr,
704  filename,
705  ap);
706  va_end (ap);
707  return ret;
708 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_OS_Process * GNUNET_OS_start_process_va(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, va_list va)
Start a process.
Definition: os_priority.c:639
static char * filename
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_start_process_va()

struct GNUNET_OS_Process* GNUNET_OS_start_process_va ( int  pipe_control,
enum GNUNET_OS_InheritStdioFlags  std_inheritance,
struct GNUNET_DISK_PipeHandle pipe_stdin,
struct GNUNET_DISK_PipeHandle pipe_stdout,
struct GNUNET_DISK_PipeHandle pipe_stderr,
const char *  filename,
va_list  va 
)

Start a process.

Parameters
pipe_controlshould a pipe be used to send signals to the child?
std_inheritancea set of GNUNET_OS_INHERIT_STD_* flags
pipe_stdinpipe to use to send input to child process (or NULL)
pipe_stdoutpipe to use to get output from child process (or NULL)
pipe_stderrpipe to use to get error output from child process (or NULL)
filenamename of the binary
vaNULL-terminated list of arguments to the process
Returns
pointer to process structure of the new process, NULL on error
Parameters
pipe_controlshould a pipe be used to send signals to the child?
std_inheritancea set of GNUNET_OS_INHERIT_STD_* flags
pipe_stdinpipe to use to send input to child process (or NULL)
pipe_stdoutpipe to use to get output from child process (or NULL)
pipe_stderrpipe to use to get output from child process (or NULL)
filenamename of the binary
vaNULL-terminated list of arguments to the process
Returns
pointer to process structure of the new process, NULL on error

Definition at line 639 of file os_priority.c.

References GNUNET_free, GNUNET_malloc, GNUNET_OS_start_process_vap(), and ret.

Referenced by GNUNET_OS_command_run(), GNUNET_OS_start_process(), and run_process_and_wait().

646 {
647  struct GNUNET_OS_Process *ret;
648  va_list ap;
649  char **argv;
650  int argc;
651 
652  argc = 0;
653  va_copy (ap, va);
654  while (NULL != va_arg (ap, char *))
655  argc++;
656  va_end (ap);
657  argv = GNUNET_malloc (sizeof(char *) * (argc + 1));
658  argc = 0;
659  va_copy (ap, va);
660  while (NULL != (argv[argc] = va_arg (ap, char *)))
661  argc++;
662  va_end (ap);
663  ret = GNUNET_OS_start_process_vap (pipe_control,
664  std_inheritance,
665  pipe_stdin,
666  pipe_stdout,
667  pipe_stderr,
668  filename,
669  argv);
670  GNUNET_free (argv);
671  return ret;
672 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_OS_Process * GNUNET_OS_start_process_vap(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, char *const argv[])
Start a process.
Definition: os_priority.c:607
static char * filename
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_start_process_v()

struct GNUNET_OS_Process* GNUNET_OS_start_process_v ( int  pipe_control,
enum GNUNET_OS_InheritStdioFlags  std_inheritance,
const int *  lsocks,
const char *  filename,
char *const  argv[] 
)

Start a process.

Parameters
pipe_controlshould a pipe be used to send signals to the child?
std_inheritancea set of GNUNET_OS_INHERIT_STD_* flags
lsocksarray of listen sockets to dup systemd-style (or NULL); must be NULL on platforms where dup is not supported
filenamename of the binary
argvNULL-terminated list of arguments to the process, including the process name as the first argument
Returns
pointer to process structure of the new process, NULL on error
Parameters
pipe_controlshould a pipe be used to send signals to the child?
std_inheritancea set of GNUNET_OS_INHERIT_STD_* flags controlling which std handles of the parent are inherited by the child. pipe_stdin and pipe_stdout take priority over std_inheritance (when they are non-NULL).
lsocksarray of listen sockets to dup systemd-style (or NULL); must be NULL on platforms where dup is not supported
filenamename of the binary
argvNULL-terminated list of arguments to the process
Returns
process ID of the new process, -1 on error

Definition at line 726 of file os_priority.c.

References start_process().

Referenced by GNUNET_OS_start_process_s().

731 {
732  return start_process (pipe_control,
733  std_inheritance,
734  NULL,
735  NULL,
736  NULL,
737  lsocks,
738  filename,
739  argv);
740 }
static struct GNUNET_OS_Process * start_process(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const int *lsocks, const char *filename, char *const argv[])
Start a process.
Definition: os_priority.c:344
static char * filename
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_start_process_s()

struct GNUNET_OS_Process* GNUNET_OS_start_process_s ( int  pipe_control,
unsigned int  std_inheritance,
const int *  lsocks,
const char *  filename,
  ... 
)

Start a process.

This function is similar to the GNUNET_OS_start_process_* except that the filename and arguments can have whole strings which contain the arguments. These arguments are to be separated by spaces and are parsed in the order they appear. Arguments containing spaces can be used by quoting them with ".

Parameters
pipe_controlshould a pipe be used to send signals to the child?
std_inheritancea set of GNUNET_OS_INHERIT_STD_* flags
lsocksarray of listen sockets to dup systemd-style (or NULL); must be NULL on platforms where dup is not supported
filenamename of the binary. It is valid to have the arguments in this string when they are separated by spaces.
...more arguments. Should be of type char *. It is valid to have the arguments in these strings when they are separated by spaces. The last argument MUST be NULL.
Returns
pointer to process structure of the new process, NULL on error

Definition at line 762 of file os_priority.c.

References find_typedefs::arg, filename, GNUNET_free, GNUNET_malloc, GNUNET_OS_start_process_v(), GNUNET_strdup, and len.

Referenced by GNUNET_TESTING_peer_start(), start_arm_service(), and start_process().

767 {
768  va_list ap;
769  char **argv;
770  unsigned int argv_size;
771  const char *arg;
772  const char *rpos;
773  char *pos;
774  char *cp;
775  const char *last;
776  struct GNUNET_OS_Process *proc;
777  char *binary_path;
778  int quote_on;
779  unsigned int i;
780  size_t len;
781 
782  argv_size = 1;
783  va_start (ap, filename);
784  arg = filename;
785  last = NULL;
786  do
787  {
788  rpos = arg;
789  quote_on = 0;
790  while ('\0' != *rpos)
791  {
792  if ('"' == *rpos)
793  {
794  if (1 == quote_on)
795  quote_on = 0;
796  else
797  quote_on = 1;
798  }
799  if ((' ' == *rpos) && (0 == quote_on))
800  {
801  if (NULL != last)
802  argv_size++;
803  last = NULL;
804  rpos++;
805  while (' ' == *rpos)
806  rpos++;
807  }
808  if ((NULL == last) && ('\0' != *rpos)) // FIXME: == or !=?
809  last = rpos;
810  if ('\0' != *rpos)
811  rpos++;
812  }
813  if (NULL != last)
814  argv_size++;
815  }
816  while (NULL != (arg = (va_arg (ap, const char *))));
817  va_end (ap);
818 
819  argv = GNUNET_malloc (argv_size * sizeof(char *));
820  argv_size = 0;
821  va_start (ap, filename);
822  arg = filename;
823  last = NULL;
824  do
825  {
826  cp = GNUNET_strdup (arg);
827  quote_on = 0;
828  pos = cp;
829  while ('\0' != *pos)
830  {
831  if ('"' == *pos)
832  {
833  if (1 == quote_on)
834  quote_on = 0;
835  else
836  quote_on = 1;
837  }
838  if ((' ' == *pos) && (0 == quote_on))
839  {
840  *pos = '\0';
841  if (NULL != last)
842  argv[argv_size++] = GNUNET_strdup (last);
843  last = NULL;
844  pos++;
845  while (' ' == *pos)
846  pos++;
847  }
848  if ((NULL == last) && ('\0' != *pos)) // FIXME: == or !=?
849  last = pos;
850  if ('\0' != *pos)
851  pos++;
852  }
853  if (NULL != last)
854  argv[argv_size++] = GNUNET_strdup (last);
855  last = NULL;
856  GNUNET_free (cp);
857  }
858  while (NULL != (arg = (va_arg (ap, const char *))));
859  va_end (ap);
860  argv[argv_size] = NULL;
861 
862  for (i = 0; i < argv_size; i++)
863  {
864  len = strlen (argv[i]);
865  if ((argv[i][0] == '"') && (argv[i][len - 1] == '"'))
866  {
867  memmove (&argv[i][0], &argv[i][1], len - 2);
868  argv[i][len - 2] = '\0';
869  }
870  }
871  binary_path = argv[0];
872  proc = GNUNET_OS_start_process_v (pipe_control,
873  std_inheritance,
874  lsocks,
875  binary_path,
876  argv);
877  while (argv_size > 0)
878  GNUNET_free (argv[--argv_size]);
879  GNUNET_free (argv);
880  return proc;
881 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * filename
struct GNUNET_OS_Process * GNUNET_OS_start_process_v(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, const int *lsocks, const char *filename, char *const argv[])
Start a process.
Definition: os_priority.c:726
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_command_stop()

void GNUNET_OS_command_stop ( struct GNUNET_OS_CommandHandle cmd)

Stop/kill a command.

Parameters
cmdhandle to the process

Must ONLY be called either from the callback after 'NULL' was passed for 'line' OR from an independent task (not within the line processor).

Parameters
cmdhandle to the process

Definition at line 1076 of file os_priority.c.

References GNUNET_OS_CommandHandle::eip, GNUNET_assert, GNUNET_break, GNUNET_DISK_pipe_close(), GNUNET_free, GNUNET_OK, GNUNET_OS_process_destroy(), GNUNET_OS_process_kill(), GNUNET_OS_process_wait(), GNUNET_SCHEDULER_cancel(), GNUNET_OS_CommandHandle::opipe, GNUNET_OS_CommandHandle::proc, and GNUNET_OS_CommandHandle::rtask.

Referenced by do_refresh(), GNUNET_NAT_mini_map_stop(), process_map_output(), process_refresh_output(), and process_unmap_output().

1077 {
1078  if (NULL != cmd->proc)
1079  {
1080  GNUNET_assert (NULL != cmd->rtask);
1082  }
1083  (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL);
1087  GNUNET_free (cmd);
1088 }
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:287
struct GNUNET_DISK_PipeHandle * opipe
Handle to the output pipe.
Definition: os_priority.c:1029
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_OS_Process * eip
Process handle.
Definition: os_priority.c:1024
struct GNUNET_SCHEDULER_Task * rtask
Task reading from pipe.
Definition: os_priority.c:1054
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1715
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:1000
GNUNET_OS_LineProcessor proc
Function to call on each line of output.
Definition: os_priority.c:1039
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:225
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_command_run()

struct GNUNET_OS_CommandHandle* GNUNET_OS_command_run ( GNUNET_OS_LineProcessor  proc,
void *  proc_cls,
struct GNUNET_TIME_Relative  timeout,
const char *  binary,
  ... 
)

Run the given command line and call the given function for each line of the output.

Parameters
procfunction to call for each line of the output
proc_clsclosure for proc
timeoutwhen to time out
binarycommand to run
...arguments to command
Returns
NULL on error
Parameters
procfunction to call for each line of the output
proc_clsclosure for proc
timeoutwhen to time out
binarycommand to run
...arguments to command
Returns
NULL on error

Definition at line 1161 of file os_priority.c.

References cmd_read(), GNUNET_OS_CommandHandle::eip, GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_DISK_pipe_close_end(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_PIPE_END_WRITE, GNUNET_DISK_pipe_handle(), GNUNET_new, GNUNET_NO, GNUNET_OS_start_process_va(), GNUNET_SCHEDULER_add_read_file(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, GNUNET_OS_CommandHandle::opipe, GNUNET_OS_CommandHandle::proc, GNUNET_OS_CommandHandle::proc_cls, GNUNET_OS_CommandHandle::r, GNUNET_OS_CommandHandle::rtask, and GNUNET_OS_CommandHandle::timeout.

Referenced by do_refresh(), GNUNET_NAT_mini_map_stop(), and run_upnpc_r().

1166 {
1167  struct GNUNET_OS_CommandHandle *cmd;
1168  struct GNUNET_OS_Process *eip;
1169  struct GNUNET_DISK_PipeHandle *opipe;
1170  va_list ap;
1171 
1173  if (NULL == opipe)
1174  return NULL;
1175  va_start (ap, binary);
1176  /* redirect stdout, don't inherit stderr/stdin */
1177  eip =
1178  GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, NULL, binary, ap);
1179  va_end (ap);
1180  if (NULL == eip)
1181  {
1182  GNUNET_DISK_pipe_close (opipe);
1183  return NULL;
1184  }
1186  cmd = GNUNET_new (struct GNUNET_OS_CommandHandle);
1187  cmd->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1188  cmd->eip = eip;
1189  cmd->opipe = opipe;
1190  cmd->proc = proc;
1191  cmd->proc_cls = proc_cls;
1193  cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
1194  return cmd;
1195 }
const struct GNUNET_DISK_FileHandle * r
Read-end of output pipe.
Definition: os_priority.c:1034
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
struct GNUNET_DISK_PipeHandle * opipe
Handle to the output pipe.
Definition: os_priority.c:1029
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1636
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_OS_Process * GNUNET_OS_start_process_va(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, va_list va)
Start a process.
Definition: os_priority.c:639
struct GNUNET_TIME_Absolute timeout
When to time out.
Definition: os_priority.c:1059
void * proc_cls
Closure for proc.
Definition: os_priority.c:1044
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:1753
struct GNUNET_OS_Process * eip
Process handle.
Definition: os_priority.c:1024
static void cmd_read(void *cls)
Read from the process and call the line processor.
Definition: os_priority.c:1097
The writing-end of a pipe.
The reading-end of a pipe.
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(int blocking_read, int blocking_write, int inherit_read, int inherit_write)
Creates an interprocess channel.
Definition: disk.c:1526
struct GNUNET_SCHEDULER_Task * rtask
Task reading from pipe.
Definition: os_priority.c:1054
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1715
int GNUNET_DISK_pipe_close_end(struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end)
Closes one half of an interprocess channel.
Definition: disk.c:1643
Handle to a command.
Definition: os_priority.c:1019
GNUNET_OS_LineProcessor proc
Function to call on each line of output.
Definition: os_priority.c:1039
#define GNUNET_YES
Definition: gnunet_common.h:77
Handle used to manage a pipe.
Definition: disk.c:68
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_process_status()

int GNUNET_OS_process_status ( struct GNUNET_OS_Process proc,
enum GNUNET_OS_ProcessStatusType type,
unsigned long *  code 
)

Retrieve the status of a process, waiting on it if dead.

Nonblocking version.

Parameters
procpointer to process structure
typestatus type
codereturn code/signal number
Returns
GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise

Nonblocking version.

Parameters
procprocess ID
typestatus type
codereturn code/signal number
Returns
GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise

Definition at line 963 of file os_priority.c.

References process_status().

Referenced by child_death_task(), habitability_check(), main(), maint_child_death(), and run_process_and_wait().

966 {
967  return process_status (proc, type, code, WNOHANG);
968 }
static int process_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code, int options)
Retrieve the status of a process, waiting on it if dead.
Definition: os_priority.c:895
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_process_wait()

int GNUNET_OS_process_wait ( struct GNUNET_OS_Process proc)

Wait for a process to terminate.

The return code is discarded. You must not use GNUNET_OS_process_status() on the same process after calling this function! This function is blocking and should thus only be used if the child process is known to have terminated or to terminate very soon.

Parameters
procpointer to process structure of the process to wait for
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

The return code is discarded. You must not use GNUNET_OS_process_status() on the same process after calling this function! This function is blocking and should thus only be used if the child process is known to have terminated or to terminate very soon.

Parameters
procpointer to process structure
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 1000 of file os_priority.c.

References GNUNET_ERROR_TYPE_WARNING, GNUNET_OK, GNUNET_SYSERR, LOG_STRERROR, GNUNET_OS_Process::pid, and ret.

Referenced by GN_request_connection_reversal(), GN_stop_gnunet_nat_server_(), GNUNET_HELPER_wait(), GNUNET_NAT_mini_get_external_ipv4_cancel_(), GNUNET_OS_command_stop(), GNUNET_TESTBED_is_host_habitable_cancel(), GNUNET_TESTING_peer_wait(), nat_server_read(), run_process_and_wait(), server_log(), shutdown_task(), and stop_shared_service_instance().

1001 {
1002  pid_t pid = proc->pid;
1003  pid_t ret;
1004 
1005  while ((pid != (ret = waitpid (pid, NULL, 0))) && (EINTR == errno))
1006  ;
1007  if (pid != ret)
1008  {
1010  return GNUNET_SYSERR;
1011  }
1012  return GNUNET_OK;
1013 }
#define LOG_STRERROR(kind, syscall)
Definition: os_priority.c:34
pid_t pid
PID of the process.
Definition: os_priority.c:48
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
Here is the caller graph for this function:

◆ GNUNET_OS_process_wait_status()

int GNUNET_OS_process_wait_status ( struct GNUNET_OS_Process proc,
enum GNUNET_OS_ProcessStatusType type,
unsigned long *  code 
)

Retrieve the status of a process, waiting on it if dead.

Blocking version.

Parameters
procpointer to process structure
typestatus type
codereturn code/signal number
Returns
GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise

Definition at line 981 of file os_priority.c.

References process_status().

984 {
985  return process_status (proc, type, code, 0);
986 }
static int process_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code, int options)
Retrieve the status of a process, waiting on it if dead.
Definition: os_priority.c:895
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Here is the call graph for this function:

◆ GNUNET_OS_install_parent_control_handler()

void GNUNET_OS_install_parent_control_handler ( void *  cls)

Connects this process to its parent via pipe; essentially, the parent control handler will read signal numbers from the GNUNET_OS_CONTROL_PIPE (as given in an environment variable) and raise those signals.

Parameters
clsclosure (unused)

Connects this process to its parent via pipe; essentially, the parent control handler will read signal numbers from the GNUNET_OS_CONTROL_PIPE (as given in an environment variable) and raise those signals.

Parameters
clsclosure (unused)

Definition at line 141 of file os_priority.c.

References GNUNET_OS_Process::control_pipe, getenv(), GNUNET_break, GNUNET_DISK_get_handle_from_int_fd(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_OS_CONTROL_PIPE, GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_TIME_UNIT_FOREVER_REL, LOG, LOG_STRERROR_FILE, parent_control_handler(), and shutdown_pch().

Referenced by install_parent_control_handler().

142 {
143  const char *env_buf;
144  char *env_buf_end;
145  struct GNUNET_DISK_FileHandle *control_pipe;
146  uint64_t pipe_fd;
147 
148  (void) cls;
149  if (NULL != pch)
150  {
151  /* already done, we've been called twice... */
152  GNUNET_break (0);
153  return;
154  }
155  env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
156  if ((NULL == env_buf) || (strlen (env_buf) <= 0))
157  {
159  "Not installing a handler because $%s is empty\n",
161  putenv (GNUNET_OS_CONTROL_PIPE "=");
162  return;
163  }
164  errno = 0;
165  pipe_fd = strtoull (env_buf, &env_buf_end, 16);
166  if ((0 != errno) || (env_buf == env_buf_end))
167  {
168  LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "strtoull", env_buf);
169  putenv (GNUNET_OS_CONTROL_PIPE "=");
170  return;
171  }
172  if (pipe_fd >= FD_SETSIZE)
173  {
175  "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
176  env_buf);
177  putenv (GNUNET_OS_CONTROL_PIPE "=");
178  return;
179  }
180 
181  control_pipe = GNUNET_DISK_get_handle_from_int_fd ((int) pipe_fd);
182 
183  if (NULL == control_pipe)
184  {
185  LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
186  putenv (GNUNET_OS_CONTROL_PIPE "=");
187  return;
188  }
190  "Adding parent control handler pipe `%s' to the scheduler\n",
191  env_buf);
193  control_pipe,
195  control_pipe);
197  putenv (GNUNET_OS_CONTROL_PIPE "=");
198 }
#define GNUNET_OS_CONTROL_PIPE
Definition: os_priority.c:40
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1300
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1636
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_SCHEDULER_Task * spch
Handle for the shutdown_pch() Task.
Definition: os_priority.c:72
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
char * getenv()
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition: os_priority.c:37
static struct GNUNET_SCHEDULER_Task * pch
Handle for the parent_control_handler() Task.
Definition: os_priority.c:67
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_int_fd(int fno)
Get a handle from a native integer FD.
Definition: disk.c:1375
static void shutdown_pch(void *cls)
This handler is called on shutdown to remove the pch.
Definition: os_priority.c:81
static void parent_control_handler(void *cls)
This handler is called when there are control data to be read on the pipe.
Definition: os_priority.c:98
Handle used to access files (and pipes).
#define LOG(kind,...)
Definition: os_priority.c:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_OS_check_helper_binary()

int GNUNET_OS_check_helper_binary ( const char *  binary,
int  check_suid,
const char *  params 
)

Check whether an executable exists and possibly if the suid bit is set on the file.

Attempts to find the file using the current PATH environment variable as a search path.

Parameters
binarythe name of the file to check. W32: must not have an .exe suffix.
check_suidinput true if the binary should be checked for SUID (*nix) W32: checks if the program has sufficient privileges by executing this binary with the -d flag. -d omits a programs main loop and only executes all privileged operations in an binary.
paramsparameters used for w32 privilege checking (can be NULL for != w32, or when not checking for suid/permissions )
Returns
GNUNET_YES if the file is SUID (*nix) or can be executed with current privileges (W32), GNUNET_NO if not SUID (but binary exists), GNUNET_SYSERR on error (no such binary or not executable)

Attempts to find the file using the current PATH environment variable as a search path.

Parameters
binarythe name of the file to check. W32: must not have an .exe suffix.
check_suidinput true if the binary should be checked for SUID (*nix) W32: checks if the program has sufficient privileges by executing this binary with the -d flag. -d omits a programs main loop and only executes all privileged operations in an binary.
paramsparameters used for w32 privilege checking (can be NULL for != w32 )
Returns
GNUNET_YES if the file is SUID (*nix) or can be executed with current privileges (W32), GNUNET_NO if not SUID (but binary exists), GNUNET_SYSERR on error (no such binary or not executable)

Definition at line 763 of file os_installation.c.

References _, get_path_from_PATH(), GNUNET_asprintf(), GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_strdup, GNUNET_STRINGS_path_is_absolute(), GNUNET_SYSERR, GNUNET_YES, LOG, LOG_STRERROR_FILE, and p.

Referenced by GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_NAT_mini_map_start(), handle_autoconfig_request(), LIBGNUNET_PLUGIN_TRANSPORT_INIT(), restart_nat_server(), run(), start_process(), test_icmp_client(), test_icmp_server(), and test_upnpc().

766 {
767  struct stat statbuf;
768  char *p;
769  char *pf;
770 
771  if ((GNUNET_YES ==
772  GNUNET_STRINGS_path_is_absolute (binary, GNUNET_NO, NULL, NULL)) ||
773  (0 == strncmp (binary, "./", 2)))
774  {
775  p = GNUNET_strdup (binary);
776  }
777  else
778  {
779  p = get_path_from_PATH (binary);
780  if (NULL != p)
781  {
782  GNUNET_asprintf (&pf, "%s/%s", p, binary);
783  GNUNET_free (p);
784  p = pf;
785  }
786  }
787 
788  if (NULL == p)
789  {
791  _ ("Could not find binary `%s' in PATH!\n"),
792  binary);
793  return GNUNET_SYSERR;
794  }
795  if (0 != access (p, X_OK))
796  {
798  GNUNET_free (p);
799  return GNUNET_SYSERR;
800  }
801 
802  if (0 == getuid ())
803  {
804  /* as we run as root, we don't insist on SUID */
805  GNUNET_free (p);
806  return GNUNET_YES;
807  }
808 
809  if (0 != stat (p, &statbuf))
810  {
812  GNUNET_free (p);
813  return GNUNET_SYSERR;
814  }
815  if (check_suid)
816  {
817  (void) params;
818  if ((0 != (statbuf.st_mode & S_ISUID)) && (0 == statbuf.st_uid))
819  {
820  GNUNET_free (p);
821  return GNUNET_YES;
822  }
824  _ ("Binary `%s' exists, but is not SUID\n"),
825  p);
826  /* binary exists, but not SUID */
827  }
828  GNUNET_free (p);
829  return GNUNET_NO;
830 }
int 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&#39;s an URI.
Definition: strings.c:1108
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define LOG(kind,...)
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define LOG_STRERROR_FILE(kind, syscall, filename)
static char * get_path_from_PATH(const char *binary)
Return the actual path to a file found in the current PATH environment variable.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function: