mockup-service.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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, const struct GNUNET_MessageHeader *message)
  29. {
  30. struct GNUNET_SERVICE_Client *client = cls;
  31. (void) message;
  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. (void) cls;
  55. (void) mq;
  56. return c;
  57. }
  58. /**
  59. * Callback called when a client disconnected from the service
  60. *
  61. * @param cls closure for the service
  62. * @param c the client that disconnected
  63. * @param internal_cls should be equal to @a c
  64. */
  65. static void
  66. client_disconnect_cb (void *cls,
  67. struct GNUNET_SERVICE_Client *c,
  68. void *internal_cls)
  69. {
  70. (void) cls;
  71. GNUNET_assert (c == internal_cls);
  72. }
  73. static void
  74. run (void *cls,
  75. const struct GNUNET_CONFIGURATION_Handle *cfg,
  76. struct GNUNET_SERVICE_Handle *service)
  77. {
  78. (void) cls;
  79. (void) cfg;
  80. (void) service;
  81. /* nothing to do */
  82. }
  83. /**
  84. * Define "main" method using service macro.
  85. */
  86. GNUNET_SERVICE_MAIN ("do-nothing",
  87. GNUNET_SERVICE_OPTION_NONE,
  88. &run,
  89. &client_connect_cb,
  90. &client_disconnect_cb,
  91. NULL,
  92. GNUNET_MQ_hd_fixed_size (stop,
  93. GNUNET_MESSAGE_TYPE_ARM_STOP,
  94. struct GNUNET_MessageHeader,
  95. NULL),
  96. GNUNET_MQ_handler_end ());
  97. /**
  98. * MINIMIZE heap size (way below 128k) since this process doesn't need much.
  99. */
  100. void __attribute__ ((destructor)) GNUNET_mockup_done () { _exit (special_ret); }