GNUnet debian-0.24.3
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:444
@ 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(), 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:987

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

204{
206 return &current_process;
207}
static struct GNUNET_OS_Process current_process
Handle for 'this' process.
Definition: os_priority.c:63
pid_t pid
PID of the process.
Definition: os_priority.c:50

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

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

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

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

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

255{
256 return proc->pid;
257}

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

623{
624 return start_process (std_inheritance,
625 pipe_stdin,
626 pipe_stdout,
627 pipe_stderr,
628 NULL,
629 filename,
630 argv);
631}
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:318

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

676{
677 struct GNUNET_OS_Process *ret;
678 va_list ap;
679
680 va_start (ap, filename);
681 ret = GNUNET_OS_start_process_va (std_inheritance,
682 pipe_stdin,
683 pipe_stdout,
684 pipe_stderr,
685 filename,
686 ap);
687 va_end (ap);
688 return ret;
689}
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:635

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

641{
642 struct GNUNET_OS_Process *ret;
643 va_list ap;
644 char **argv;
645 int argc;
646
647 argc = 0;
648 va_copy (ap, va);
649 while (NULL != va_arg (ap, char *))
650 argc++;
651 va_end (ap);
652 argv = GNUNET_malloc (sizeof(char *) * (argc + 1));
653 argc = 0;
654 va_copy (ap, va);
655 while (NULL != (argv[argc] = va_arg (ap, char *)))
656 argc++;
657 va_end (ap);
658 ret = GNUNET_OS_start_process_vap (std_inheritance,
659 pipe_stdin,
660 pipe_stdout,
661 pipe_stderr,
662 filename,
663 argv);
664 GNUNET_free (argv);
665 return ret;
666}
#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:617

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

697{
698 return start_process (std_inheritance,
699 NULL,
700 NULL,
701 NULL,
702 lsocks,
703 filename,
704 argv);
705}

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

713{
714 va_list ap;
715 char **argv;
716 unsigned int argv_size;
717 const char *arg;
718 const char *rpos;
719 char *pos;
720 char *cp;
721 const char *last;
722 struct GNUNET_OS_Process *proc;
723 char *binary_path;
724 int quote_on;
725 unsigned int i;
726 size_t len;
727
728 argv_size = 1;
729 va_start (ap, filename);
730 arg = filename;
731 last = NULL;
732 do
733 {
734 rpos = arg;
735 quote_on = 0;
736 while ('\0' != *rpos)
737 {
738 if ('"' == *rpos)
739 {
740 if (1 == quote_on)
741 quote_on = 0;
742 else
743 quote_on = 1;
744 }
745 if ((' ' == *rpos) && (0 == quote_on))
746 {
747 if (NULL != last)
748 argv_size++;
749 last = NULL;
750 rpos++;
751 while (' ' == *rpos)
752 rpos++;
753 }
754 if ((NULL == last) && ('\0' != *rpos)) // FIXME: == or !=?
755 last = rpos;
756 if ('\0' != *rpos)
757 rpos++;
758 }
759 if (NULL != last)
760 argv_size++;
761 }
762 while (NULL != (arg = (va_arg (ap, const char *))));
763 va_end (ap);
764
765 argv = GNUNET_malloc (argv_size * sizeof(char *));
766 argv_size = 0;
767 va_start (ap, filename);
768 arg = filename;
769 last = NULL;
770 do
771 {
772 cp = GNUNET_strdup (arg);
773 quote_on = 0;
774 pos = cp;
775 while ('\0' != *pos)
776 {
777 if ('"' == *pos)
778 {
779 if (1 == quote_on)
780 quote_on = 0;
781 else
782 quote_on = 1;
783 }
784 if ((' ' == *pos) && (0 == quote_on))
785 {
786 *pos = '\0';
787 if (NULL != last)
788 argv[argv_size++] = GNUNET_strdup (last);
789 last = NULL;
790 pos++;
791 while (' ' == *pos)
792 pos++;
793 }
794 if ((NULL == last) && ('\0' != *pos)) // FIXME: == or !=?
795 last = pos;
796 if ('\0' != *pos)
797 pos++;
798 }
799 if (NULL != last)
800 argv[argv_size++] = GNUNET_strdup (last);
801 last = NULL;
802 GNUNET_free (cp);
803 }
804 while (NULL != (arg = (va_arg (ap, const char *))));
805 va_end (ap);
806 argv[argv_size] = NULL;
807
808 for (i = 0; i < argv_size; i++)
809 {
810 len = strlen (argv[i]);
811 if ((argv[i][0] == '"') && (argv[i][len - 1] == '"'))
812 {
813 memmove (&argv[i][0], &argv[i][1], len - 2);
814 argv[i][len - 2] = '\0';
815 }
816 }
817 binary_path = argv[0];
818 proc = GNUNET_OS_start_process_v (std_inheritance,
819 lsocks,
820 binary_path,
821 argv);
822 while (argv_size > 0)
823 GNUNET_free_nz (argv[--argv_size]);
824 GNUNET_free (argv);
825 return proc;
826}
#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:693

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

