mockup-service.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2007, 2008, 2009, 2016 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your 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. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. #include <stdlib.h>
  17. #include "platform.h"
  18. #include "gnunet_util_lib.h"
  19. #include "gnunet_protocols.h"
  20. static int special_ret = 0;
  21. /**
  22. * Handler for STOP message.
  23. *
  24. * @param cls client identification of the client
  25. * @param message the actual message
  26. */
  27. static void
  28. handle_stop (void *cls,
  29. const struct GNUNET_MessageHeader *message)
  30. {
  31. struct GNUNET_SERVICE_Client *client = cls;
  32. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  33. _("Initiating shutdown as requested by client.\n"));
  34. GNUNET_SERVICE_client_persist (client);
  35. GNUNET_SCHEDULER_shutdown ();
  36. /* ARM won't exponentially increase restart delay if we
  37. * terminate normally. This changes the return code.
  38. */
  39. special_ret = 1;
  40. }
  41. /**
  42. * Callback called when a client connects to the service.
  43. *
  44. * @param cls closure for the service
  45. * @param c the new client that connected to the service
  46. * @param mq the message queue used to send messages to the client
  47. * @return @a c
  48. */
  49. static void *
  50. client_connect_cb (void *cls,
  51. struct GNUNET_SERVICE_Client *c,
  52. struct GNUNET_MQ_Handle *mq)
  53. {
  54. return c;
  55. }
  56. /**
  57. * Callback called when a client disconnected from the service
  58. *
  59. * @param cls closure for the service
  60. * @param c the client that disconnected
  61. * @param internal_cls should be equal to @a c
  62. */
  63. static void
  64. client_disconnect_cb (void *cls,
  65. struct GNUNET_SERVICE_Client *c,
  66. void *internal_cls)
  67. {
  68. GNUNET_assert (c == internal_cls);
  69. }
  70. static void
  71. run (void *cls,
  72. const struct GNUNET_CONFIGURATION_Handle *cfg,
  73. struct GNUNET_SERVICE_Handle *service)
  74. {
  75. /* nothing to do */
  76. }
  77. /**
  78. * Define "main" method using service macro.
  79. */
  80. GNUNET_SERVICE_MAIN
  81. ("do-nothing",
  82. GNUNET_SERVICE_OPTION_NONE,
  83. &run,
  84. &client_connect_cb,
  85. &client_disconnect_cb,
  86. NULL,
  87. GNUNET_MQ_hd_fixed_size (stop,
  88. GNUNET_MESSAGE_TYPE_ARM_STOP,
  89. struct GNUNET_MessageHeader,
  90. NULL),
  91. GNUNET_MQ_handler_end ());
  92. /**
  93. * MINIMIZE heap size (way below 128k) since this process doesn't need much.
  94. */
  95. void __attribute__ ((destructor))
  96. GNUNET_mockup_done ()
  97. {
  98. _exit (special_ret);
  99. }