2 This file is part of GNUnet.
3 (C) 2011, 2012 Christian Grothoff
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 3, 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_helper_lib.h
23 * @brief API for dealing with (SUID) helper processes that communicate via
24 * GNUNET_MessageHeaders on stdin/stdout
25 * @author Philipp Toelke
26 * @author Christian Grothoff
29 #ifndef GNUNET_HELPER_LIB_H
30 #define GNUNET_HELPER_LIB_H
32 #include "gnunet_scheduler_lib.h"
33 #include "gnunet_server_lib.h"
36 * The handle to a helper process.
38 struct GNUNET_HELPER_Handle;
42 * Callback that will be called when the helper process dies. This is not called
43 * when the helper process is stoped using GNUNET_HELPER_stop()
45 * @param cls the closure from GNUNET_HELPER_start()
47 typedef void (*GNUNET_HELPER_ExceptionCallback) (void *cls);
51 * Starts a helper and begins reading from it. The helper process is
52 * restarted when it dies except when it is stopped using GNUNET_HELPER_stop()
53 * or when the exp_cb callback is not NULL.
55 * @param with_control_pipe does the helper support the use of a control pipe for signalling?
56 * @param binary_name name of the binary to run
57 * @param binary_argv NULL-terminated list of arguments to give when starting the binary (this
58 * argument must not be modified by the client for
59 * the lifetime of the helper handle)
60 * @param cb function to call if we get messages from the helper
61 * @param exp_cb the exception callback to call. Set this to NULL if the helper
62 * process has to be restarted automatically when it dies/crashes
63 * @param cb_cls closure for the above callbacks
64 * @return the new Handle, NULL on error
66 struct GNUNET_HELPER_Handle *
67 GNUNET_HELPER_start (int with_control_pipe,
68 const char *binary_name,
69 char *const binary_argv[],
70 GNUNET_SERVER_MessageTokenizerCallback cb,
71 GNUNET_HELPER_ExceptionCallback exp_cb,
76 * Sends termination signal to the helper process. The helper process is not
77 * reaped; call GNUNET_HELPER_wait() for reaping the dead helper process.
79 * @param h the helper handle
80 * @param soft_kill if GNUNET_YES, signals termination by closing the helper's
81 * stdin; GNUNET_NO to signal termination by sending SIGTERM to helper
82 * @return GNUNET_OK on success; GNUNET_SYSERR on error
85 GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill);
89 * Reap the helper process. This call is blocking(!). The helper process
90 * should either be sent a termination signal before or should be dead before
91 * calling this function
93 * @param h the helper handle
94 * @return GNUNET_OK on success; GNUNET_SYSERR on error
97 GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h);
101 * Free's the resources occupied by the helper handle
103 * @param h the helper handle to free
106 GNUNET_HELPER_destroy (struct GNUNET_HELPER_Handle *h);
110 * Kills the helper, closes the pipe, frees the handle and calls wait() on the
113 * @param h handle to helper to stop
114 * @param soft_kill if GNUNET_YES, signals termination by closing the helper's
115 * stdin; GNUNET_NO to signal termination by sending SIGTERM to helper
118 GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, int soft_kill);
122 * Continuation function.
125 * @param result GNUNET_OK on success,
126 * GNUNET_NO if helper process died
127 * GNUNET_SYSERR during GNUNET_HELPER_stop
129 typedef void (*GNUNET_HELPER_Continuation)(void *cls,
134 * Handle to cancel 'send'
136 struct GNUNET_HELPER_SendHandle;
140 * Send an message to the helper.
142 * @param h helper to send message to
143 * @param msg message to send
144 * @param can_drop can the message be dropped if there is already one in the queue?
145 * @param cont continuation to run once the message is out
146 * @param cont_cls closure for 'cont'
147 * @return NULL if the message was dropped,
148 * otherwise handle to cancel *cont* (actual transmission may
151 struct GNUNET_HELPER_SendHandle *
152 GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h,
153 const struct GNUNET_MessageHeader *msg,
155 GNUNET_HELPER_Continuation cont,
160 * Cancel a 'send' operation. If possible, transmitting the
161 * message is also aborted, but at least 'cont' won't be
164 * @param sh operation to cancel
167 GNUNET_HELPER_send_cancel (struct GNUNET_HELPER_SendHandle *sh);
169 #endif /* end of include guard: GNUNET_HELPER_LIB_H */