992{
993 if (NULL != cmd->proc)
994 {
995 GNUNET_assert (NULL != cmd->rtask);
997 }
998 (void) GNUNET_OS_process_kill (cmd->eip, SIGKILL);
1002 GNUNET_free (cmd);
1003}
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1605
#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:261
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:211
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:921
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:951
struct GNUNET_OS_Process * eip
Process handle.
Definition: os_priority.c:946
struct GNUNET_SCHEDULER_Task * rtask
Task reading from pipe.
Definition: os_priority.c:976
GNUNET_OS_LineProcessor proc
Function to call on each line of output.
Definition: os_priority.c:961

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

1070{
1071 struct GNUNET_OS_CommandHandle *cmd;
1072 struct GNUNET_OS_Process *eip;
1073 struct GNUNET_DISK_PipeHandle *opipe;
1074 va_list ap;
1075
1077 if (NULL == opipe)
1078 return NULL;
1079 va_start (ap, binary);
1080 /* redirect stdout, don't inherit stderr/stdin */
1081 eip =
1083 NULL,
1084 opipe,
1085 NULL,
1086 binary,
1087 ap);
1088 va_end (ap);
1089 if (NULL == eip)
1090 {
1091 GNUNET_DISK_pipe_close (opipe);
1092 return NULL;
1093 }
1095 cmd = GNUNET_new (struct GNUNET_OS_CommandHandle);
1097 cmd->eip = eip;
1098 cmd->opipe = opipe;
1099 cmd->proc = proc;
1100 cmd->proc_cls = proc_cls;
1103 return cmd;
1104}
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:1635
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition: disk.c:1458
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:1552
@ 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:1012
Handle used to manage a pipe.
Definition: disk.c:69
Handle to a command.
Definition: os_priority.c:942
struct GNUNET_TIME_Absolute timeout
When to time out.
Definition: os_priority.c:981
void * proc_cls
Closure for proc.
Definition: os_priority.c:966
const struct GNUNET_DISK_FileHandle * r
Read-end of output pipe.
Definition: os_priority.c:956

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

906{
907 return process_status (proc, type, code, WNOHANG);
908}
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:840

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

922{
923 pid_t pid = proc->pid;
924 pid_t ret;
925
926 while ((pid != (ret = waitpid (pid, NULL, 0))) && (EINTR == errno))
927 ;
928 if (pid != ret)
929 {
931 "waitpid");
932 return GNUNET_SYSERR;
933 }
934 return GNUNET_OK;
935}
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 912 of file os_priority.c.

915{
916 return process_status (proc, type, code, 0);
917}

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

135{
136 const char *env_buf;
137 char *env_buf_end;
138 struct GNUNET_DISK_FileHandle *control_pipe;
139 uint64_t pipe_fd;
140
141 (void) cls;
142 if (NULL != pch)
143 {
144 /* already done, we've been called twice... */
145 GNUNET_break (0);
146 return;
147 }
148 env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
149 if ((NULL == env_buf) || (strlen (env_buf) <= 0))
150 {
152 "Not installing a handler because $%s is empty\n",
154 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
155 return;
156 }
157 errno = 0;
158 pipe_fd = strtoull (env_buf, &env_buf_end, 16);
159 if ((0 != errno) || (env_buf == env_buf_end))
160 {
161 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "strtoull", env_buf);
162 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
163 return;
164 }
165 if (pipe_fd >= FD_SETSIZE)
166 {
168 "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
169 env_buf);
170 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
171 return;
172 }
173
174 control_pipe = GNUNET_DISK_get_handle_from_int_fd ((int) pipe_fd);
175
176 if (NULL == control_pipe)
177 {
179 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
180 return;
181 }
183 "Adding parent control handler pipe `%s' to the scheduler\n",
184 env_buf);
186 control_pipe,
188 control_pipe);
190 setenv (GNUNET_OS_CONTROL_PIPE, "", 1);
191}
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:1344
@ 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:42
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:99
static struct GNUNET_SCHEDULER_Task * pch
Handle for the parent_control_handler() Task.
Definition: os_priority.c:68
#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:82
static struct GNUNET_SCHEDULER_Task * spch
Handle for the shutdown_pch() Task.
Definition: os_priority.c:73
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: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(), 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: