GNUnet 0.27.0
 
Loading...
Searching...
No Matches
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...
 
struct  GNUNET_ProcessOptionValue
 Possible options we can set for a process. More...
 

Macros

#define GNUNET_OS_get_hostname_max_length()   255
 Get maximum string length returned by gethostname()
 
#define GNUNET_PROCESS_OPTIONS_ARRAY_MAX_SIZE   32
 Maximum number of process options we can set in one pass.
 
#define GNUNET_process_option_end_()
 Terminate the list of the options.
 
#define GNUNET_process_option_set_environment(k, v)
 Set environment variable in child process.
 
#define GNUNET_process_option_inherit_fd(p, c)
 Have child process inherit a file descriptor.
 
#define GNUNET_process_option_inherit_rpipe(rpipe, child_fd)
 Have child process inherit a pipe for reading.
 
#define GNUNET_process_option_inherit_wpipe(wpipe, child_fd)
 Have child process inherit a pipe for writing.
 
#define GNUNET_process_option_inherit_lsock(lsock)
 Pass listen socket to child systemd-style.
 
#define GNUNET_process_set_options(proc, ...)
 Set the requested options for the process.
 

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.
 
typedef void(* GNUNET_OS_LineProcessor) (void *cls, const char *line)
 Type of a function to process a line of output.
 

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...
 
enum  GNUNET_ProcessOption { GNUNET_PROCESS_OPTION_END = 0 , GNUNET_PROCESS_OPTION_SET_ENVIRONMENT = 1 , GNUNET_PROCESS_OPTION_INHERIT_FD = 2 , GNUNET_PROCESS_OPTION_INHERIT_LSOCK = 3 }
 Possible options we can set for a process. More...
 

Functions

const struct GNUNET_OS_ProjectDataGNUNET_OS_project_data_gnunet (void)
 Return default project data used by 'libgnunetutil' for GNUnet.
 
void GNUNET_OS_init (const char *package_name, const struct GNUNET_OS_ProjectData *pd)
 Setup OS subsystem for the given project data and package.
 
char * GNUNET_OS_installation_get_path (const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
 Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation directory.
 
char * GNUNET_OS_get_libexec_binary_path (const struct GNUNET_OS_ProjectData *pd, const char *progname)
 Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the libexec/-directory to get the full path.
 
char * GNUNET_OS_get_suid_binary_path (const struct GNUNET_OS_ProjectData *pd, const struct GNUNET_CONFIGURATION_Handle *cfg, const char *progname)
 Given the name of a helper, service or daemon binary construct the full path to the binary using the SUID_BINARY_PATH in the PATHS section of the configuration.
 
void GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
 Enumerate all network interfaces.
 
void GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd)
 Stop/kill a command.
 
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.
 
struct GNUNET_ProcessGNUNET_process_create (enum GNUNET_OS_InheritStdioFlags std_inheritance)
 Create a process handle.
 
enum GNUNET_GenericReturnValue GNUNET_process_run_command_ap (struct GNUNET_Process *p, const char *filename, va_list va)
 Set the command and start a process.
 
enum GNUNET_GenericReturnValue GNUNET_process_run_command_argv (struct GNUNET_Process *p, const char *filename, const char **argv)
 Set the command and start a process.
 
enum GNUNET_GenericReturnValue GNUNET_process_run_command_va (struct GNUNET_Process *p, const char *filename,...)
 Set the command and start a process.
 
enum GNUNET_GenericReturnValue GNUNET_process_run_command (struct GNUNET_Process *p, const char *command)
 Set the command and start a process.
 
enum GNUNET_GenericReturnValue GNUNET_process_set_options_ (struct GNUNET_Process *proc, unsigned int num_options, const struct GNUNET_ProcessOptionValue options[])
 Set the requested options for the process.
 
enum GNUNET_GenericReturnValue GNUNET_process_wait (struct GNUNET_Process *proc, bool blocking, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
 Wait for a process to terminate.
 
void GNUNET_process_destroy (struct GNUNET_Process *proc)
 Cleans up process structure contents (OS-dependent) and deallocates it.
 
pid_t GNUNET_process_get_pid (const struct GNUNET_Process *proc)
 Get the pid of the process in question.
 
enum GNUNET_GenericReturnValue GNUNET_process_kill (struct GNUNET_Process *proc, int sig)
 Sends a signal to the process.
 
struct GNUNET_ProcessGNUNET_process_current (void)
 Get process structure for current process.
 
void GNUNET_process_install_parent_control_handler (void)
 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.
 
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.
 
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.
 

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

◆ GNUNET_PROCESS_OPTIONS_ARRAY_MAX_SIZE

#define GNUNET_PROCESS_OPTIONS_ARRAY_MAX_SIZE   32

Maximum number of process options we can set in one pass.

Definition at line 588 of file gnunet_os_lib.h.

◆ GNUNET_process_option_end_

#define GNUNET_process_option_end_ ( )
Value:
(const struct GNUNET_ProcessOptionValue) \
{ \
}
@ GNUNET_PROCESS_OPTION_END
End of list of options.
Possible options we can set for a process.

Terminate the list of the options.

Returns
the terminating object of struct GNUNET_ProcessOptionValue

Definition at line 659 of file gnunet_os_lib.h.

661 { \
662 .option = GNUNET_PROCESS_OPTION_END \
663 }

◆ GNUNET_process_option_set_environment

#define GNUNET_process_option_set_environment (   k,
 
)
Value:
(const struct GNUNET_ProcessOptionValue) \
{ \
.details.set_environment.key = k, \
.details.set_environment.value = v \
}
@ GNUNET_PROCESS_OPTION_SET_ENVIRONMENT
Option to set environment variables.

Set environment variable in child process.

Parameters
kname of the variable
vvalue to set, NULL to clear
Returns
the option

Definition at line 672 of file gnunet_os_lib.h.

674 { \
676 .details.set_environment.key = k, \
677 .details.set_environment.value = v \
678 }

◆ GNUNET_process_option_inherit_fd

#define GNUNET_process_option_inherit_fd (   p,
 
)
Value:
(const struct GNUNET_ProcessOptionValue) \
{ \
.details.inherit_fd.target_fd = c, \
.details.inherit_fd.parent_fd = p \
}
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38
@ GNUNET_PROCESS_OPTION_INHERIT_FD
Option to inherit file descriptors.

Have child process inherit a file descriptor.

The ownership over the file descriptor is afterwards with the process handle.

Parameters
popen file descriptor in this process
ctarget file descriptor in the child process
Returns
the terminating object of struct GNUNET_ProcessOptionValue

Definition at line 689 of file gnunet_os_lib.h.

691 { \
693 .details.inherit_fd.target_fd = c, \
694 .details.inherit_fd.parent_fd = p \
695 }

◆ GNUNET_process_option_inherit_rpipe

#define GNUNET_process_option_inherit_rpipe (   rpipe,
  child_fd 
)
Value:
(const struct GNUNET_ProcessOptionValue) \
{ \
.details.inherit_fd.target_fd = child_fd, \
.details.inherit_fd.parent_fd \
}
struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_detach_end(struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end)
Detaches one of the ends from the pipe.
Definition disk.c:1644
int GNUNET_DISK_internal_file_handle(const struct GNUNET_DISK_FileHandle *fh)
Retrieve OS file handle.
Definition disk.c:1731
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.

Have child process inherit a pipe for reading.

The read-end is detached from the pipe.

Parameters
rpipeopen pipe in this process the child should read from
child_fdtarget file descriptor in the child process
Returns
the terminating object of struct GNUNET_ProcessOptionValue

Definition at line 705 of file gnunet_os_lib.h.

707 { \
709 .details.inherit_fd.target_fd = child_fd, \
710 .details.inherit_fd.parent_fd \
714 }

◆ GNUNET_process_option_inherit_wpipe

#define GNUNET_process_option_inherit_wpipe (   wpipe,
  child_fd 
)
Value:
(const struct GNUNET_ProcessOptionValue) \
{ \
.details.inherit_fd.target_fd = child_fd, \
.details.inherit_fd.parent_fd \
}
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.

Have child process inherit a pipe for writing.

The write-end is detached from the pipe.

Parameters
wpipeopen pipe in this process the child should write to
child_fdtarget file descriptor in the child process
Returns
the terminating object of struct GNUNET_ProcessOptionValue

Definition at line 724 of file gnunet_os_lib.h.

726 { \
728 .details.inherit_fd.target_fd = child_fd, \
729 .details.inherit_fd.parent_fd \
733 }

◆ GNUNET_process_option_inherit_lsock

#define GNUNET_process_option_inherit_lsock (   lsock)
Value:
(const struct GNUNET_ProcessOptionValue) \
{ \
.details.inherit_lsock = lsock \
}
@ GNUNET_PROCESS_OPTION_INHERIT_LSOCK
Option to inherit a listen socket systemd-style.

Pass listen socket to child systemd-style.

The ownership over the file descriptor remains with the caller!

Parameters
lsockopen listen socket to pass to the child
Returns
the option

Definition at line 743 of file gnunet_os_lib.h.

745 { \
747 .details.inherit_lsock = lsock \
748 }

◆ GNUNET_process_set_options

#define GNUNET_process_set_options (   proc,
  ... 
)
Value:
proc, \
((const struct GNUNET_ProcessOptionValue[]) \
{__VA_ARGS__, GNUNET_process_option_end_ () } \
))
enum GNUNET_GenericReturnValue GNUNET_process_set_options_(struct GNUNET_Process *proc, unsigned int num_options, const struct GNUNET_ProcessOptionValue options[])
Set the requested options for the process.
#define GNUNET_process_option_end_()
Terminate the list of the options.
#define GNUNET_PROCESS_OPTIONS_ARRAY_MAX_SIZE
Maximum number of process options we can set in one pass.

Set the requested options for the process.

If any option fail other options may be or may be not applied.

It should be used with helpers that creates required options, for example:

GNUNET_process_set_options ( proc, GNUNET_process_option_std_inheritance_(si));

Parameters
procthe process to set the options for
...the list of the options, each option must be created by helpers GNUNET_process_option_NAME(VALUE)
Returns
GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR on internal error

Definition at line 789 of file gnunet_os_lib.h.

794 {__VA_ARGS__, GNUNET_process_option_end_ () } \
795 ))

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 367 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 434 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 74 of file gnunet_os_lib.h.

75{
80
86
92
98
104
110
115};
@ GNUNET_OS_INHERIT_STD_IN
When this flag is set, the child process will inherit stdin 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_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_NONE
No standard streams should be inherited.
@ 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 121 of file gnunet_os_lib.h.

122{
127
132
137
142
147
154
159
165
170};
@ 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 176 of file gnunet_os_lib.h.

177{
183
188
193
198
203};
@ 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.

◆ GNUNET_ProcessOption

Possible options we can set for a process.

Enumerator
GNUNET_PROCESS_OPTION_END 

End of list of options.

GNUNET_PROCESS_OPTION_SET_ENVIRONMENT 

Option to set environment variables.

GNUNET_PROCESS_OPTION_INHERIT_FD 

Option to inherit file descriptors.

GNUNET_PROCESS_OPTION_INHERIT_LSOCK 

Option to inherit a listen socket systemd-style.

Definition at line 561 of file gnunet_os_lib.h.

Function Documentation

◆ GNUNET_OS_project_data_gnunet()

const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet ( void  )

◆ GNUNET_OS_init()

void GNUNET_OS_init ( const char *  package_name,
const struct GNUNET_OS_ProjectData pd 
)

Setup OS subsystem for the given project data and package.

Initializes GNU Gettext.

Parameters
package_namename of the package for GNU gettext
pdproject data to use to determine paths

Definition at line 89 of file os_installation.c.

91{
92 char *path;
93
96 if (NULL != path)
97 bindtextdomain (package_name,
98 path);
99 GNUNET_free (path);
100}
#define bindtextdomain(Domainname, Dirname)
Definition gettext.h:62
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...

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

Here is the call graph for this function:

◆ GNUNET_OS_installation_get_path()

char * GNUNET_OS_installation_get_path ( const struct GNUNET_OS_ProjectData pd,
enum GNUNET_OS_InstallationPathKind  dirkind 
)

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

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

Definition at line 434 of file os_installation.c.

