gnunet_helper_lib.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2011, 2012 Christian Grothoff
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. /**
  18. * @author Philipp Toelke
  19. * @author Christian Grothoff
  20. *
  21. * @file
  22. * API for dealing with SUID helper processes
  23. *
  24. * @defgroup helper Helper library
  25. * Dealing with SUID helper processes.
  26. *
  27. * Provides an API for dealing with (SUID) helper processes
  28. * that communicate via GNUNET_MessageHeaders on STDIN/STDOUT.
  29. *
  30. * @{
  31. */
  32. #ifndef GNUNET_HELPER_LIB_H
  33. #define GNUNET_HELPER_LIB_H
  34. #include "gnunet_scheduler_lib.h"
  35. #include "gnunet_server_lib.h"
  36. /**
  37. * The handle to a helper process.
  38. */
  39. struct GNUNET_HELPER_Handle;
  40. /**
  41. * Callback that will be called when the helper process dies. This is not called
  42. * when the helper process is stoped using GNUNET_HELPER_stop()
  43. *
  44. * @param cls the closure from GNUNET_HELPER_start()
  45. */
  46. typedef void (*GNUNET_HELPER_ExceptionCallback) (void *cls);
  47. /**
  48. * Starts a helper and begins reading from it. The helper process is
  49. * restarted when it dies except when it is stopped using GNUNET_HELPER_stop()
  50. * or when the exp_cb callback is not NULL.
  51. *
  52. * @param with_control_pipe does the helper support the use of a control pipe for signalling?
  53. * @param binary_name name of the binary to run
  54. * @param binary_argv NULL-terminated list of arguments to give when starting the binary (this
  55. * argument must not be modified by the client for
  56. * the lifetime of the helper handle)
  57. * @param cb function to call if we get messages from the helper
  58. * @param exp_cb the exception callback to call. Set this to NULL if the helper
  59. * process has to be restarted automatically when it dies/crashes
  60. * @param cb_cls closure for the above callbacks
  61. * @return the new Handle, NULL on error
  62. */
  63. struct GNUNET_HELPER_Handle *
  64. GNUNET_HELPER_start (int with_control_pipe,
  65. const char *binary_name,
  66. char *const binary_argv[],
  67. GNUNET_SERVER_MessageTokenizerCallback cb,
  68. GNUNET_HELPER_ExceptionCallback exp_cb,
  69. void *cb_cls);
  70. /**
  71. * Sends termination signal to the helper process. The helper process is not
  72. * reaped; call GNUNET_HELPER_wait() for reaping the dead helper process.
  73. *
  74. * @param h the helper handle
  75. * @param soft_kill if #GNUNET_YES, signals termination by closing the helper's
  76. * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper
  77. * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
  78. */
  79. int
  80. GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill);
  81. /**
  82. * Reap the helper process. This call is blocking (!). The helper process
  83. * should either be sent a termination signal before or should be dead before
  84. * calling this function
  85. *
  86. * @param h the helper handle
  87. * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
  88. */
  89. int
  90. GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h);
  91. /**
  92. * Free's the resources occupied by the helper handle
  93. *
  94. * @param h the helper handle to free
  95. */
  96. void
  97. GNUNET_HELPER_destroy (struct GNUNET_HELPER_Handle *h);
  98. /**
  99. * Kills the helper, closes the pipe, frees the handle and calls wait() on the
  100. * helper process
  101. *
  102. * @param h handle to helper to stop
  103. * @param soft_kill if #GNUNET_YES, signals termination by closing the helper's
  104. * stdin; #GNUNET_NO to signal termination by sending SIGTERM to helper
  105. */
  106. void
  107. GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, int soft_kill);
  108. /**
  109. * Continuation function.
  110. *
  111. * @param cls closure
  112. * @param result #GNUNET_OK on success,
  113. * #GNUNET_NO if helper process died
  114. * #GNUNET_SYSERR during GNUNET_HELPER_destroy
  115. */
  116. typedef void (*GNUNET_HELPER_Continuation)(void *cls,
  117. int result);
  118. /**
  119. * Handle to cancel 'send'
  120. */
  121. struct GNUNET_HELPER_SendHandle;
  122. /**
  123. * Send an message to the helper.
  124. *
  125. * @param h helper to send message to
  126. * @param msg message to send
  127. * @param can_drop can the message be dropped if there is already one in the queue?
  128. * @param cont continuation to run once the message is out (#GNUNET_OK on succees, #GNUNET_NO
  129. * if the helper process died, #GNUNET_SYSERR during #GNUNET_HELPER_destroy).
  130. * @param cont_cls closure for @a cont
  131. * @return NULL if the message was dropped,
  132. * otherwise handle to cancel @a cont (actual transmission may
  133. * not be abortable)
  134. */
  135. struct GNUNET_HELPER_SendHandle *
  136. GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h,
  137. const struct GNUNET_MessageHeader *msg,
  138. int can_drop,
  139. GNUNET_HELPER_Continuation cont,
  140. void *cont_cls);
  141. /**
  142. * Cancel a #GNUNET_HELPER_send operation. If possible, transmitting
  143. * the message is also aborted, but at least 'cont' won't be called.
  144. *
  145. * @param sh operation to cancel
  146. */
  147. void
  148. GNUNET_HELPER_send_cancel (struct GNUNET_HELPER_SendHandle *sh);
  149. #endif
  150. /* end of include guard: GNUNET_HELPER_LIB_H */
  151. /** @} */ /* end of group */