GNUnet 0.26.2-114-g7c6b613e3
 
Loading...
Searching...
No Matches
gnunet_os_lib.h
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2011, 2020 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
22#error "Only <gnunet_util_lib.h> can be included directly."
23#endif
24
56#ifndef GNUNET_OS_LIB_H
57#define GNUNET_OS_LIB_H
58
59#include "gnunet_disk_lib.h"
60
61#ifdef __cplusplus
62extern "C"
63{
64#if 0 /* keep Emacsens' auto-indent happy */
65}
66#endif
67#endif
68
69
116
117
171
172
204
205
211{
217 const char *libname;
218
225 const char *project_dirname;
226
232 const char *binary_name;
233
238 const char *env_varname;
239
245 const char *env_varname_alt;
246
253
257 const char *bug_email;
258
262 const char *homepage;
263
267 const char *config_file;
268
272 const char *user_config_file;
273
277 const char *version;
278
283
288 const char *gettext_domain;
289
294 const char *gettext_path;
295
302 const char *agpl_url;
303};
304
305
309const struct GNUNET_OS_ProjectData *
311
312
320void
321GNUNET_OS_init (const char *package_name,
322 const struct GNUNET_OS_ProjectData *pd);
323
324
334char *
336 enum GNUNET_OS_InstallationPathKind dirkind);
337
338
348char *
350 const char *progname);
351
352
366char *
368 const struct GNUNET_CONFIGURATION_Handle *cfg,
369 const char *progname);
370
371
384typedef enum GNUNET_GenericReturnValue
386 const char *name,
387 int isDefault,
388 const struct sockaddr *addr,
389 const struct sockaddr *broadcast_addr,
390 const struct sockaddr *netmask,
391 socklen_t addrlen);
392
393
400void
402 void *proc_cls);
403
404#ifndef HAVE_SYSCONF
405#define HAVE_SYSCONF 0
406#endif
407
411#if HAVE_SYSCONF && defined(_SC_HOST_NAME_MAX)
412#define GNUNET_OS_get_hostname_max_length() ({ int __sc_tmp = sysconf ( \
413 _SC_HOST_NAME_MAX); __sc_tmp <= \
414 0 ? 255 : __sc_tmp; })
415#elif defined(HOST_NAME_MAX)
416#define GNUNET_OS_get_hostname_max_length() HOST_NAME_MAX
417#else
418#define GNUNET_OS_get_hostname_max_length() 255
419#endif
420
421
426
427
434typedef void
435(*GNUNET_OS_LineProcessor) (void *cls,
436 const char *line);
437
438
444void
446
447
462 void *proc_cls,
464 const char *binary,
465 ...);
466
467
471struct GNUNET_Process;
472
478struct GNUNET_Process *
480
481
498 struct GNUNET_Process *p,
499 const char *filename,
500 va_list va);
501
502
517 struct GNUNET_Process *p,
518 const char *filename,
519 const char **argv);
520
521
538 const char *filename,
539 ...);
540
555 const char *command);
556
557
583
584
588#define GNUNET_PROCESS_OPTIONS_ARRAY_MAX_SIZE 32
589
590
595{
596
601
605 union
606 {
607
611 struct
612 {
616 const char *key;
617
621 const char *value;
622
624
628 struct
629 {
630
635
640
642
648
650
651};
652
653
659#define GNUNET_process_option_end_() \
660 (const struct GNUNET_ProcessOptionValue) \
661 { \
662 .option = GNUNET_PROCESS_OPTION_END \
663 }
664
672#define GNUNET_process_option_set_environment(k,v) \
673 (const struct GNUNET_ProcessOptionValue) \
674 { \
675 .option = GNUNET_PROCESS_OPTION_SET_ENVIRONMENT, \
676 .details.set_environment.key = k, \
677 .details.set_environment.value = v \
678 }
679
689#define GNUNET_process_option_inherit_fd(p, c) \
690 (const struct GNUNET_ProcessOptionValue) \
691 { \
692 .option = GNUNET_PROCESS_OPTION_INHERIT_FD, \
693 .details.inherit_fd.target_fd = c, \
694 .details.inherit_fd.parent_fd = p \
695 }
696
705#define GNUNET_process_option_inherit_rpipe(rpipe, child_fd) \
706 (const struct GNUNET_ProcessOptionValue) \
707 { \
708 .option = GNUNET_PROCESS_OPTION_INHERIT_FD, \
709 .details.inherit_fd.target_fd = child_fd, \
710 .details.inherit_fd.parent_fd \
711 = GNUNET_DISK_internal_file_handle ( \
712 GNUNET_DISK_pipe_detach_end (rpipe, \
713 GNUNET_DISK_PIPE_END_READ)) \
714 }
715
724#define GNUNET_process_option_inherit_wpipe(wpipe, child_fd) \
725 (const struct GNUNET_ProcessOptionValue) \
726 { \
727 .option = GNUNET_PROCESS_OPTION_INHERIT_FD, \
728 .details.inherit_fd.target_fd = child_fd, \
729 .details.inherit_fd.parent_fd \
730 = GNUNET_DISK_internal_file_handle ( \
731 GNUNET_DISK_pipe_detach_end (wpipe, \
732 GNUNET_DISK_PIPE_END_WRITE)) \
733 }
734
743#define GNUNET_process_option_inherit_lsock(lsock) \
744 (const struct GNUNET_ProcessOptionValue) \
745 { \
746 .option = GNUNET_PROCESS_OPTION_INHERIT_LSOCK, \
747 .details.inherit_lsock = lsock \
748 }
749
750
766 struct GNUNET_Process *proc,
767 unsigned int num_options,
768 const struct GNUNET_ProcessOptionValue options[]);
769
770
789#define GNUNET_process_set_options(proc,...) \
790 GNUNET_process_set_options_ ( \
791 proc, \
792 GNUNET_PROCESS_OPTIONS_ARRAY_MAX_SIZE, \
793 ((const struct GNUNET_ProcessOptionValue[]) \
794 {__VA_ARGS__, GNUNET_process_option_end_ () } \
795 ))
796
797
814 bool blocking,
816 unsigned long *code);
817
818
825void
827
828
836pid_t
837GNUNET_process_get_pid (const struct GNUNET_Process *proc);
838
839
849 int sig);
850
851
860struct GNUNET_Process *
862
863
869void
871
872
881void
883
884
903GNUNET_OS_check_helper_binary (const char *binary,
904 bool check_suid,
905 const char *params);
906
907
908#if 0 /* keep Emacsens' auto-indent happy */
909{
910#endif
911#ifdef __cplusplus
912}
913#endif
914
915/* ifndef GNUNET_OS_LIB_H */
916#endif
917
/* end of group */
919
/* end of group addition */
921
922/* end of gnunet_os_lib.h */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition gnunet-arm.c:118
static char * line
Desired phone line (string to be converted to a hash).
static char * filename
static char * name
Name (label) of the records to list.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38
Disk IO APIs.
GNUNET_GenericReturnValue
Named constants for return values.
void(* GNUNET_OS_LineProcessor)(void *cls, const char *line)
Type of a function to process a line of output.
GNUNET_OS_InheritStdioFlags
Flags that determine which of the standard streams should be inherited by the child process.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
void GNUNET_process_install_parent_control_handler(void)
Connects this process to its parent via pipe; essentially, the parent control handler will read signa...
Definition os_process.c:223
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,...
GNUNET_ProcessOption
Possible options we can set for a process.
void GNUNET_OS_install_parent_control_handler(void *cls)
Connects this process to its parent via pipe; essentially, the parent control handler will read signa...
enum GNUNET_GenericReturnValue GNUNET_process_run_command_va(struct GNUNET_Process *p, const char *filename,...)
Set the command and start a process.
Definition os_process.c:903
enum GNUNET_GenericReturnValue GNUNET_process_run_command(struct GNUNET_Process *p, const char *command)
Set the command and start a process.
Definition os_process.c:921
enum GNUNET_GenericReturnValue GNUNET_process_run_command_argv(struct GNUNET_Process *p, const char *filename, const char **argv)
Set the command and start a process.
Definition os_process.c:840
enum GNUNET_GenericReturnValue GNUNET_process_wait(struct GNUNET_Process *proc, bool blocking, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Wait for a process to terminate.
enum GNUNET_GenericReturnValue GNUNET_process_set_options_(struct GNUNET_Process *proc, unsigned int num_options, const struct GNUNET_ProcessOptionValue options[])
Set the requested options for the process.
enum GNUNET_GenericReturnValue GNUNET_process_run_command_ap(struct GNUNET_Process *p, const char *filename, va_list va)
Set the command and start a process.
Definition os_process.c:866
void GNUNET_process_destroy(struct GNUNET_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition os_process.c:363
void GNUNET_OS_command_stop(struct GNUNET_OS_CommandHandle *cmd)
Stop/kill a command.
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.
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
Definition os_network.c:397
void GNUNET_OS_init(const char *package_name, const struct GNUNET_OS_ProjectData *pd)
Setup OS subsystem for the given project data and package.
struct GNUNET_Process * GNUNET_process_current(void)
Get process structure for current process.
Definition os_process.c:299
GNUNET_OS_ProcessStatusType
Process status types.
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.
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 ...
GNUNET_OS_InstallationPathKind
Possible installation paths to request.
pid_t GNUNET_process_get_pid(const struct GNUNET_Process *proc)
Get the pid of the process in question.
Definition os_process.c:356
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.
enum GNUNET_GenericReturnValue GNUNET_process_kill(struct GNUNET_Process *proc, int sig)
Sends a signal to the process.
Definition os_process.c:307
struct GNUNET_Process * GNUNET_process_create(enum GNUNET_OS_InheritStdioFlags std_inheritance)
Create a process handle.
Definition os_process.c:462
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 ...
@ GNUNET_OS_INHERIT_STD_IN
When this flag is set, the child process will inherit stdin of the parent.
@ GNUNET_OS_INHERIT_STD_ALL
Use this option to have all of the standard streams (stdin, stdout and stderror) be inherited.
@ GNUNET_OS_INHERIT_STD_OUT
When this flag is set, the child process will inherit stdout of the parent.
@ GNUNET_OS_INHERIT_STD_ERR
When this flag is set, the child process will inherit stderr of the parent.
@ GNUNET_OS_INHERIT_STD_NONE
No standard streams should be inherited.
@ GNUNET_OS_INHERIT_STD_OUT_AND_ERR
When these flags are set, the child process will inherit stdout and stderr of the parent.
@ GNUNET_OS_USE_PIPE_CONTROL
Should a pipe be used to send signals to the child?
@ GNUNET_PROCESS_OPTION_INHERIT_FD
Option to inherit file descriptors.
@ GNUNET_PROCESS_OPTION_END
End of list of options.
@ GNUNET_PROCESS_OPTION_INHERIT_LSOCK
Option to inherit a listen socket systemd-style.
@ GNUNET_PROCESS_OPTION_SET_ENVIRONMENT
Option to set environment variables.
@ GNUNET_OS_PROCESS_SIGNALED
The process was killed by a signal.
@ GNUNET_OS_PROCESS_EXITED
The process exited with a return code.
@ GNUNET_OS_PROCESS_UNKNOWN
The process is not known to the OS (or at least not one of our children).
@ GNUNET_OS_PROCESS_STOPPED
The process is paused (but could be resumed).
@ GNUNET_OS_PROCESS_RUNNING
The process is still running.
@ GNUNET_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/)
Handle to a command.
size_t off
Current read offset in buf.
void * proc_cls
Closure for proc.
GNUNET_OS_LineProcessor proc
Function to call on each line of output.
Project-specific data used to help the OS subsystem find installation paths.
const char * binary_name
Name of a project-specific binary that should be in "$PREFIX/bin/".
const char * env_varname
Name of an environment variable that can be used to override installation path detection,...
const char * env_varname_alt
Alternative name of an environment variable that can be used to override installation path detection,...
const char * libname
Name of a library that is installed in the "lib/" directory of the project, such as "libgnunetutil".
const char * base_config_varname
Name of an environment variable that can be used to override the location from which default configur...
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".
const char * gettext_path
Gettext directory, e.g.
const char * gettext_domain
Gettext domain for localisation, e.g.
const char * bug_email
E-mail address for reporting bugs.
const char * agpl_url
URL pointing to the source code of the application.
int is_gnu
Non-zero means this project is part of GNU.
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.
const char * version
String identifying the current project version.
const char * homepage
Project homepage.
Possible options we can set for a process.
struct GNUNET_ProcessOptionValue::@34::@35 set_environment
Value of if option is GNUNET_PROCESS_OPTION_SET_ENVIRONMENT.
int target_fd
File descriptor in the target process.
const char * key
Name of the environment variable to set.
struct GNUNET_ProcessOptionValue::@34::@36 inherit_fd
Value of if option is GNUNET_PROCESS_OPTION_INHERIT_FD.
int parent_fd
File descriptor in the parent process (must be open!).
enum GNUNET_ProcessOption option
Type of the option being set.
const char * value
Value to set, NULL to clear.
union GNUNET_ProcessOptionValue::@34 details
Specific option value.
int inherit_lsock
Value of if option is GNUNET_PROCESS_OPTION_INHERIT_LSOCK.
enum GNUNET_OS_InheritStdioFlags std_inheritance
What to do with stdin/stdout/stderr unless already specified in the file map.
Definition os_process.c:106
char ** argv
Command-line arguments to pass, NULL-terminated.
Definition os_process.c:136
Time for relative time used by GNUnet, in microseconds.