436{
437 size_t n;
438 char *dirname;
439 char *execpath = NULL;
440 char *tmp;
441 char *multiarch;
442 char *libdir;
443 int isbasedir;
444
445 /* if wanted, try to get the current app's bin/ */
446 if (dirkind == GNUNET_OS_IPK_SELF_PREFIX)
447 execpath = os_get_exec_path (pd);
448
449 /* try to get GNUnet's bin/ or lib/, or if previous was unsuccessful some
450 * guess for the current app */
451 if (NULL == execpath)
452 execpath = os_get_gnunet_path (pd);
453 if (NULL == execpath)
454 return NULL;
455
456 n = strlen (execpath);
457 if (0 == n)
458 {
459 /* should never happen, but better safe than sorry */
460 GNUNET_free (execpath);
461 return NULL;
462 }
463 /* remove filename itself */
464 while ((n > 1) && (DIR_SEPARATOR == execpath[n - 1]))
465 execpath[--n] = '\0';
466
467 isbasedir = 1;
468 if ((n > 6) && ((0 == strcasecmp (&execpath[n - 6], "/lib32")) ||
469 (0 == strcasecmp (&execpath[n - 6], "/lib64"))))
470 {
471 if ((GNUNET_OS_IPK_LIBDIR != dirkind) &&
472 (GNUNET_OS_IPK_LIBEXECDIR != dirkind))
473 {
474 /* strip '/lib32' or '/lib64' */
475 execpath[n - 6] = '\0';
476 n -= 6;
477 }
478 else
479 isbasedir = 0;
480 }
481 else if ((n > 4) && ((0 == strcasecmp (&execpath[n - 4], "/bin")) ||
482 (0 == strcasecmp (&execpath[n - 4], "/lib"))))
483 {
484 /* strip '/bin' or '/lib' */
485 execpath[n - 4] = '\0';
486 n -= 4;
487 }
488 multiarch = NULL;
489 if (NULL != (libdir = strstr (execpath, "/lib/")))
490 {
491 /* test for multi-arch path of the form "PREFIX/lib/MULTIARCH/";
492 here we need to re-add 'multiarch' to lib and libexec paths later! */
493 multiarch = &libdir[5];
494 if (NULL == strchr (multiarch, '/'))
495 libdir[0] =
496 '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */
497 else
498 multiarch =
499 NULL; /* maybe not, multiarch still has a '/', which is not OK */
500 }
501 /* in case this was a directory named foo-bin, remove "foo-" */
502 while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR))
503 execpath[--n] = '\0';
504 switch (dirkind)
505 {
509 break;
510
513 break;
514
516 if (isbasedir)
517 {
518 GNUNET_asprintf (&tmp,
519 "%s%s%s%s%s%s%s",
520 execpath,
521 DIR_SEPARATOR_STR "lib",
522 (NULL != multiarch) ? DIR_SEPARATOR_STR : "",
523 (NULL != multiarch) ? multiarch : "",
525 pd->project_dirname,
528 {
529 GNUNET_free (execpath);
530 return tmp;
531 }
532 GNUNET_free (tmp);
533 tmp = NULL;
534 dirname = NULL;
535 if (4 == sizeof(void *))
536 {
537 GNUNET_asprintf (&dirname,
540 pd->project_dirname);
541 GNUNET_asprintf (&tmp,
542 "%s%s",
543 execpath,
544 dirname);
545 }
546 if (8 == sizeof(void *))
547 {
548 GNUNET_asprintf (&dirname,
551 pd->project_dirname);
552 GNUNET_asprintf (&tmp,
553 "%s%s",
554 execpath,
555 dirname);
556 }
557
558 if ((NULL != tmp) &&
559 (GNUNET_YES ==
561 GNUNET_YES)))
562 {
563 GNUNET_free (execpath);
564 GNUNET_free (dirname);
565 return tmp;
566 }
567 GNUNET_free (tmp);
568 GNUNET_free (dirname);
569 }
570 GNUNET_asprintf (&dirname,
572 pd->project_dirname);
573 break;
574
576 GNUNET_asprintf (&dirname,
579 pd->project_dirname);
580 break;
581
584 "locale" DIR_SEPARATOR_STR);
585 break;
586
589 "icons" DIR_SEPARATOR_STR);
590 break;
591
593 GNUNET_asprintf (&dirname,
597 pd->project_dirname);
598 break;
599
601 if (isbasedir)
602 {
603 GNUNET_asprintf (&dirname,
605 "libexec" DIR_SEPARATOR_STR,
606 pd->project_dirname);
607 GNUNET_asprintf (&tmp,
608 "%s%s%s%s",
609 execpath,
611 (NULL != multiarch) ? multiarch : "",
612 dirname);
613 GNUNET_free (dirname);
614 if (GNUNET_YES ==
616 true))
617 {
618 GNUNET_free (execpath);
619 return tmp;
620 }
621 GNUNET_free (tmp);
622 tmp = NULL;
623 dirname = NULL;
624 if (4 == sizeof(void *))
625 {
626 GNUNET_asprintf (&dirname,
629 "libexec" DIR_SEPARATOR_STR,
630 pd->project_dirname);
631 GNUNET_asprintf (&tmp,
632 "%s%s",
633 execpath,
634 dirname);
635 }
636 if (8 == sizeof(void *))
637 {
638 GNUNET_asprintf (&dirname,
641 "libexec" DIR_SEPARATOR_STR,
642 pd->project_dirname);
643 GNUNET_asprintf (&tmp,
644 "%s%s",
645 execpath,
646 dirname);
647 }
648 if ((NULL != tmp) &&
649 (GNUNET_YES ==
651 true)))
652 {
653 GNUNET_free (execpath);
654 GNUNET_free (dirname);
655 return tmp;
656 }
657 GNUNET_free (tmp);
658 GNUNET_free (dirname);
659 }
660 GNUNET_asprintf (&dirname,
662 "libexec" DIR_SEPARATOR_STR,
663 pd->project_dirname);
664 break;
665
666 default:
667 GNUNET_free (execpath);
668 return NULL;
669 }
670 GNUNET_asprintf (&tmp,
671 "%s%s",
672 execpath,
673 dirname);
674 GNUNET_free (dirname);
675 GNUNET_free (execpath);
676 return tmp;
677}
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition disk.c:466
@ 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_exec_path(const struct GNUNET_OS_ProjectData *pd)
get the path to current app's bin/
static char * os_get_gnunet_path(const struct GNUNET_OS_ProjectData *pd)
get the path to GNUnet bin/ or lib/, preferring the lib/ path
#define DIR_SEPARATOR
Definition platform.h:166
#define DIR_SEPARATOR_STR
Definition platform.h:167
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".

References 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 dump_os_ipk(), GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_load(), GNUNET_OS_get_libexec_binary_path(), GNUNET_OS_init(), GNUNET_PLUGIN_load_all(), GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), main(), netjail_start_run(), open_library(), run(), 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 struct GNUNET_OS_ProjectData pd,
const char *  progname 
)

Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the libexec/-directory to get the full path.

Parameters
pdproject data to use to determine paths
prognamename of the binary
Returns
full path to the binary, if possible, otherwise copy of 'progname'

Definition at line 681 of file os_installation.c.

683{
684 static char *cache;
685 char *libexecdir;
686 char *binary;
687
688 if ((DIR_SEPARATOR == progname[0]) ||
689 (GNUNET_YES ==
691 GNUNET_NO,
692 NULL,
693 NULL)))
694 return GNUNET_strdup (progname);
695 if (NULL != cache)
696 libexecdir = cache;
697 else
698 libexecdir = GNUNET_OS_installation_get_path (pd,
700 if (NULL == libexecdir)
701 return GNUNET_strdup (progname);
702 GNUNET_asprintf (&binary,
703 "%s%s",
704 libexecdir,
705 progname);
706 cache = libexecdir;
707 return binary;
708}
@ 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:1006

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(), service_start(), start_arm_service(), start_helper(), start_peer_run(), start_process(), test_icmp_client(), and test_icmp_server().

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_OS_ProjectData pd,
const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  progname 
)

