GNUnet 0.22.2
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 HAVE_SYSCONF   0
 
#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_gnunet (void)
 Return default project data used by 'libgnunetutil' for GNUnet. More...
 
void GNUNET_OS_init (const char *package_name, const struct GNUNET_OS_ProjectData *pd)
 Setup OS subsystem for the given project data and package. More...
 
char * GNUNET_OS_installation_get_path (const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
 Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation directory. More...
 
char * GNUNET_OS_get_libexec_binary_path (const struct GNUNET_OS_ProjectData *pd, const char *progname)
 Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the libexec/-directory to get the full path. More...
 
char * GNUNET_OS_get_suid_binary_path (const struct GNUNET_OS_ProjectData *pd, const struct GNUNET_CONFIGURATION_Handle *cfg, const char *progname)
 Given the name of a helper, service or daemon binary construct the full path to the binary using the SUID_BINARY_PATH in the PATHS section of the configuration. More...
 
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

◆ HAVE_SYSCONF

#define HAVE_SYSCONF   0

Definition at line 409 of file gnunet_os_lib.h.

◆ GNUNET_OS_get_hostname_max_length

#define GNUNET_OS_get_hostname_max_length ( )    255

Get maximum string length returned by gethostname()

Definition at line 422 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 371 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 589 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_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:427
@ 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: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 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 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(), 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:981

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(), nat_start(), peerstore_start(), resolver_start(), start_arm_service(), start_helper(), start_peer_run(), start_process(), statistics_start(), 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(), 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:93
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:682
@ 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(), 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_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:1289

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(), maint_child_death(), nat_server_read(), netjail_start_cleanup(), run(), shutdown_process(), start_arm_service(), start_peer_cleanup(), 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 567 of file os_priority.c.

573{
574 return start_process (std_inheritance,
575 pipe_stdin,
576 pipe_stdout,
577 pipe_stderr,
578 NULL,
579 filename,
580 argv);
581}
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(), 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 620 of file os_priority.c.

626{
627 struct GNUNET_OS_Process *ret;
628 va_list ap;
629
630 va_start (ap, filename);
631 ret = GNUNET_OS_start_process_va (std_inheritance,
632 pipe_stdin,
633 pipe_stdout,
634 pipe_stderr,
635 filename,
636 ap);
637 va_end (ap);
638 return ret;
639}
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:585

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(), 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 585 of file os_priority.c.

591{
592 struct GNUNET_OS_Process *ret;
593 va_list ap;
594 char **argv;
595 int argc;
596
597 argc = 0;
598 va_copy (ap, va);
599 while (NULL != va_arg (ap, char *))
600 argc++;
601 va_end (ap);
602 argv = GNUNET_malloc (sizeof(char *) * (argc + 1));
603 argc = 0;
604 va_copy (ap, va);
605 while (NULL != (argv[argc] = va_arg (ap, char *)))
606 argc++;
607 va_end (ap);
608 ret = GNUNET_OS_start_process_vap (std_inheritance,
609 pipe_stdin,
610 pipe_stdout,
611 pipe_stderr,
612 filename,
613 argv);
614 GNUNET_free (argv);
615 return ret;
616}
#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:567

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

647{
648 return start_process (std_inheritance,
649 NULL,
650 NULL,
651 NULL,
652 lsocks,
653 filename,
654 argv);
655}

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

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

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

Referenced by communicator_start(), start_arm_service(), start_peer_run(), 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 941 of file os_priority.c.

942{
943 if (NULL != cmd->proc)
944 {
945 GNUNET_assert (NULL != cmd->rtask);
947 }
948 (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL);
952 GNUNET_free (cmd);
953}
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1572
#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.
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:871
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
struct GNUNET_DISK_PipeHandle * opipe
Handle to the output pipe.
Definition: os_priority.c:901
struct GNUNET_OS_Process * eip
Process handle.
Definition: os_priority.c:896
struct GNUNET_SCHEDULER_Task * rtask
Task reading from pipe.
Definition: os_priority.c:926
GNUNET_OS_LineProcessor proc
Function to call on each line of output.
Definition: os_priority.c:911

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

1020{
1021 struct GNUNET_OS_CommandHandle *cmd;
1022 struct GNUNET_OS_Process *eip;
1023 struct GNUNET_DISK_PipeHandle *opipe;
1024 va_list ap;
1025
1027 if (NULL == opipe)
1028 return NULL;
1029 va_start (ap, binary);
1030 /* redirect stdout, don't inherit stderr/stdin */
1031 eip =
1033 NULL,
1034 opipe,
1035 NULL,
1036 binary,
1037 ap);
1038 va_end (ap);
1039 if (NULL == eip)
1040 {
1041 GNUNET_DISK_pipe_close (opipe);
1042 return NULL;
1043 }
1045 cmd = GNUNET_new (struct GNUNET_OS_CommandHandle);
1047 cmd->eip = eip;
1048 cmd->opipe = opipe;
1049 cmd->proc = proc;
1050 cmd->proc_cls = proc_cls;
1053 return cmd;
1054}
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:1602
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition: disk.c:1425
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:1519
@ 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:1661
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:962
Handle used to manage a pipe.
Definition: disk.c:69
Handle to a command.
Definition: os_priority.c:892
struct GNUNET_TIME_Absolute timeout
When to time out.
Definition: os_priority.c:931
void * proc_cls
Closure for proc.
Definition: os_priority.c:916
const struct GNUNET_DISK_FileHandle * r
Read-end of output pipe.
Definition: os_priority.c:906

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

856{
857 return process_status (proc, type, code, WNOHANG);
858}
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:790

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

872{
873 pid_t pid = proc->pid;
874 pid_t ret;
875
876 while ((pid != (ret = waitpid (pid, NULL, 0))) && (EINTR == errno))
877 ;
878 if (pid != ret)
879 {
881 "waitpid");
882 return GNUNET_SYSERR;
883 }
884 return GNUNET_OK;
885}
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(), nat_server_read(), netjail_start_cleanup(), run(), run_process_and_wait(), shutdown_process(), and start_peer_cleanup().

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

865{
866 return process_status (proc, type, code, 0);
867}

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 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
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 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
162 return;
163 }
164 if (pipe_fd >= FD_SETSIZE)
165 {
167 "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
168 env_buf);
169 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
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 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
179 return;
180 }
182 "Adding parent control handler pipe `%s' to the scheduler\n",
183 env_buf);
185 control_pipe,
187 control_pipe);
189 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
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:1311
@ 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:1339
#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 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}
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 GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_NAT_mini_map_start(), handle_autoconfig_request(), netjail_start_run(), restart_nat_server(), run(), 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: