GNUnet 0.21.0
OS library

Low level process routines. More...

Collaboration diagram for OS library:

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 enum GNUNET_GenericReturnValue(* 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 , GNUNET_OS_USE_PIPE_CONTROL = 8
}
 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 (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 (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 (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 (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 (enum GNUNET_OS_InheritStdioFlags 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...
 
enum GNUNET_GenericReturnValue GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
 Retrieve the status of a process. More...
 
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc)
 Wait for a process to terminate. More...
 
enum GNUNET_GenericReturnValue 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...
 
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...
 

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 416 of file gnunet_os_lib.h.

Typedef Documentation

◆ GNUNET_OS_NetworkInterfaceProcessor

typedef enum GNUNET_GenericReturnValue(* 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 574 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.

GNUNET_OS_USE_PIPE_CONTROL 

Should a pipe be used to send signals to the child?

Definition at line 72 of file gnunet_os_lib.h.

73{
78
84
90
96
102
108
113};
@ GNUNET_OS_INHERIT_STD_IN
When this flag is set, the child process will inherit stdin of the parent.
Definition: gnunet_os_lib.h:83
@ GNUNET_OS_INHERIT_STD_ALL
Use this option to have all of the standard streams (stdin, stdout and stderror) be inherited.
@ GNUNET_OS_INHERIT_STD_OUT
When this flag is set, the child process will inherit stdout of the parent.
Definition: gnunet_os_lib.h:89
@ GNUNET_OS_INHERIT_STD_ERR
When this flag is set, the child process will inherit stderr of the parent.
Definition: gnunet_os_lib.h:95
@ GNUNET_OS_INHERIT_STD_NONE
No standard streams should be inherited.
Definition: gnunet_os_lib.h:77
@ 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_USE_PIPE_CONTROL
Should a pipe be used to send signals to the child?

◆ 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 125 of file gnunet_os_lib.h.

126{
131
136
141
146
151
158
163
169
174};
@ 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/)

◆ 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 180 of file gnunet_os_lib.h.

181{
187
192
197
202
207};
@ GNUNET_OS_PROCESS_SIGNALED
The process was killed by a signal.
@ GNUNET_OS_PROCESS_EXITED
The process exited with a return code.
@ GNUNET_OS_PROCESS_UNKNOWN
The process is not known to the OS (or at least not one of our children).
@ GNUNET_OS_PROCESS_STOPPED
The process is paused (but could be resumed).
@ GNUNET_OS_PROCESS_RUNNING
The process is still running.

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 95 of file os_installation.c.

96{
97 return &default_pd;
98}
static const struct GNUNET_OS_ProjectData default_pd
Default project data used for installation path detection for GNUnet (core).

References default_pd.

Referenced by __attribute__(), GNUNET_BLOCK_context_create(), GNUNET_CONFIGURATION_default(), GNUNET_DATACACHE_create(), and init().

Here is the caller graph for this function:

◆ 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 105 of file os_installation.c.

106{
107 if (current_pd != gettextinit)
108 {
110
111 if (NULL != path)
112 bindtextdomain (PACKAGE,
113 path);
114 GNUNET_free (path);
116 }
117 return current_pd;
118}
#define bindtextdomain(Domainname, Dirname)
Definition: gettext.h:58
#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,...
static const struct GNUNET_OS_ProjectData * gettextinit
PD for which gettext has been initialized last.
static const struct GNUNET_OS_ProjectData * current_pd
Which project data do we currently use for installation path detection? Never NULL.

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

Referenced by __attribute__(), format_help(), GNUNET_CADET_open_port(), GNUNET_CONFIGURATION_config_tool_run(), GNUNET_CONFIGURATION_default(), GNUNET_CONFIGURATION_default_filename(), GNUNET_CONFIGURATION_load(), GNUNET_DATACACHE_create(), GNUNET_PLUGIN_load_all_in_context(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_main(), GNUNET_SERVICE_register_(), GNUNET_SERVICE_run_(), return_agpl(), and set_cont().

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.

Definition at line 122 of file os_installation.c.

123{
124 GNUNET_assert (NULL != pd);
125 current_pd = pd;
126 if (pd != gettextinit)
127 {
129
130 if (NULL != path)
131 bindtextdomain (PACKAGE,
132 path);
133 GNUNET_free (path);
134 gettextinit = pd;
135 }
136}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

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

Referenced by __attribute__(), GNUNET_CONFIGURATION_default(), GNUNET_DATACACHE_create(), and GNUNET_PLUGIN_load_all_in_context().

Here is the call graph for this function:
Here is the caller 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 451 of file os_installation.c.

452{
453 size_t n;
454 char *dirname;
455 char *execpath = NULL;
456 char *tmp;
457 char *multiarch;
458 char *libdir;
459 int isbasedir;
460
461 /* if wanted, try to get the current app's bin/ */
462 if (dirkind == GNUNET_OS_IPK_SELF_PREFIX)
463 execpath = os_get_exec_path ();
464
465 /* try to get GNUnet's bin/ or lib/, or if previous was unsuccessful some
466 * guess for the current app */
467 if (NULL == execpath)
468 execpath = os_get_gnunet_path ();
469 if (NULL == execpath)
470 return NULL;
471
472 n = strlen (execpath);
473 if (0 == n)
474 {
475 /* should never happen, but better safe than sorry */
476 GNUNET_free (execpath);
477 return NULL;
478 }
479 /* remove filename itself */
480 while ((n > 1) && (DIR_SEPARATOR == execpath[n - 1]))
481 execpath[--n] = '\0';
482
483 isbasedir = 1;
484 if ((n > 6) && ((0 == strcasecmp (&execpath[n - 6], "/lib32")) ||
485 (0 == strcasecmp (&execpath[n - 6], "/lib64"))))
486 {
487 if ((GNUNET_OS_IPK_LIBDIR != dirkind) &&
488 (GNUNET_OS_IPK_LIBEXECDIR != dirkind))
489 {
490 /* strip '/lib32' or '/lib64' */
491 execpath[n - 6] = '\0';
492 n -= 6;
493 }
494 else
495 isbasedir = 0;
496 }
497 else if ((n > 4) && ((0 == strcasecmp (&execpath[n - 4], "/bin")) ||
498 (0 == strcasecmp (&execpath[n - 4], "/lib"))))
499 {
500 /* strip '/bin' or '/lib' */
501 execpath[n - 4] = '\0';
502 n -= 4;
503 }
504 multiarch = NULL;
505 if (NULL != (libdir = strstr (execpath, "/lib/")))
506 {
507 /* test for multi-arch path of the form "PREFIX/lib/MULTIARCH/";
508 here we need to re-add 'multiarch' to lib and libexec paths later! */
509 multiarch = &libdir[5];
510 if (NULL == strchr (multiarch, '/'))
511 libdir[0] =
512 '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */
513 else
514 multiarch =
515 NULL; /* maybe not, multiarch still has a '/', which is not OK */
516 }
517 /* in case this was a directory named foo-bin, remove "foo-" */
518 while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR))
519 execpath[--n] = '\0';
520 switch (dirkind)
521 {
525 break;
526
529 break;
530
532 if (isbasedir)
533 {
534 GNUNET_asprintf (&tmp,
535 "%s%s%s%s%s%s%s",
536 execpath,
537 DIR_SEPARATOR_STR "lib",
538 (NULL != multiarch) ? DIR_SEPARATOR_STR : "",
539 (NULL != multiarch) ? multiarch : "",
544 {
545 GNUNET_free (execpath);
546 return tmp;
547 }
548 GNUNET_free (tmp);
549 tmp = NULL;
550 dirname = NULL;
551 if (4 == sizeof(void *))
552 {
553 GNUNET_asprintf (&dirname,
557 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
558 }
559 if (8 == sizeof(void *))
560 {
561 GNUNET_asprintf (&dirname,
565 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
566 }
567
568 if ((NULL != tmp) &&
570 {
571 GNUNET_free (execpath);
572 GNUNET_free (dirname);
573 return tmp;
574 }
575 GNUNET_free (tmp);
576 GNUNET_free (dirname);
577 }
578 GNUNET_asprintf (&dirname,
581 break;
582
584 GNUNET_asprintf (&dirname,
588 break;
589
592 "locale" DIR_SEPARATOR_STR);
593 break;
594
597 "icons" DIR_SEPARATOR_STR);
598 break;
599
601 GNUNET_asprintf (&dirname,
606 break;
607
609 if (isbasedir)
610 {
611 GNUNET_asprintf (&dirname,
613 "libexec" DIR_SEPARATOR_STR,
615 GNUNET_asprintf (&tmp,
616 "%s%s%s%s",
617 execpath,
619 (NULL != multiarch) ? multiarch : "",
620 dirname);
621 GNUNET_free (dirname);
623 {
624 GNUNET_free (execpath);
625 return tmp;
626 }
627 GNUNET_free (tmp);
628 tmp = NULL;
629 dirname = NULL;
630 if (4 == sizeof(void *))
631 {
632 GNUNET_asprintf (&dirname,
635 "libexec" DIR_SEPARATOR_STR,
637 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
638 }
639 if (8 == sizeof(void *))
640 {
641 GNUNET_asprintf (&dirname,
644 "libexec" DIR_SEPARATOR_STR,
646 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
647 }
648 if ((NULL != tmp) &&
650 {
651 GNUNET_free (execpath);
652 GNUNET_free (dirname);
653 return tmp;
654 }
655 GNUNET_free (tmp);
656 GNUNET_free (dirname);
657 }
658 GNUNET_asprintf (&dirname,
660 "libexec" DIR_SEPARATOR_STR,
662 break;
663
664 default:
665 GNUNET_free (execpath);
666 return NULL;
667 }
668 GNUNET_asprintf (&tmp, "%s%s", execpath, dirname);
669 GNUNET_free (dirname);
670 GNUNET_free (execpath);
671 return tmp;
672}
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:403
@ GNUNET_YES
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static char * os_get_gnunet_path(void)
get the path to GNUnet bin/ or lib/, preferring the lib/ path
static char * os_get_exec_path()
get the path to current app's bin/
#define DIR_SEPARATOR
Definition: platform.h:165
#define DIR_SEPARATOR_STR
Definition: platform.h:166
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".

References current_pd, DIR_SEPARATOR, DIR_SEPARATOR_STR, GNUNET_asprintf(), GNUNET_DISK_directory_test(), GNUNET_free, 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 exec_bash_script_run(), GNUNET_CONFIGURATION_create(), 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(), netjail_start_run(), netjail_stop_run(), plugin_init(), run(), and start_helper().

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 684 of file os_installation.c.

685{
686 static char *cache;
687 char *libexecdir;
688 char *binary;
689
690 if ((DIR_SEPARATOR == progname[0]) ||
691 (GNUNET_YES ==
692 GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL)))
693 return GNUNET_strdup (progname);
694 if (NULL != cache)
695 libexecdir = cache;
696 else
698 if (NULL == libexecdir)
699 return GNUNET_strdup (progname);
700 GNUNET_asprintf (&binary, "%s%s", libexecdir, progname);
701 cache = libexecdir;
702 return binary;
703}
@ GNUNET_NO
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.
Definition: strings.c:958

References 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_TESTING_peer_configure(), GNUNET_TESTING_service_run(), nat_start(), peerstore_start(), resolver_start(), start_arm_service(), start_helper(), start_process(), start_shared_service_instance(), statistics_start(), test_icmp_client(), test_icmp_server(), and tokenizer_cb().

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 719 of file os_installation.c.

721{
722 static char *cache;
723 char *binary = NULL;
724 char *path = NULL;
725 size_t path_len;
726
727 if (GNUNET_YES ==
728 GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL))
729 {
730 return GNUNET_strdup (progname);
731 }
732 if (NULL != cache)
733 path = cache;
734 else
736 "PATHS",
737 "SUID_BINARY_PATH",
738 &path);
739 if ((NULL == path) || (0 == strlen (path)))
740 {
741 if (NULL != path)
742 GNUNET_free (path);
743 cache = NULL;
744 return GNUNET_OS_get_libexec_binary_path (progname);
745 }
746 path_len = strlen (path);
747 GNUNET_asprintf (&binary,
748 "%s%s%s",
749 path,
750 (path[path_len - 1] == DIR_SEPARATOR) ? ""
752 progname);
753 cache = path;
754 return binary;
755}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
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.
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 ...

References cfg, DIR_SEPARATOR, DIR_SEPARATOR_STR, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_free, 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().

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 397 of file os_network.c.

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

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(), run_scan(), scan(), and test_local_ip().

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 202 of file os_priority.c.

203{
205 return &current_process;
206}
static struct GNUNET_OS_Process current_process
Handle for 'this' process.
Definition: os_priority.c:62
pid_t pid
PID of the process.
Definition: os_priority.c:49

References current_process, and GNUNET_OS_Process::pid.

◆ 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 210 of file os_priority.c.

212{
213 int ret;
214 char csig;
215
216 csig = (char) sig;
217 if (NULL != proc->control_pipe)
218 {
220 "Sending signal %d to pid: %u via pipe\n",
221 sig,
222 proc->pid);
223 ret = GNUNET_DISK_file_write (proc->control_pipe, &csig, sizeof(csig));
224 if (sizeof(csig) == ret)
225 return 0;
226 }
227 /* pipe failed or non-existent, try other methods */
228 switch (sig)
229 {
230 case SIGHUP:
231 case SIGINT:
232 case SIGKILL:
233 case SIGTERM:
234#if (SIGTERM != GNUNET_TERM_SIG)
235 case GNUNET_TERM_SIG:
236#endif
238 "Sending signal %d to pid: %u via system call\n",
239 sig,
240 proc->pid);
241 return kill (proc->pid, sig);
242 default:
244 "Sending signal %d to pid: %u via system call\n",
245 sig,
246 proc->pid);
247 return kill (proc->pid, sig);
248 }
249}
static int ret
Final status code.
Definition: gnunet-arm.c:94
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:686
@ GNUNET_ERROR_TYPE_DEBUG
#define LOG(kind,...)
Definition: os_priority.c:33
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:234
struct GNUNET_DISK_FileHandle * control_pipe
Pipe we use to signal the process.
Definition: os_priority.c:55

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(), exec_bash_script_cleanup(), GN_stop_gnunet_nat_server_(), GNUNET_HELPER_kill(), GNUNET_NAT_mini_get_external_ipv4_cancel_(), GNUNET_OS_command_stop(), GNUNET_PQ_exec_sql(), GNUNET_TESTING_peer_kill(), handle_stop(), maint_child_death(), nat_server_read(), netjail_start_cleanup(), netjail_stop_cleanup(), shutdown_process(), shutdown_program(), shutdown_task(), and stop_shared_service_instance().

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 260 of file os_priority.c.

261{
262 if (NULL != proc->control_pipe)
264
265 GNUNET_free (proc);
266}
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308

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

Referenced by child_completed_callback(), exec_bash_script_cleanup(), GN_request_connection_reversal(), GN_stop_gnunet_nat_server_(), GNUNET_HELPER_wait(), GNUNET_NAT_mini_get_external_ipv4_cancel_(), GNUNET_OS_command_stop(), GNUNET_PQ_exec_sql(), GNUNET_TESTING_peer_wait(), maint_child_death(), nat_server_read(), netjail_start_cleanup(), netjail_stop_cleanup(), shutdown_process(), start_arm_service(), stop_shared_service_instance(), and wait_child().

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 253 of file os_priority.c.

254{
255 return proc->pid;
256}

References GNUNET_OS_Process::pid.

Referenced by maint_child_death().

Here is the caller graph for this function:

◆ GNUNET_OS_start_process_vap()

struct GNUNET_OS_Process * GNUNET_OS_start_process_vap ( 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
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

Definition at line 573 of file os_priority.c.

579{
580 return start_process (std_inheritance,
581 pipe_stdin,
582 pipe_stdout,
583 pipe_stderr,
584 NULL,
585 filename,
586 argv);
587}
static char * filename
static struct GNUNET_OS_Process * start_process(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:317

References filename, and start_process().

Referenced by exec_bash_script_run(), GNUNET_OS_start_process_va(), handle_uri(), netjail_start_run(), netjail_stop_run(), start_helper(), and work().

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 ( 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
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

Definition at line 626 of file os_priority.c.

632{
633 struct GNUNET_OS_Process *ret;
634 va_list ap;
635
636 va_start (ap, filename);
637 ret = GNUNET_OS_start_process_va (std_inheritance,
638 pipe_stdin,
639 pipe_stdout,
640 pipe_stderr,
641 filename,
642 ap);
643 va_end (ap);
644 return ret;
645}
struct GNUNET_OS_Process * GNUNET_OS_start_process_va(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:591

References filename, GNUNET_OS_start_process_va(), and ret.

Referenced by GN_request_connection_reversal(), GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_PQ_exec_sql(), nat_start(), peerstore_start(), resolver_start(), restart_nat_server(), run(), start_shared_service_instance(), and statistics_start().

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 ( 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
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

Definition at line 591 of file os_priority.c.

597{
598 struct GNUNET_OS_Process *ret;
599 va_list ap;
600 char **argv;
601 int argc;
602
603 argc = 0;
604 va_copy (ap, va);
605 while (NULL != va_arg (ap, char *))
606 argc++;
607 va_end (ap);
608 argv = GNUNET_malloc (sizeof(char *) * (argc + 1));
609 argc = 0;
610 va_copy (ap, va);
611 while (NULL != (argv[argc] = va_arg (ap, char *)))
612 argc++;
613 va_end (ap);
614 ret = GNUNET_OS_start_process_vap (std_inheritance,
615 pipe_stdin,
616 pipe_stdout,
617 pipe_stderr,
618 filename,
619 argv);
620 GNUNET_free (argv);
621 return ret;
622}
#define GNUNET_malloc(size)
Wrapper around malloc.
struct GNUNET_OS_Process * GNUNET_OS_start_process_vap(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:573

References filename, 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().

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 ( enum GNUNET_OS_InheritStdioFlags  std_inheritance,
const int *  lsocks,
const char *  filename,
char *const  argv[] 
)

Start a process.

Parameters
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

Definition at line 649 of file os_priority.c.

653{
654 return start_process (std_inheritance,
655 NULL,
656 NULL,
657 NULL,
658 lsocks,
659 filename,
660 argv);
661}

References filename, and start_process().

Referenced by GNUNET_OS_start_process_s().

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 ( enum GNUNET_OS_InheritStdioFlags  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
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 665 of file os_priority.c.

669{
670 va_list ap;
671 char **argv;
672 unsigned int argv_size;
673 const char *arg;
674 const char *rpos;
675 char *pos;
676 char *cp;
677 const char *last;
678 struct GNUNET_OS_Process *proc;
679 char *binary_path;
680 int quote_on;
681 unsigned int i;
682 size_t len;
683
684 argv_size = 1;
685 va_start (ap, filename);
686 arg = filename;
687 last = NULL;
688 do
689 {
690 rpos = arg;
691 quote_on = 0;
692 while ('\0' != *rpos)
693 {
694 if ('"' == *rpos)
695 {
696 if (1 == quote_on)
697 quote_on = 0;
698 else
699 quote_on = 1;
700 }
701 if ((' ' == *rpos) && (0 == quote_on))
702 {
703 if (NULL != last)
704 argv_size++;
705 last = NULL;
706 rpos++;
707 while (' ' == *rpos)
708 rpos++;
709 }
710 if ((NULL == last) && ('\0' != *rpos)) // FIXME: == or !=?
711 last = rpos;
712 if ('\0' != *rpos)
713 rpos++;
714 }
715 if (NULL != last)
716 argv_size++;
717 }
718 while (NULL != (arg = (va_arg (ap, const char *))));
719 va_end (ap);
720
721 argv = GNUNET_malloc (argv_size * sizeof(char *));
722 argv_size = 0;
723 va_start (ap, filename);
724 arg = filename;
725 last = NULL;
726 do
727 {
728 cp = GNUNET_strdup (arg);
729 quote_on = 0;
730 pos = cp;
731 while ('\0' != *pos)
732 {
733 if ('"' == *pos)
734 {
735 if (1 == quote_on)
736 quote_on = 0;
737 else
738 quote_on = 1;
739 }
740 if ((' ' == *pos) && (0 == quote_on))
741 {
742 *pos = '\0';
743 if (NULL != last)
744 argv[argv_size++] = GNUNET_strdup (last);
745 last = NULL;
746 pos++;
747 while (' ' == *pos)
748 pos++;
749 }
750 if ((NULL == last) && ('\0' != *pos)) // FIXME: == or !=?
751 last = pos;
752 if ('\0' != *pos)
753 pos++;
754 }
755 if (NULL != last)
756 argv[argv_size++] = GNUNET_strdup (last);
757 last = NULL;
758 GNUNET_free (cp);
759 }
760 while (NULL != (arg = (va_arg (ap, const char *))));
761 va_end (ap);
762 argv[argv_size] = NULL;
763
764 for (i = 0; i < argv_size; i++)
765 {
766 len = strlen (argv[i]);
767 if ((argv[i][0] == '"') && (argv[i][len - 1] == '"'))
768 {
769 memmove (&argv[i][0], &argv[i][1], len - 2);
770 argv[i][len - 2] = '\0';
771 }
772 }
773 binary_path = argv[0];
774 proc = GNUNET_OS_start_process_v (std_inheritance,
775 lsocks,
776 binary_path,
777 argv);
778 while (argv_size > 0)
779 GNUNET_free_nz (argv[--argv_size]);
780 GNUNET_free (argv);
781 return proc;
782}
#define GNUNET_free_nz(ptr)
Wrapper around free.
struct GNUNET_OS_Process * GNUNET_OS_start_process_v(enum GNUNET_OS_InheritStdioFlags std_inheritance, const int *lsocks, const char *filename, char *const argv[])
Start a process.
Definition: os_priority.c:649

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

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

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

Definition at line 947 of file os_priority.c.

948{
949 if (NULL != cmd->proc)
950 {
951 GNUNET_assert (NULL != cmd->rtask);
953 }
954 (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL);
958 GNUNET_free (cmd);
959}
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1587
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:260
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:210
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:877
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
struct GNUNET_DISK_PipeHandle * opipe
Handle to the output pipe.
Definition: os_priority.c:907
struct GNUNET_OS_Process * eip
Process handle.
Definition: os_priority.c:902
struct GNUNET_SCHEDULER_Task * rtask
Task reading from pipe.
Definition: os_priority.c:932
GNUNET_OS_LineProcessor proc
Function to call on each line of output.
Definition: os_priority.c:917

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().

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

Definition at line 1021 of file os_priority.c.

1026{
1027 struct GNUNET_OS_CommandHandle *cmd;
1028 struct GNUNET_OS_Process *eip;
1029 struct GNUNET_DISK_PipeHandle *opipe;
1030 va_list ap;
1031
1033 if (NULL == opipe)
1034 return NULL;
1035 va_start (ap, binary);
1036 /* redirect stdout, don't inherit stderr/stdin */
1037 eip =
1039 NULL,
1040 opipe,
1041 NULL,
1042 binary,
1043 ap);
1044 va_end (ap);
1045 if (NULL == eip)
1046 {
1047 GNUNET_DISK_pipe_close (opipe);
1048 return NULL;
1049 }
1051 cmd = GNUNET_new (struct GNUNET_OS_CommandHandle);
1053 cmd->eip = eip;
1054 cmd->opipe = opipe;
1055 cmd->proc = proc;
1056 cmd->proc_cls = proc_cls;
1059 return cmd;
1060}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:119
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:1617
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition: disk.c:1444
enum GNUNET_GenericReturnValue 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:1534
@ GNUNET_DISK_PF_BLOCKING_RW
Configure both pipe ends for blocking operations if set.
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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:1656
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:316
static void cmd_read(void *cls)
Read from the process and call the line processor.
Definition: os_priority.c:968
Handle used to manage a pipe.
Definition: disk.c:68
Handle to a command.
Definition: os_priority.c:898
struct GNUNET_TIME_Absolute timeout
When to time out.
Definition: os_priority.c:937
void * proc_cls
Closure for proc.
Definition: os_priority.c:922
const struct GNUNET_DISK_FileHandle * r
Read-end of output pipe.
Definition: os_priority.c:912

References cmd_read(), GNUNET_OS_CommandHandle::eip, GNUNET_DISK_PF_BLOCKING_RW, 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_OS_INHERIT_STD_NONE, GNUNET_OS_start_process_va(), GNUNET_SCHEDULER_add_read_file(), GNUNET_TIME_relative_to_absolute(), GNUNET_OS_CommandHandle::opipe, GNUNET_OS_CommandHandle::proc, GNUNET_OS_CommandHandle::proc_cls, GNUNET_OS_CommandHandle::r, GNUNET_OS_CommandHandle::rtask, timeout, and GNUNET_OS_CommandHandle::timeout.

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

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

◆ GNUNET_OS_process_status()

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

Retrieve the status of a process.

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

Definition at line 859 of file os_priority.c.

862{
863 return process_status (proc, type, code, WNOHANG);
864}
static uint32_t type
Type string converted to DNS type value.
static enum GNUNET_GenericReturnValue 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:796

References process_status(), and type.

Referenced by maint_child_death(), and run_process_and_wait().

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

◆ GNUNET_OS_process_wait()

enum GNUNET_GenericReturnValue 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

Definition at line 877 of file os_priority.c.

878{
879 pid_t pid = proc->pid;
880 pid_t ret;
881
882 while ((pid != (ret = waitpid (pid, NULL, 0))) && (EINTR == errno))
883 ;
884 if (pid != ret)
885 {
887 "waitpid");
888 return GNUNET_SYSERR;
889 }
890 return GNUNET_OK;
891}
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
@ GNUNET_SYSERR
#define LOG_STRERROR(kind, syscall)
Definition: os_priority.c:35

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

Referenced by exec_bash_script_cleanup(), GN_request_connection_reversal(), GN_stop_gnunet_nat_server_(), GNUNET_HELPER_wait(), GNUNET_NAT_mini_get_external_ipv4_cancel_(), GNUNET_OS_command_stop(), GNUNET_TESTING_peer_wait(), nat_server_read(), netjail_start_cleanup(), netjail_stop_cleanup(), run_process_and_wait(), shutdown_process(), and stop_shared_service_instance().

Here is the caller graph for this function:

◆ GNUNET_OS_process_wait_status()

enum GNUNET_GenericReturnValue 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 868 of file os_priority.c.

871{
872 return process_status (proc, type, code, 0);
873}

References process_status(), and type.

Referenced by GNUNET_PQ_exec_sql().

Here is the call graph for this function:
Here is the caller 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)

Definition at line 133 of file os_priority.c.

134{
135 const char *env_buf;
136 char *env_buf_end;
137 struct GNUNET_DISK_FileHandle *control_pipe;
138 uint64_t pipe_fd;
139
140 (void) cls;
141 if (NULL != pch)
142 {
143 /* already done, we've been called twice... */
144 GNUNET_break (0);
145 return;
146 }
147 env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
148 if ((NULL == env_buf) || (strlen (env_buf) <= 0))
149 {
151 "Not installing a handler because $%s is empty\n",
153 putenv (GNUNET_OS_CONTROL_PIPE "=");
154 return;
155 }
156 errno = 0;
157 pipe_fd = strtoull (env_buf, &env_buf_end, 16);
158 if ((0 != errno) || (env_buf == env_buf_end))
159 {
160 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "strtoull", env_buf);
161 putenv (GNUNET_OS_CONTROL_PIPE "=");
162 return;
163 }
164 if (pipe_fd >= FD_SETSIZE)
165 {
167 "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
168 env_buf);
169 putenv (GNUNET_OS_CONTROL_PIPE "=");
170 return;
171 }
172
173 control_pipe = GNUNET_DISK_get_handle_from_int_fd ((int) pipe_fd);
174
175 if (NULL == control_pipe)
176 {
178 putenv (GNUNET_OS_CONTROL_PIPE "=");
179 return;
180 }
182 "Adding parent control handler pipe `%s' to the scheduler\n",
183 env_buf);
185 control_pipe,
187 control_pipe);
189 putenv (GNUNET_OS_CONTROL_PIPE "=");
190}
char * getenv()
struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_int_fd(int fno)
Get a handle from a native integer FD.
Definition: disk.c:1330
@ GNUNET_ERROR_TYPE_ERROR
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,...
Definition: scheduler.c:1334
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_OS_CONTROL_PIPE
Definition: os_priority.c:41
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
static struct GNUNET_SCHEDULER_Task * pch
Handle for the parent_control_handler() Task.
Definition: os_priority.c:67
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition: os_priority.c:38
static void shutdown_pch(void *cls)
This handler is called on shutdown to remove the pch.
Definition: os_priority.c:81
static struct GNUNET_SCHEDULER_Task * spch
Handle for the shutdown_pch() Task.
Definition: os_priority.c:72
Handle used to access files (and pipes).

References 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(), pch, shutdown_pch(), and spch.

Referenced by install_parent_control_handler().

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

◆ GNUNET_OS_check_helper_binary()

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.

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)

Definition at line 759 of file os_installation.c.

762{
763 struct stat statbuf;
764 char *p;
765 char *pf;
766
767 if ((GNUNET_YES ==
768 GNUNET_STRINGS_path_is_absolute (binary, GNUNET_NO, NULL, NULL)) ||
769 (0 == strncmp (binary, "./", 2)))
770 {
771 p = GNUNET_strdup (binary);
772 }
773 else
774 {
775 p = get_path_from_PATH (binary);
776 if (NULL != p)
777 {
778 GNUNET_asprintf (&pf, "%s/%s", p, binary);
779 GNUNET_free (p);
780 p = pf;
781 }
782 }
783
784 if (NULL == p)
785 {
787 _ ("Could not find binary `%s' in PATH!\n"),
788 binary);
789 return GNUNET_SYSERR;
790 }
791 if (0 != access (p, X_OK))
792 {
794 GNUNET_free (p);
795 return GNUNET_SYSERR;
796 }
797
798 if (0 == getuid ())
799 {
800 /* as we run as root, we don't insist on SUID */
801 GNUNET_free (p);
802 return GNUNET_YES;
803 }
804
805 if (0 != stat (p, &statbuf))
806 {
808 GNUNET_free (p);
809 return GNUNET_SYSERR;
810 }
811 if (check_suid)
812 {
813 (void) params;
814 if ((0 != (statbuf.st_mode & S_ISUID)) && (0 == statbuf.st_uid))
815 {
816 GNUNET_free (p);
817 return GNUNET_YES;
818 }
820 _ ("Binary `%s' exists, but is not SUID\n"),
821 p);
822 /* binary exists, but not SUID */
823 }
824 GNUNET_free (p);
825 return GNUNET_NO;
826}
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_INFO
#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 LOG(kind,...)
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

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 exec_bash_script_run(), GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_NAT_mini_map_start(), handle_autoconfig_request(), netjail_start_run(), netjail_stop_run(), restart_nat_server(), run(), start_helper(), start_process(), test_icmp_client(), test_icmp_server(), and test_upnpc().

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