Given the name of a helper, service or daemon binary construct the full path to the binary using the SUID_BINARY_PATH in the PATHS section of the configuration.

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
pdproject data to use to determine paths
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.

715{
716 static char *cache;
717 char *binary = NULL;
718 char *path = NULL;
719 size_t path_len;
720
721 if (GNUNET_YES ==
723 GNUNET_NO,
724 NULL,
725 NULL))
726 {
727 return GNUNET_strdup (progname);
728 }
729 if (NULL != cache)
730 path = cache;
731 else
733 "PATHS",
734 "SUID_BINARY_PATH",
735 &path);
736 if ( (NULL == path) ||
737 (0 == strlen (path)) )
738 {
739 if (NULL != path)
740 GNUNET_free (path);
741 cache = NULL;
743 progname);
744 }
745 path_len = strlen (path);
746 GNUNET_asprintf (&binary,
747 "%s%s%s",
748 path,
749 (path[path_len - 1] == DIR_SEPARATOR) ? ""
751 progname);
752 cache = path;
753 return binary;
754}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
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 struct GNUNET_OS_ProjectData *pd, const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...

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(), run(), run(), 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_command_stop()

void GNUNET_OS_command_stop ( struct GNUNET_OS_CommandHandle cmd)

Stop/kill a command.

Parameters
cmdhandle to the process

Definition at line 224 of file os_priority.c.

225{
226 if (NULL != cmd->proc)
227 {
228 GNUNET_assert (NULL != cmd->rtask);
230 }
233 SIGKILL));
236 true,
237 NULL,
238 NULL));
241 GNUNET_free (cmd);
242}
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition disk.c:1671
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_GenericReturnValue GNUNET_process_wait(struct GNUNET_Process *proc, bool blocking, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Wait for a process to terminate.
void GNUNET_process_destroy(struct GNUNET_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition os_process.c:363
enum GNUNET_GenericReturnValue GNUNET_process_kill(struct GNUNET_Process *proc, int sig)
Sends a signal to the process.
Definition os_process.c:307
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_Process * eip
Process handle.
struct GNUNET_DISK_PipeHandle * opipe
Handle to the output pipe.
struct GNUNET_SCHEDULER_Task * rtask
Task reading from pipe.
GNUNET_OS_LineProcessor proc
Function to call on each line of output.

References GNUNET_OS_CommandHandle::eip, GNUNET_assert, GNUNET_break, GNUNET_DISK_pipe_close(), GNUNET_free, GNUNET_OK, GNUNET_process_destroy(), GNUNET_process_kill(), GNUNET_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 306 of file os_priority.c.

311{
313 struct GNUNET_Process *eip;
314 struct GNUNET_DISK_PipeHandle *opipe;
315 va_list ap;
316
318 if (NULL == opipe)
319 return NULL;
320 va_start (ap, binary);
321 /* redirect stdout, don't inherit stderr/stdin */
325 eip,
327 STDOUT_FILENO)));
328 if (GNUNET_OK !=
330 binary,
331 ap))
332 {
334 va_end (ap);
336 return NULL;
337 }
338 va_end (ap);
341 cmd = GNUNET_new (struct GNUNET_OS_CommandHandle);
343 cmd->eip = eip;
344 cmd->opipe = opipe;
345 cmd->proc = proc;
346 cmd->proc_cls = proc_cls;
347 cmd->r = GNUNET_DISK_pipe_handle (opipe,
350 cmd->r,
351 &cmd_read, cmd);
352 return cmd;
353}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition gnunet-arm.c:118
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:1703
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition disk.c:1524
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:1618
@ GNUNET_DISK_PF_BLOCKING_RW
Configure both pipe ends for blocking operations if set.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
enum GNUNET_GenericReturnValue GNUNET_process_run_command_ap(struct GNUNET_Process *p, const char *filename, va_list va)
Set the command and start a process.
Definition os_process.c:866
#define GNUNET_process_set_options(proc,...)
Set the requested options for the process.
#define GNUNET_process_option_inherit_wpipe(wpipe, child_fd)
Have child process inherit a pipe for writing.
struct GNUNET_Process * GNUNET_process_create(enum GNUNET_OS_InheritStdioFlags std_inheritance)
Create a process handle.
Definition os_process.c:462
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:1667
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.
Handle used to manage a pipe.
Definition disk.c:69
Handle to a command.
size_t off
Current read offset in buf.
struct GNUNET_TIME_Absolute timeout
When to time out.
void * proc_cls
Closure for proc.
const struct GNUNET_DISK_FileHandle * r
Read-end of output pipe.

References cmd_read(), GNUNET_OS_CommandHandle::eip, GNUNET_assert, 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_OK, GNUNET_OS_INHERIT_STD_NONE, GNUNET_process_create(), GNUNET_process_destroy(), GNUNET_process_option_inherit_wpipe, GNUNET_process_run_command_ap(), GNUNET_process_set_options, GNUNET_SCHEDULER_add_read_file(), GNUNET_TIME_relative_to_absolute(), GNUNET_OS_CommandHandle::off, 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_process_create()

struct GNUNET_Process * GNUNET_process_create ( enum GNUNET_OS_InheritStdioFlags  std_inheritance)

Create a process handle.

Does not yet start it!

Returns
process handle

Definition at line 462 of file os_process.c.

463{
464 struct GNUNET_Process *p;
465
466 p = GNUNET_new (struct GNUNET_Process);
467 p->pid = -1;
469 return p;
470}
pid_t pid
PID of the process.
Definition os_process.c:94
enum GNUNET_OS_InheritStdioFlags std_inheritance
What to do with stdin/stdout/stderr unless already specified in the file map.
Definition os_process.c:106

References GNUNET_new, p, GNUNET_Process::pid, and GNUNET_Process::std_inheritance.

Referenced by communicator_start(), exec_bash_script_run(), GN_request_connection_reversal(), GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_OS_command_run(), GNUNET_PQ_exec_sql(), handle_uri(), netjail_start_run(), restart_nat_server(), run(), run(), service_start(), start_arm_service(), start_helper(), start_peer_run(), start_process(), and work().

Here is the caller graph for this function:

◆ GNUNET_process_run_command_ap()

enum GNUNET_GenericReturnValue GNUNET_process_run_command_ap ( struct GNUNET_Process p,
const char *  filename,
va_list  va 
)

Set the command and start a process.

Client must pass the filename and arguments. Can only be called once per struct GNUNET_Process. Should be called after setting options (if there are any).

Parameters
[in,out]pprocess handle for the process to setup
filenamename of the binary. It is valid to have the arguments in this string when they are separated by spaces.
vaprocess arguments, usually including filename as argv[0] again. Should all be of type const char *. The last argument MUST be NULL.
Returns
GNUNET_OK on success

Definition at line 866 of file os_process.c.

870{
871 va_list ap;
872 const char *av;
873 int argc;
874
875 if (GNUNET_SYSERR ==
877 GNUNET_NO,
878 NULL))
879 return GNUNET_SYSERR; /* not executable */
880 GNUNET_assert (NULL == p->argv);
882 argc = 0;
883 va_copy (ap,
884 va);
885 while (NULL != va_arg (ap,
886 const char *))
887 argc++;
888 va_end (ap);
889 p->argv = GNUNET_new_array (argc + 1,
890 char *);
891 argc = 0;
892 va_copy (ap,
893 va);
894 while (NULL != (av = va_arg (ap,
895 const char *)))
896 p->argv[argc++] = GNUNET_strdup (av);
897 va_end (ap);
898 return process_start (p);
899}
static char * filename
@ GNUNET_SYSERR
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
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.
static enum GNUNET_GenericReturnValue process_start(struct GNUNET_Process *proc)
Definition os_process.c:545
char * filename
Name of the binary to execute.
Definition os_process.c:131
char ** argv
Command-line arguments to pass, NULL-terminated.
Definition os_process.c:136

References GNUNET_Process::argv, filename, GNUNET_Process::filename, GNUNET_assert, GNUNET_new_array, GNUNET_NO, GNUNET_OS_check_helper_binary(), GNUNET_strdup, GNUNET_SYSERR, p, and process_start().

Referenced by GNUNET_OS_command_run(), and GNUNET_process_run_command_va().

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

◆ GNUNET_process_run_command_argv()

enum GNUNET_GenericReturnValue GNUNET_process_run_command_argv ( struct GNUNET_Process p,
const char *  filename,
const char **  argv 
)

Set the command and start a process.

Client must pass the filename and arguments. Can only be called once per struct GNUNET_Process. Should be called after setting options (if there are any).

Parameters
[in,out]pprocess handle for the process to setup
filenamename of the binary. It is valid to have the arguments in this string when they are separated by spaces.
argvprocess arguments, array MUST be NULL-terminated
Returns
GNUNET_OK on success

Definition at line 840 of file os_process.c.

844{
845 int argc;
846
847 if (GNUNET_SYSERR ==
849 GNUNET_NO,
850 NULL))
851 return GNUNET_SYSERR; /* not executable */
852 GNUNET_assert (NULL == p->argv);
854 argc = 0;
855 while (NULL != argv[argc])
856 argc++;
857 p->argv = GNUNET_new_array (argc + 1,
858 char *);
859 for (argc = 0; NULL != argv[argc]; argc++)
860 p->argv[argc] = GNUNET_strdup (argv[argc]);
861 return process_start (p);
862}

References GNUNET_Process::argv, filename, GNUNET_Process::filename, GNUNET_assert, GNUNET_new_array, GNUNET_NO, GNUNET_OS_check_helper_binary(), GNUNET_strdup, GNUNET_SYSERR, p, and process_start().

Referenced by exec_bash_script_run(), start_helper(), and work().

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

◆ GNUNET_process_run_command_va()

enum GNUNET_GenericReturnValue GNUNET_process_run_command_va ( struct GNUNET_Process p,
const char *  filename,
  ... 
)

Set the command and start a process.

Client must pass the filename and arguments. Can only be called once per struct GNUNET_Process. Should be called after setting options (if there are any).

Parameters
[in,out]pprocess handle for the process to setup
filenamename of the binary. It is valid to have the arguments in this string when they are separated by spaces.
...the process arguments, usually including filename as argv[0] again. Should all be of type const char *. The last argument MUST be NULL.
Returns
GNUNET_OK on success

Definition at line 903 of file os_process.c.

906{
908 va_list ap;
909
910 va_start (ap,
911 filename);
913 filename,
914 ap);
915 va_end (ap);
916 return ret;
917}
static int ret
Final status code.
Definition gnunet-arm.c:93
GNUNET_GenericReturnValue
Named constants for return values.

References filename, GNUNET_process_run_command_ap(), p, and ret.

Referenced by communicator_start(), GN_request_connection_reversal(), GNUNET_PQ_exec_sql(), netjail_start_run(), restart_nat_server(), run(), run(), service_start(), start_peer_run(), and start_process().

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

◆ GNUNET_process_run_command()

enum GNUNET_GenericReturnValue GNUNET_process_run_command ( struct GNUNET_Process p,
const char *  command 
)

Set the command and start a process.

Client must pass the full command, which must include the filename and arguments. Can only be called once per struct GNUNET_Process. Should be called after setting options (if there are any).

Parameters
[in,out]pprocess handle for the process to setup
commandthe command-line to run; quoting with '"' is supported to not separate arguments on whitespace; similarly, you can use '"' to escape quotes
Returns
GNUNET_OK on success

Definition at line 921 of file os_process.c.

923{
924 char *cmd = GNUNET_strdup (command);
925 size_t len = strlen (command);
926 size_t cnt = 1;
927 size_t start = 0;
928 bool quote_on = false;
929 size_t i;
930 size_t skip = 0;
931
932 GNUNET_assert (NULL == p->argv);
933 for (i=0; i<len; i++)
934 {
935 char c = cmd[i];
936
937 switch (c)
938 {
939 case '"':
940 quote_on = ! quote_on;
941 break;
942 case '\\':
943 i++;
944 break;
945 case ' ':
946 if (! quote_on)
947 cnt++;
948 while (' ' == cmd[i + 1])
949 i++;
950 break;
951 }
952 }
953
954 p->argv = GNUNET_new_array (cnt + 1,
955 char *);
956 cnt = 0;
957 for (i=0; i<len; i++)
958 {
959 char c = cmd[i];
960
961 switch (c)
962 {
963 case '"':
964 quote_on = ! quote_on;
965 skip++;
966 break;
967 case ' ':
968 if ( (! quote_on) &&
969 (i != start) )
970 {
971 p->argv[cnt] = GNUNET_strndup (&cmd[start],
972 i - start - skip);
973 cnt++;
974 skip = 0;
975 }
976 while (' ' == cmd[i + 1])
977 i++;
978 if (! quote_on)
979 start = i + 1;
980 break;
981 case '\\':
982 i++;
983 skip++;
984 cmd[i - skip] = cmd[i];
985 break;
986 default:
987 cmd[i - skip] = c;
988 break;
989 }
990 }
991 if (i != start)
992 p->argv[cnt] = GNUNET_strndup (&cmd[start],
993 i - start);
994 GNUNET_free (cmd);
995 if (quote_on)
996 {
998 "Cmd `%s' has imbalanced quotes\n",
999 cmd);
1000 }
1001 if (NULL == p->argv[0])
1002 {
1004 "Empty command specified, cannot execute\n");
1005 return GNUNET_SYSERR;
1006 }
1007 if (GNUNET_SYSERR ==
1009 GNUNET_NO,
1010 NULL))
1011 {
1013 "Specified binary `%s' is not executable\n",
1014 p->argv[0]);
1015 return GNUNET_SYSERR;
1016 }
1017 p->filename = GNUNET_strdup (p->argv[0]);
1018 return process_start (p);
1019}
static int start
Set if we are to start default services (including ARM).
Definition gnunet-arm.c:38
#define GNUNET_log(kind,...)
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.

References GNUNET_Process::argv, GNUNET_Process::filename, GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_new_array, GNUNET_NO, GNUNET_OS_check_helper_binary(), GNUNET_strdup, GNUNET_strndup, GNUNET_SYSERR, p, process_start(), and start.

Referenced by GNUNET_NAT_mini_get_external_ipv4_(), handle_uri(), start_arm_service(), and start_process().

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

◆ GNUNET_process_set_options_()

enum GNUNET_GenericReturnValue GNUNET_process_set_options_ ( struct GNUNET_Process proc,
unsigned int  num_options,
const struct GNUNET_ProcessOptionValue  options[] 
)

Set the requested options for the process.

If any option fail other options may be or may be not applied. Options must be set before calling the "GNUNET_process_run_command()" family of functions.

Parameters
[in,out]procthe process to set the options for
num_optionsmaximum length of the options array
optionsarray of options, possibly terminated early
Returns
GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR on internal error

Definition at line 1023 of file os_process.c.

1027{
1028 for (unsigned int i=0; i<num_options; i++)
1029 {
1030 const struct GNUNET_ProcessOptionValue *ov = &options[i];
1031
1032 switch (ov->option)
1033 {
1035 return GNUNET_OK;
1037 {
1038 struct EnviEntry ee = {
1040 };
1041
1042 if (NULL != ov->details.set_environment.value)
1045 proc->envs_size,
1046 ee);
1047 }
1048 continue;
1050 {
1051 struct ProcessFileMapEntry pme = {
1053 .parent_fd = ov->details.inherit_fd.parent_fd,
1054 .owned = true
1055 };
1056
1057 GNUNET_array_append (proc->map,
1058 proc->map_size,
1059 pme);
1060 }
1061 continue;
1063 {
1064 struct ProcessFileMapEntry pme = {
1065 .target_fd = -1, /* any */
1066 .parent_fd = ov->details.inherit_lsock,
1067 .systemd_listen_socket = true,
1068 .owned = false
1069 };
1070
1071 GNUNET_array_append (proc->map,
1072 proc->map_size,
1073 pme);
1074 }
1075 continue;
1076 }
1077 GNUNET_break (0);
1078 return GNUNET_SYSERR;
1079 }
1080 return GNUNET_OK;
1081}
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
Key-value pairs for setenv().
Definition os_process.c:76
char * value
Value of the environment variable.
Definition os_process.c:85
char * key
Environment key to use.
Definition os_process.c:80
struct GNUNET_ProcessOptionValue::@34::@35 set_environment
Value of if option is GNUNET_PROCESS_OPTION_SET_ENVIRONMENT.
int target_fd
File descriptor in the target process.
const char * key
Name of the environment variable to set.
struct GNUNET_ProcessOptionValue::@34::@36 inherit_fd
Value of if option is GNUNET_PROCESS_OPTION_INHERIT_FD.
int parent_fd
File descriptor in the parent process (must be open!).
enum GNUNET_ProcessOption option
Type of the option being set.
const char * value
Value to set, NULL to clear.
union GNUNET_ProcessOptionValue::@34 details
Specific option value.
int inherit_lsock
Value of if option is GNUNET_PROCESS_OPTION_INHERIT_LSOCK.
struct EnviEntry * envs
Environment variables to set in the target process.
Definition os_process.c:126
unsigned int envs_size
Length of the envs.
Definition os_process.c:121
struct ProcessFileMapEntry * map
Map of file descriptors to keep and dup2 for the new process.
Definition os_process.c:116
unsigned int map_size
Length of the map.
Definition os_process.c:111
Mapping of file descriptors of the current process to (desired) file descriptors of the child process...
Definition os_process.c:48
int target_fd
File descriptor to be used in the target process, -1 if it does not matter.
Definition os_process.c:52

References GNUNET_ProcessOptionValue::details, GNUNET_Process::envs, GNUNET_Process::envs_size, GNUNET_array_append, GNUNET_break, GNUNET_OK, GNUNET_PROCESS_OPTION_END, GNUNET_PROCESS_OPTION_INHERIT_FD, GNUNET_PROCESS_OPTION_INHERIT_LSOCK, GNUNET_PROCESS_OPTION_SET_ENVIRONMENT, GNUNET_strdup, GNUNET_SYSERR, GNUNET_ProcessOptionValue::inherit_fd, GNUNET_ProcessOptionValue::inherit_lsock, GNUNET_ProcessOptionValue::key, EnviEntry::key, GNUNET_Process::map, GNUNET_Process::map_size, GNUNET_ProcessOptionValue::option, options, GNUNET_ProcessOptionValue::parent_fd, GNUNET_ProcessOptionValue::set_environment, GNUNET_ProcessOptionValue::target_fd, ProcessFileMapEntry::target_fd, GNUNET_ProcessOptionValue::value, and EnviEntry::value.

◆ GNUNET_process_wait()

enum GNUNET_GenericReturnValue GNUNET_process_wait ( struct GNUNET_Process proc,
bool  blocking,
enum GNUNET_OS_ProcessStatusType type,
unsigned long *  code 
)

Wait for a process to terminate.

Retrieve the status of a process. This function may be called repeatedly, it will always return the last status of the process.

Parameters
procpointer to process structure
blockingtrue to wait for the process to terminate
[out]typeset to process status type
[out]codereturn code/signal number
Returns
GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise

Definition at line 1085 of file os_process.c.

1089{
1090 pid_t ret;
1091 int status;
1092
1093 if (-1 == proc->pid)
1094 {
1095 if (NULL != type)
1096 *type = proc->exit_type;
1097 if (NULL != code)
1098 *code = proc->exit_code;
1099 return GNUNET_OK;
1100 }
1101 while (proc->pid !=
1102 (ret = waitpid (proc->pid,
1103 &status,
1104 blocking ? 0 : WNOHANG)))
1105 {
1106 if ( (! blocking) &&
1107 (EINTR == errno) )
1108 {
1109 ret = 0;
1110 break;
1111 }
1112 if (EINTR != errno)
1113 break;
1114 }
1115 if (0 == ret)
1116 {
1117 if (NULL != type)
1119 if (NULL != code)
1120 *code = 0;
1121 return GNUNET_NO;
1122 }
1123#ifdef WIFCONTINUED
1124 if ( (proc->pid == ret) &&
1125 (WIFCONTINUED (status)) )
1126 {
1127 if (NULL != type)
1129 if (NULL != code)
1130 *code = 0;
1131 return GNUNET_NO;
1132 }
1133#endif
1134 if (proc->pid != ret)
1135 {
1137 "waitpid");
1138 return GNUNET_SYSERR;
1139 }
1140 /* process did exit! */
1141 proc->pid = -1;
1142 if (WIFEXITED (status))
1143 {
1145 proc->exit_code = WEXITSTATUS (status);
1146 }
1147 else if (WIFSIGNALED (status))
1148 {
1150 proc->exit_code = WTERMSIG (status);
1151 }
1152 else if (WIFSTOPPED (status))
1153 {
1155 proc->exit_code = WSTOPSIG (status);
1156 }
1157 else
1158 {
1160 proc->exit_code = 0;
1161 }
1162 if (NULL != type)
1163 *type = proc->exit_type;
1164 if (NULL != code)
1165 *code = proc->exit_code;
1166 return GNUNET_OK;
1167}
static uint32_t type
Type string converted to DNS type value.
static int status
The program status; 0 for success.
Definition gnunet-nse.c:39
@ GNUNET_ERROR_TYPE_ERROR
#define LOG_STRERROR(kind, syscall)
Definition os_process.c:33
enum GNUNET_OS_ProcessStatusType exit_type
Runtime status of the process.
Definition os_process.c:141
unsigned long exit_code
Exit status code of the process, interpretation depends on exit_type.
Definition os_process.c:146

References GNUNET_Process::exit_code, GNUNET_Process::exit_type, GNUNET_ERROR_TYPE_ERROR, GNUNET_NO, GNUNET_OK, GNUNET_OS_PROCESS_EXITED, GNUNET_OS_PROCESS_RUNNING, GNUNET_OS_PROCESS_SIGNALED, GNUNET_OS_PROCESS_UNKNOWN, GNUNET_SYSERR, LOG_STRERROR, GNUNET_Process::pid, ret, status, and type.

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_PQ_exec_sql(), maint_child_death(), maint_child_death(), maint_child_death(), maint_child_death(), nat_server_read(), netjail_start_cleanup(), run(), shutdown_process(), and start_peer_cleanup().

Here is the caller graph for this function:

◆ GNUNET_process_destroy()

void GNUNET_process_destroy ( struct GNUNET_Process proc)

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

Does NOT kill a running process.

Parameters
[in]procpointer to process structure

Definition at line 363 of file os_process.c.

364{
365 if (NULL != proc->control_pipe)
367 GNUNET_free (proc->filename);
368 for (unsigned int i = 0; i < proc->envs_size; i++)
369 {
370 GNUNET_free (proc->envs[i].key);
371 GNUNET_free (proc->envs[i].value);
372 }
373 GNUNET_free (proc->envs);
374 for (unsigned int i = 0; i < proc->map_size; i++)
375 {
376 struct ProcessFileMapEntry *me = &proc->map[i];
377 int pfd = me->parent_fd;
378
379 if (-1 == pfd)
380 continue;
381 if (! me->owned)
382 continue;
383 GNUNET_break (0 == close (pfd));
384 }
385 GNUNET_free (proc->map);
386 for (unsigned int i = 0; NULL != proc->argv[i]; i++)
387 GNUNET_free (proc->argv[i]);
388 GNUNET_free (proc->argv);
389 GNUNET_free (proc);
390}
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition disk.c:1386
struct GNUNET_DISK_FileHandle * control_pipe
Pipe we use to signal the process.
Definition os_process.c:100

References GNUNET_Process::argv, GNUNET_Process::control_pipe, GNUNET_Process::envs, GNUNET_Process::envs_size, GNUNET_Process::filename, GNUNET_break, GNUNET_DISK_file_close(), GNUNET_free, EnviEntry::key, GNUNET_Process::map, GNUNET_Process::map_size, me, and EnviEntry::value.

Referenced by child_completed_callback(), child_completed_callback(), communicator_start(), exec_bash_script_cleanup(), GN_request_connection_reversal(), GN_stop_gnunet_nat_server_(), GNUNET_HELPER_wait(), GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_NAT_mini_get_external_ipv4_cancel_(), GNUNET_OS_command_run(), GNUNET_OS_command_stop(), GNUNET_PQ_exec_sql(), maint_child_death(), maint_child_death(), maint_child_death(), nat_server_read(), netjail_start_cleanup(), restart_nat_server(), run(), run(), service_start(), shutdown_process(), start_arm_service(), start_peer_cleanup(), start_peer_run(), start_process(), wait_child(), and work().

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

◆ GNUNET_process_get_pid()

pid_t GNUNET_process_get_pid ( const struct GNUNET_Process proc)

Get the pid of the process in question.

Parameters
procthe process to get the pid of
Returns
the current process id, -1 if the process is not running (both not yet started and already terminated with status)

Definition at line 356 of file os_process.c.

357{
358 return proc->pid;
359}

References GNUNET_Process::pid.

Referenced by maint_child_death().

Here is the caller graph for this function:

◆ GNUNET_process_kill()

enum GNUNET_GenericReturnValue GNUNET_process_kill ( struct GNUNET_Process proc,
int  sig 
)

Sends a signal to the process.

Parameters
procpointer to process structure
sigsignal
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 307 of file os_process.c.

309{
310 if (NULL != proc->control_pipe)
311 {
312 char csig = (char) sig;
313 ssize_t iret;
314
316 "Sending signal %d to pid: %u via pipe\n",
317 sig,
318 proc->pid);
320 &csig,
321 sizeof(csig));
322 if (sizeof(csig) == iret)
323 return GNUNET_OK;
324 }
325 /* pipe failed or non-existent, try other methods */
326 if (-1 == proc->pid)
327 {
329 "Refusing to send signal %d process `%s': not running\n",
330 sig,
331 proc->filename);
332 return GNUNET_NO; /* -1 means process is not running, refuse... */
333 }
335 "Sending signal %d to pid: %u via system call\n",
336 sig,
337 proc->pid);
338 {
339 int ret;
340
341 ret = kill (proc->pid,
342 sig);
343 if (0 != ret)
344 {
346 "kill");
347 }
348 return (0 == ret)
349 ? GNUNET_OK
351 }
352}
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:745
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_DEBUG
#define LOG(kind,...)
Definition os_process.c:31

