2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_os_lib.h
23 * @brief low level process routines
24 * @author Christian Grothoff
25 * @author Krista Bennett
26 * @author Gerd Knorr <kraxel@bytesex.org>
27 * @author Ioana Patrascu
28 * @author Tzvetan Horozov
32 #ifndef GNUNET_OS_LIB_H
33 #define GNUNET_OS_LIB_H
38 #if 0 /* keep Emacsens' auto-indent happy */
43 #include "gnunet_common.h"
44 #include "gnunet_configuration_lib.h"
45 #include "gnunet_scheduler_lib.h"
49 * Possible installation paths to request
51 enum GNUNET_OS_InstallationPathKind
54 * Return the "PREFIX" directory given to configure.
59 * Return the directory where the program binaries are installed. (bin/)
64 * Return the directory where libraries are installed. (lib/)
69 * Return the directory where data is installed (share/)
71 GNUNET_OS_IPK_DATADIR,
74 * Return the directory where translations are installed (share/locale/)
76 GNUNET_OS_IPK_LOCALEDIR,
79 * Return the installation directory of this application, not
80 * the one of the overall GNUnet installation (in case they
83 GNUNET_OS_IPK_SELF_PREFIX
88 * Process status types
90 enum GNUNET_OS_ProcessStatusType
93 * The process is not known to the OS (or at
94 * least not one of our children).
96 GNUNET_OS_PROCESS_UNKNOWN,
99 * The process is still running.
101 GNUNET_OS_PROCESS_RUNNING,
104 * The process is paused (but could be resumed).
106 GNUNET_OS_PROCESS_STOPPED,
109 * The process exited with a return code.
111 GNUNET_OS_PROCESS_EXITED,
114 * The process was killed by a signal.
116 GNUNET_OS_PROCESS_SIGNALED
121 * Get the path to a specific GNUnet installation directory or, with
122 * GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation
125 * @param dirkind what kind of directory is desired?
126 * @return a pointer to the dir path (to be freed by the caller)
128 char *GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind
133 * Callback function invoked for each interface found.
136 * @param name name of the interface (can be NULL for unknown)
137 * @param isDefault is this presumably the default interface
138 * @param addr address of this interface (can be NULL for unknown or unassigned)
139 * @param addrlen length of the address
140 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
142 typedef int (*GNUNET_OS_NetworkInterfaceProcessor) (void *cls,
145 const struct sockaddr *
146 addr, socklen_t addrlen);
150 * @brief Enumerate all network interfaces
151 * @param proc the callback function
152 * @param proc_cls closure for proc
154 void GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor
155 proc, void *proc_cls);
158 * @brief Get maximum string length returned by gethostname()
160 #if HAVE_SYSCONF && defined(_SC_HOST_NAME_MAX)
161 #define GNUNET_OS_get_hostname_max_length() ({ int __sc_tmp = sysconf(_SC_HOST_NAME_MAX); __sc_tmp <= 0 ? 255 : __sc_tmp; })
162 #elif defined(HOST_NAME_MAX)
163 #define GNUNET_OS_get_hostname_max_length() HOST_NAME_MAX
165 #define GNUNET_OS_get_hostname_max_length() 255
170 * Get the current CPU load.
172 * @param cfg to determine acceptable load level (LOAD::MAXCPULOAD)
173 * @return -1 on error, otherwise load value (between 0 and 100,
174 * (100 is equivalent to full load for one CPU)
176 int GNUNET_OS_load_cpu_get (const struct GNUNET_CONFIGURATION_Handle *cfg);
180 * Get the current IO load.
182 * @param cfg to determine acceptable load level (LOAD::MAXIOLOAD)
183 * @return -1 on error, otherwise load value (between 0 and 100,
184 * 100 means that we spend all of our cycles waiting for
187 int GNUNET_OS_load_disk_get (const struct GNUNET_CONFIGURATION_Handle *cfg);
191 * Set process priority
193 * @param proc id of the process
194 * @param prio priority value
195 * @return GNUNET_OK on success, GNUNET_SYSERR on error
197 int GNUNET_OS_set_process_priority (pid_t proc,
198 enum GNUNET_SCHEDULER_Priority prio);
204 * @param pipe_stdin pipe to use to send input to child process (or NULL)
205 * @param pipe_stdout pipe to use to get output from child process (or NULL)
206 * @param filename name of the binary
207 * @param ... NULL-terminated list of arguments to the process
208 * @return process ID of the new process, -1 on error
211 GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
212 struct GNUNET_DISK_PipeHandle *pipe_stdout,
213 const char *filename, ...);
219 * @param filename name of the binary
220 * @param argv NULL-terminated list of arguments to the process,
221 * including the process name as the first argument
222 * @return process ID of the new process, -1 on error
224 pid_t GNUNET_OS_start_process_v (const char *filename, char *const argv[]);
228 * Retrieve the status of a process
229 * @param proc process ID
230 * @param type status type
231 * @param code return code/signal number
232 * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise
234 int GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
235 unsigned long *code);
240 * @param proc process ID to wait for
241 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
243 int GNUNET_OS_process_wait (pid_t proc);
246 #if 0 /* keep Emacsens' auto-indent happy */
254 /* ifndef GNUNET_OS_LIB_H */
256 /* end of gnunet_os_lib.h */