LCOV - code coverage report
Current view: top level - bank-lib - fakebank_stop.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 81.7 % 60 49
Test Date: 2026-04-14 15:39:31 Functions: 66.7 % 3 2

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (C) 2016-2023 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or
       6              :   modify it under the terms of the GNU General Public License
       7              :   as published by the Free Software Foundation; either version 3,
       8              :   or (at your option) any later version.
       9              : 
      10              :   TALER is distributed in the hope that it will be useful,
      11              :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      12              :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13              :   GNU General Public License for more details.
      14              : 
      15              :   You should have received a copy of the GNU General Public
      16              :   License along with TALER; see the file COPYING.  If not,
      17              :   see <http://www.gnu.org/licenses/>
      18              : */
      19              : /**
      20              :  * @file bank-lib/fakebank_stop.c
      21              :  * @brief library that fakes being a Taler bank for testcases
      22              :  * @author Christian Grothoff <christian@grothoff.org>
      23              :  */
      24              : #include <pthread.h>
      25              : #include <poll.h>
      26              : #ifdef __linux__
      27              : #include <sys/eventfd.h>
      28              : #endif
      29              : #include "taler/taler_fakebank_lib.h"
      30              : #include "taler/taler_bank_service.h"
      31              : #include "taler/taler_mhd_lib.h"
      32              : #include <gnunet/gnunet_mhd_compat.h>
      33              : #include "fakebank.h"
      34              : #include "fakebank_common_lp.h"
      35              : 
      36              : 
      37              : /**
      38              :  * Helper function to free memory when finished.
      39              :  *
      40              :  * @param cls NULL
      41              :  * @param key key of the account to free (ignored)
      42              :  * @param val a `struct Account` to free.
      43              :  */
      44              : static enum GNUNET_GenericReturnValue
      45           53 : free_account (void *cls,
      46              :               const struct GNUNET_HashCode *key,
      47              :               void *val)
      48              : {
      49           53 :   struct Account *account = val;
      50              : 
      51              :   (void) cls;
      52              :   (void) key;
      53           53 :   GNUNET_assert (NULL == account->lp_head);
      54           53 :   GNUNET_free (account->account_name);
      55           53 :   GNUNET_free (account->receiver_name);
      56           53 :   GNUNET_free (account->payto_uri);
      57           53 :   GNUNET_free (account->password);
      58           53 :   GNUNET_free (account);
      59           53 :   return GNUNET_OK;
      60              : }
      61              : 
      62              : 
      63              : /**
      64              :  * Helper function to free memory when finished.
      65              :  *
      66              :  * @param cls NULL
      67              :  * @param key key of the operation to free (ignored)
      68              :  * @param val a `struct WithdrawalOperation *` to free.
      69              :  */
      70              : static enum GNUNET_GenericReturnValue
      71            0 : free_withdraw_op (void *cls,
      72              :                   const struct GNUNET_ShortHashCode *key,
      73              :                   void *val)
      74              : {
      75            0 :   struct WithdrawalOperation *wo = val;
      76              : 
      77              :   (void) cls;
      78              :   (void) key;
      79            0 :   GNUNET_free (wo->amount);
      80            0 :   GNUNET_free (wo);
      81            0 :   return GNUNET_OK;
      82              : }
      83              : 
      84              : 
      85              : void
      86           16 : TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h)
      87              : {
      88           16 :   if (NULL != h->lp_task)
      89              :   {
      90            0 :     GNUNET_SCHEDULER_cancel (h->lp_task);
      91            0 :     h->lp_task = NULL;
      92              :   }
      93              : #if EPOLL_SUPPORT
      94              :   if (NULL != h->mhd_rfd)
      95              :   {
      96              :     GNUNET_NETWORK_socket_free_memory_only_ (h->mhd_rfd);
      97              :     h->mhd_rfd = NULL;
      98              :   }
      99              : #endif
     100              : #ifdef __linux__
     101           16 :   if (-1 != h->lp_event)
     102              : #else
     103              :   if (-1 != h->lp_event_in && -1 != h->lp_event_out)
     104              : #endif
     105              :   {
     106           15 :     uint64_t val = 1;
     107              :     void *ret;
     108              :     struct LongPoller *lp;
     109              : 
     110           15 :     GNUNET_assert (0 ==
     111              :                    pthread_mutex_lock (&h->big_lock));
     112           15 :     h->in_shutdown = true;
     113           15 :     while (NULL != (lp = GNUNET_CONTAINER_heap_remove_root (h->lp_heap)))
     114            0 :       TALER_FAKEBANK_lp_trigger_ (lp);
     115           15 :     GNUNET_assert (0 ==
     116              :                    pthread_mutex_unlock (&h->big_lock));
     117              : #ifdef __linux__
     118           15 :     GNUNET_break (sizeof (val) ==
     119              :                   write (h->lp_event,
     120              :                          &val,
     121              :                          sizeof (val)));
     122              : #else
     123              :     GNUNET_break (sizeof (val) ==
     124              :                   write (h->lp_event_in,
     125              :                          &val,
     126              :                          sizeof (val)));
     127              : #endif
     128           15 :     GNUNET_break (0 ==
     129              :                   pthread_join (h->lp_thread,
     130              :                                 &ret));
     131           15 :     GNUNET_break (NULL == ret);
     132              : #ifdef __linux__
     133           15 :     GNUNET_break (0 == close (h->lp_event));
     134           15 :     h->lp_event = -1;
     135              : #else
     136              :     GNUNET_break (0 == close (h->lp_event_in));
     137              :     GNUNET_break (0 == close (h->lp_event_out));
     138              :     h->lp_event_in = -1;
     139              :     h->lp_event_out = -1;
     140              : #endif
     141              :   }
     142              :   else
     143              :   {
     144              :     struct LongPoller *lp;
     145              : 
     146            1 :     while (NULL != (lp = GNUNET_CONTAINER_heap_remove_root (h->lp_heap)))
     147            0 :       TALER_FAKEBANK_lp_trigger_ (lp);
     148              :   }
     149           16 :   if (NULL != h->mhd_bank)
     150              :   {
     151           16 :     MHD_stop_daemon (h->mhd_bank);
     152           16 :     h->mhd_bank = NULL;
     153              :   }
     154           16 :   if (NULL != h->mhd_task)
     155              :   {
     156            1 :     GNUNET_SCHEDULER_cancel (h->mhd_task);
     157            1 :     h->mhd_task = NULL;
     158              :   }
     159           16 :   if (NULL != h->accounts)
     160              :   {
     161           16 :     GNUNET_CONTAINER_multihashmap_iterate (h->accounts,
     162              :                                            &free_account,
     163              :                                            NULL);
     164           16 :     GNUNET_CONTAINER_multihashmap_destroy (h->accounts);
     165              :   }
     166           16 :   if (NULL != h->wops)
     167              :   {
     168            0 :     GNUNET_CONTAINER_multishortmap_iterate (h->wops,
     169              :                                             &free_withdraw_op,
     170              :                                             NULL);
     171            0 :     GNUNET_CONTAINER_multishortmap_destroy (h->wops);
     172              :   }
     173           16 :   GNUNET_CONTAINER_multihashmap_destroy (h->uuid_map);
     174           16 :   GNUNET_CONTAINER_multipeermap_destroy (h->rpubs);
     175           16 :   GNUNET_CONTAINER_heap_destroy (h->lp_heap);
     176           16 :   GNUNET_assert (0 ==
     177              :                  pthread_mutex_destroy (&h->big_lock));
     178           16 :   GNUNET_assert (0 ==
     179              :                  pthread_mutex_destroy (&h->uuid_map_lock));
     180           16 :   GNUNET_assert (0 ==
     181              :                  pthread_mutex_destroy (&h->accounts_lock));
     182           16 :   GNUNET_assert (0 ==
     183              :                  pthread_mutex_destroy (&h->rpubs_lock));
     184      1114160 :   for (uint64_t i = 0; i<h->ram_limit; i++)
     185      1114144 :     GNUNET_free (h->transactions[i]);
     186           16 :   GNUNET_free (h->transactions);
     187           16 :   GNUNET_free (h->my_baseurl);
     188           16 :   GNUNET_free (h->currency);
     189           16 :   GNUNET_free (h->exchange_url);
     190           16 :   GNUNET_free (h->hostname);
     191           16 :   GNUNET_free (h);
     192           16 : }
        

Generated by: LCOV version 2.0-1