References GNUNET_Process::control_pipe, GNUNET_Process::filename, GNUNET_DISK_file_write(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, LOG, GNUNET_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(), handle_stop(), maint_child_death(), nat_server_read(), netjail_start_cleanup(), shutdown_process(), shutdown_program(), shutdown_task(), signal_run(), and start_peer_cleanup().

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

◆ GNUNET_process_current()

struct GNUNET_Process * GNUNET_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

Definition at line 299 of file os_process.c.

300{
302 return &current_process;
303}
static struct GNUNET_Process current_process
Handle for 'this' process.
Definition os_process.c:153

References current_process, and GNUNET_Process::pid.

◆ GNUNET_process_install_parent_control_handler()

void GNUNET_process_install_parent_control_handler ( void  )

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.

Definition at line 223 of file os_process.c.

224{
225 const char *env_buf;
226 char *env_buf_end;
227 struct GNUNET_DISK_FileHandle *control_pipe;
228 uint64_t pipe_fd;
229
230 if (NULL != pch)
231 {
232 /* already done, we've been called twice... */
233 GNUNET_break (0);
234 return;
235 }
236 env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
237 if ( (NULL == env_buf) ||
238 (strlen (env_buf) <= 0) )
239 {
241 "Not installing a handler because $%s is empty\n",
243 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
244 return;
245 }
246 errno = 0;
247 pipe_fd = strtoull (env_buf,
248 &env_buf_end,
249 16);
250 if ( (0 != errno) ||
251 (env_buf == env_buf_end) )
252 {
254 "strtoull",
255 env_buf);
257 "",
258 1);
259 return;
260 }
261 if (pipe_fd >= FD_SETSIZE)
262 {
264 "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
265 env_buf);
267 "",
268 1);
269 return;
270 }
271
272 control_pipe = GNUNET_DISK_get_handle_from_int_fd ((int) pipe_fd);
273 if (NULL == control_pipe)
274 {
276 "open",
277 env_buf);
279 "",
280 1);
281 return;
282 }
284 "Adding parent control handler pipe `%s' to the scheduler\n",
285 env_buf);
287 control_pipe,
289 control_pipe);
291 control_pipe);
293 "",
294 1);
295}
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:1410
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:1345
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_OS_CONTROL_PIPE
Definition os_process.c:40
static void parent_control_handler(void *cls)
This handler is called when there are control data to be read on the pipe.
Definition os_process.c:189
static struct GNUNET_SCHEDULER_Task * pch
Handle for the parent_control_handler() Task.
Definition os_process.c:158
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition os_process.c:36
static void shutdown_pch(void *cls)
This handler is called on shutdown to remove the pch.
Definition os_process.c:172
static struct GNUNET_SCHEDULER_Task * spch
Handle for the shutdown_pch() Task.
Definition os_process.c:163
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.

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)

Definition at line 111 of file os_priority.c.

112{
113 const char *env_buf;
114 char *env_buf_end;
115 struct GNUNET_DISK_FileHandle *control_pipe;
116 uint64_t pipe_fd;
117
118 (void) cls;
119 if (NULL != pch)
120 {
121 /* already done, we've been called twice... */
122 GNUNET_break (0);
123 return;
124 }
125 env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
126 if ((NULL == env_buf) || (strlen (env_buf) <= 0))
127 {
129 "Not installing a handler because $%s is empty\n",
131 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
132 return;
133 }
134 errno = 0;
135 pipe_fd = strtoull (env_buf, &env_buf_end, 16);
136 if ((0 != errno) || (env_buf == env_buf_end))
137 {
138 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "strtoull", env_buf);
139 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
140 return;
141 }
142 if (pipe_fd >= FD_SETSIZE)
143 {
145 "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
146 env_buf);
147 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
148 return;
149 }
150
151 control_pipe = GNUNET_DISK_get_handle_from_int_fd ((int) pipe_fd);
152
153 if (NULL == control_pipe)
154 {
156 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
157 return;
158 }
160 "Adding parent control handler pipe `%s' to the scheduler\n",
161 env_buf);
163 control_pipe,
165 control_pipe);
167 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
168}
#define GNUNET_OS_CONTROL_PIPE
Definition os_priority.c:40
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:76
static struct GNUNET_SCHEDULER_Task * pch
Handle for the parent_control_handler() Task.
Definition os_priority.c:45
#define LOG_STRERROR_FILE(kind, syscall, filename)
Definition os_priority.c:36
static void shutdown_pch(void *cls)
This handler is called on shutdown to remove the pch.
Definition os_priority.c:59
static struct GNUNET_SCHEDULER_Task * spch
Handle for the shutdown_pch() Task.
Definition os_priority.c:50
#define LOG(kind,...)
Definition os_priority.c:31

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

761{
762 struct stat statbuf;
763 char *p;
764 char *pf;
765
766 if ( (GNUNET_YES ==
768 GNUNET_NO,
769 NULL,
770 NULL)) ||
771 (0 == strncmp (binary, "./", 2)) )
772 {
773 p = GNUNET_strdup (binary);
774 }
775 else
776 {
777 p = get_path_from_PATH (binary);
778 if (NULL != p)
779 {
780 GNUNET_asprintf (&pf,
781 "%s/%s",
782 p,
783 binary);
784 GNUNET_free (p);
785 p = pf;
786 }
787 }
788
789 if (NULL == p)
790 {
792 _ ("Could not find binary `%s' in PATH!\n"),
793 binary);
794 return GNUNET_SYSERR;
795 }
796 if (0 != access (p,
797 X_OK))
798 {
800 "access",
801 p);
802 GNUNET_free (p);
803 return GNUNET_SYSERR;
804 }
805
806 if (0 == getuid ())
807 {
808 /* as we run as root, we don't insist on SUID */
809 GNUNET_free (p);
810 return GNUNET_YES;
811 }
812
813 if (0 != stat (p,
814 &statbuf))
815 {
817 "stat",
818 p);
819 GNUNET_free (p);
820 return GNUNET_SYSERR;
821 }
822 if (check_suid)
823 {
824 (void) params;
825 if ( (0 != (statbuf.st_mode & S_ISUID)) &&
826 (0 == statbuf.st_uid) )
827 {
828 GNUNET_free (p);
829 return GNUNET_YES;
830 }
832 _ ("Binary `%s' exists, but is not SUID\n"),
833 p);
834 /* binary exists, but not SUID */
835 }
836 GNUNET_free (p);
837 return GNUNET_NO;
838}
@ 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:179

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(), GNUNET_process_run_command(), GNUNET_process_run_command_ap(), GNUNET_process_run_command_argv(), handle_autoconfig_request(), netjail_start_run(), restart_nat_server(), run(), run(), run(), run(), 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: