GNUnet  0.17.6
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 
52 #ifndef GNUNET_OS_LIB_H
53 #define GNUNET_OS_LIB_H
54 
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #if 0 /* keep Emacsens' auto-indent happy */
59 }
60 #endif
61 #endif
62 
63 #include "gnunet_common.h"
65 #include "gnunet_scheduler_lib.h"
66 
67 
73 {
78 
84 
90 
96 
102 
108 
113 };
114 
115 
119 struct GNUNET_OS_Process;
120 
121 
126 {
131 
136 
141 
146 
151 
158 
163 
169 
174 };
175 
176 
181 {
187 
192 
197 
202 
207 };
208 
209 
215 {
221  const char *libname;
222 
229  const char *project_dirname;
230 
236  const char *binary_name;
237 
242  const char *env_varname;
243 
249  const char *env_varname_alt;
250 
256  const char *base_config_varname;
257 
261  const char *bug_email;
262 
266  const char *homepage;
267 
271  const char *config_file;
272 
276  const char *user_config_file;
277 
281  const char *version;
282 
286  int is_gnu;
287 
293 
299 
306  char *agpl_url;
307 };
308 
309 
313 const struct GNUNET_OS_ProjectData *
315 
316 
320 const struct GNUNET_OS_ProjectData *
322 
323 
329 void
330 GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd);
331 
332 
341 char *
343 
344 
353 char *
354 GNUNET_OS_get_libexec_binary_path (const char *progname);
355 
356 
369 char *
371  const char *progname);
372 
373 
386 typedef int
388  const char *name,
389  int isDefault,
390  const struct sockaddr *addr,
391  const struct sockaddr *broadcast_addr,
392  const struct sockaddr *netmask,
393  socklen_t addrlen);
394 
395 
402 void
404  void *proc_cls);
405 
409 #if HAVE_SYSCONF && defined(_SC_HOST_NAME_MAX)
410 #define GNUNET_OS_get_hostname_max_length() ({ int __sc_tmp = sysconf ( \
411  _SC_HOST_NAME_MAX); __sc_tmp <= \
412  0 ? 255 : __sc_tmp; })
413 #elif defined(HOST_NAME_MAX)
414 #define GNUNET_OS_get_hostname_max_length() HOST_NAME_MAX
415 #else
416 #define GNUNET_OS_get_hostname_max_length() 255
417 #endif
418 
419 
428 struct GNUNET_OS_Process *
430 
431 
439 int
441  int sig);
442 
443 
449 void
451 
452 
460 pid_t
462 
463 
475 struct GNUNET_OS_Process *
477  struct GNUNET_DISK_PipeHandle *pipe_stdin,
478  struct GNUNET_DISK_PipeHandle *pipe_stdout,
479  struct GNUNET_DISK_PipeHandle *pipe_stderr,
480  const char *filename,
481  char *const argv[]);
482 
483 
495 struct GNUNET_OS_Process *
497  struct GNUNET_DISK_PipeHandle *pipe_stdin,
498  struct GNUNET_DISK_PipeHandle *pipe_stdout,
499  struct GNUNET_DISK_PipeHandle *pipe_stderr,
500  const char *filename, ...);
501 
502 
514 struct GNUNET_OS_Process *
516  struct GNUNET_DISK_PipeHandle *pipe_stdin,
517  struct GNUNET_DISK_PipeHandle *pipe_stdout,
518  struct GNUNET_DISK_PipeHandle *pipe_stderr,
519  const char *filename, va_list va);
520 
532 struct GNUNET_OS_Process *
534  const int *lsocks,
535  const char *filename,
536  char *const argv[]);
537 
538 
556 struct GNUNET_OS_Process *
558  const int *lsocks,
559  const char *filename, ...);
560 
561 
566 
567 
574 typedef void
575 (*GNUNET_OS_LineProcessor) (void *cls, const char *line);
576 
577 
583 void
585 
586 
600  void *proc_cls,
602  const char *binary,
603  ...);
604 
605 
615 int
618  unsigned long *code);
619 
620 
631 int
633 
634 
644 int
647  unsigned long *code);
648 
649 
658 void
660 
661 
680 GNUNET_OS_check_helper_binary (const char *binary,
681  bool check_suid,
682  const char *params);
683 
684 
685 #if 0 /* keep Emacsens' auto-indent happy */
686 {
687 #endif
688 #ifdef __cplusplus
689 }
690 #endif
691 
692 /* ifndef GNUNET_OS_LIB_H */
693 #endif
694  /* end of group */
696  /* end of group addition */
698 
699 /* end of gnunet_os_lib.h */
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
static char * line
Desired phone line (string to be converted to a hash).
static char * filename
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
Configuration API.
API to schedule computations using continuation passing style.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:96
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.
Definition: os_priority.c:1142
int GNUNET_OS_process_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Retrieve the status of a process.
Definition: os_priority.c:944
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.
Definition: gnunet_os_lib.h:73
char * GNUNET_OS_get_suid_binary_path(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *progname)
Given the name of a helper, service or daemon binary construct the full path to the binary using the ...
int(* 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.
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
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:627
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...
Definition: os_priority.c:140
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.
Definition: os_priority.c:672
struct GNUNET_OS_Process * GNUNET_OS_start_process_s(enum GNUNET_OS_InheritStdioFlags std_inheritance, const int *lsocks, const char *filename,...)
Start a process.
Definition: os_priority.c:741
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:598
int 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.
Definition: os_priority.c:962
void GNUNET_OS_command_stop(struct GNUNET_OS_CommandHandle *cmd)
Stop/kill a command.
Definition: os_priority.c:1057
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_default(void)
Return default project data used by 'libgnunetutil' for GNUnet.
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
Definition: os_network.c:396
pid_t GNUNET_OS_process_get_pid(struct GNUNET_OS_Process *proc)
Get the pid of the process in question.
Definition: os_priority.c:267
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:981
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
GNUNET_OS_ProcessStatusType
Process status types.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:280
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:708
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_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
struct GNUNET_OS_Process * GNUNET_OS_process_current(void)
Get process structure for current process.
Definition: os_priority.c:209
void GNUNET_OS_init(const struct GNUNET_OS_ProjectData *pd)
Setup OS subsystem with project data.
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:217
GNUNET_OS_InstallationPathKind
Possible installation paths to request.
@ 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_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/)
const char * name
Handle used to manage a pipe.
Definition: disk.c:69
Handle to a command.
Definition: os_priority.c:1001
void * proc_cls
Closure for proc.
Definition: os_priority.c:1025
GNUNET_OS_LineProcessor proc
Function to call on each line of output.
Definition: os_priority.c:1020
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 * bug_email
E-mail address for reporting bugs.
int is_gnu
Non-zero means this project is part of GNU.
char * gettext_path
Gettext directory, e.g.
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.
char * gettext_domain
Gettext domain for localisation, e.g.
const char * version
String identifying the current project version.
char * agpl_url
URL pointing to the source code of the application.
const char * homepage
Project homepage.
Time for relative time used by GNUnet, in microseconds.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model