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"
48 * Process information (OS-dependent)
50 typedef struct _GNUNET_OS_Process GNUNET_OS_Process;
54 * Possible installation paths to request
56 enum GNUNET_OS_InstallationPathKind
59 * Return the "PREFIX" directory given to configure.
64 * Return the directory where the program binaries are installed. (bin/)
69 * Return the directory where libraries are installed. (lib/)
74 * Return the directory where data is installed (share/)
76 GNUNET_OS_IPK_DATADIR,
79 * Return the directory where translations are installed (share/locale/)
81 GNUNET_OS_IPK_LOCALEDIR,
84 * Return the installation directory of this application, not
85 * the one of the overall GNUnet installation (in case they
88 GNUNET_OS_IPK_SELF_PREFIX,
91 * Return the prefix of the path with application icons.
98 * Process status types
100 enum GNUNET_OS_ProcessStatusType
103 * The process is not known to the OS (or at
104 * least not one of our children).
106 GNUNET_OS_PROCESS_UNKNOWN,
109 * The process is still running.
111 GNUNET_OS_PROCESS_RUNNING,
114 * The process is paused (but could be resumed).
116 GNUNET_OS_PROCESS_STOPPED,
119 * The process exited with a return code.
121 GNUNET_OS_PROCESS_EXITED,
124 * The process was killed by a signal.
126 GNUNET_OS_PROCESS_SIGNALED
131 * Get the path to a specific GNUnet installation directory or, with
132 * GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation
135 * @param dirkind what kind of directory is desired?
136 * @return a pointer to the dir path (to be freed by the caller)
138 char *GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind
143 * Callback function invoked for each interface found.
146 * @param name name of the interface (can be NULL for unknown)
147 * @param isDefault is this presumably the default interface
148 * @param addr address of this interface (can be NULL for unknown or unassigned)
149 * @param addrlen length of the address
150 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
152 typedef int (*GNUNET_OS_NetworkInterfaceProcessor) (void *cls,
155 const struct sockaddr *
156 addr, socklen_t addrlen);
160 * @brief Enumerate all network interfaces
161 * @param proc the callback function
162 * @param proc_cls closure for proc
164 void GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor
165 proc, void *proc_cls);
168 * @brief Get maximum string length returned by gethostname()
170 #if HAVE_SYSCONF && defined(_SC_HOST_NAME_MAX)
171 #define GNUNET_OS_get_hostname_max_length() ({ int __sc_tmp = sysconf(_SC_HOST_NAME_MAX); __sc_tmp <= 0 ? 255 : __sc_tmp; })
172 #elif defined(HOST_NAME_MAX)
173 #define GNUNET_OS_get_hostname_max_length() HOST_NAME_MAX
175 #define GNUNET_OS_get_hostname_max_length() 255
179 * Allocates new process structure
181 * Should be made internal?
183 * @return pointer to allocated structure
185 GNUNET_OS_Process *GNUNET_OS_process_alloc ();
189 * Get process structure for current process
191 * The pointer it returns points to static memory location and must not be
194 * @return pointer to the process sturcutre for this process
196 GNUNET_OS_Process *GNUNET_OS_process_current ();
200 * Sends @sig to the process
202 * @param proc pointer to process structure
204 * @return 0 on success, -1 on error
206 int GNUNET_OS_process_kill (GNUNET_OS_Process *proc, int sig);
211 * Should be made internal?
213 * @param proc pointer to process structure
216 pid_t GNUNET_OS_process_get_pid (GNUNET_OS_Process *proc);
221 * Should be made internal?
223 * @param proc pointer to process structure
224 * @param pid process ID
226 void GNUNET_OS_process_set_pid (GNUNET_OS_Process *proc, pid_t pid);
232 * Should be made internal?
234 * @param proc pointer to process structure
235 * @return process handle
237 HANDLE GNUNET_OS_process_get_handle (GNUNET_OS_Process *proc);
242 * Should be made internal?
244 * @param proc pointer to process structure
245 * @param handle process handle
247 void GNUNET_OS_process_set_handle(GNUNET_OS_Process *proc, HANDLE handle);
251 * Cleans up process structure contents (OS-dependent) and deallocates it
253 * @param proc pointer to process structure
255 void GNUNET_OS_process_close (GNUNET_OS_Process *proc);
258 * Set process priority
260 * @param proc pointer to process structure
261 * @param prio priority value
262 * @return GNUNET_OK on success, GNUNET_SYSERR on error
264 int GNUNET_OS_set_process_priority (GNUNET_OS_Process *proc,
265 enum GNUNET_SCHEDULER_Priority prio);
271 * @param pipe_stdin pipe to use to send input to child process (or NULL)
272 * @param pipe_stdout pipe to use to get output from child process (or NULL)
273 * @param filename name of the binary
274 * @param ... NULL-terminated list of arguments to the process
275 * @return pointer to process structure of the new process, NULL on error
278 GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
279 struct GNUNET_DISK_PipeHandle *pipe_stdout,
280 const char *filename, ...);
286 * @param lsocks array of listen sockets to dup systemd-style (or NULL);
287 * must be NULL on platforms where dup is not supported
288 * @param filename name of the binary
289 * @param argv NULL-terminated list of arguments to the process,
290 * including the process name as the first argument
291 * @return pointer to process structure of the new process, NULL on error
294 GNUNET_OS_start_process_v (const int *lsocks, const char *filename,
299 * Retrieve the status of a process
300 * @param proc pointer to process structure
301 * @param type status type
302 * @param code return code/signal number
303 * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise
305 int GNUNET_OS_process_status (GNUNET_OS_Process *proc,
306 enum GNUNET_OS_ProcessStatusType *type, unsigned long *code);
311 * @param proc pointer to process structure of the process to wait for
312 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
314 int GNUNET_OS_process_wait (GNUNET_OS_Process *proc);
317 #if 0 /* keep Emacsens' auto-indent happy */
325 /* ifndef GNUNET_OS_LIB_H */
327 /* end of gnunet_os_lib.h */