exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

testing_api_cmd_exec_wirewatch.c (5023B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2018, 2023 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify
      6   it under the terms of the GNU General Public License as
      7   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, see
     17   <http://www.gnu.org/licenses/>
     18 */
     19 /**
     20  * @file testing/testing_api_cmd_exec_wirewatch.c
     21  * @brief run the taler-exchange-wirewatch command
     22  * @author Christian Grothoff
     23  * @author Marcello Stanisci
     24  */
     25 #include "taler/platform.h"
     26 #include "taler/taler_json_lib.h"
     27 #include <gnunet/gnunet_curl_lib.h>
     28 #include "taler/taler_signatures.h"
     29 #include "taler/taler_testing_lib.h"
     30 
     31 
     32 /**
     33  * State for a "wirewatch" CMD.
     34  */
     35 struct WirewatchState
     36 {
     37   /**
     38    * Process for the wirewatcher.
     39    */
     40   struct GNUNET_OS_Process *wirewatch_proc;
     41 
     42   /**
     43    * Configuration file used by the wirewatcher.
     44    */
     45   const char *config_filename;
     46 
     47   /**
     48    * Account section to be used by the wirewatcher.
     49    */
     50   const char *account_section;
     51 };
     52 
     53 
     54 /**
     55  * Run the command; use the `taler-exchange-wirewatch' program.
     56  *
     57  * @param cls closure.
     58  * @param cmd command currently being executed.
     59  * @param is interpreter state.
     60  */
     61 static void
     62 wirewatch_run (void *cls,
     63                const struct TALER_TESTING_Command *cmd,
     64                struct TALER_TESTING_Interpreter *is)
     65 {
     66   struct WirewatchState *ws = cls;
     67 
     68   (void) cmd;
     69   ws->wirewatch_proc
     70     = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
     71                                NULL, NULL, NULL,
     72                                "taler-exchange-wirewatch",
     73                                "taler-exchange-wirewatch",
     74                                "-c", ws->config_filename,
     75                                "-L", "INFO",
     76                                "-S", "1",
     77                                "-w", "0",
     78                                "-t", /* exit when done */
     79                                (NULL == ws->account_section)
     80                                ? NULL
     81                                : "-a",
     82                                ws->account_section,
     83                                NULL);
     84   if (NULL == ws->wirewatch_proc)
     85   {
     86     GNUNET_break (0);
     87     TALER_TESTING_interpreter_fail (is);
     88     return;
     89   }
     90   TALER_TESTING_wait_for_sigchld (is);
     91 }
     92 
     93 
     94 /**
     95  * Free the state of a "wirewatch" CMD, and possibly
     96  * kills its process if it did not terminate regularly.
     97  *
     98  * @param cls closure.
     99  * @param cmd the command being freed.
    100  */
    101 static void
    102 wirewatch_cleanup (void *cls,
    103                    const struct TALER_TESTING_Command *cmd)
    104 {
    105   struct WirewatchState *ws = cls;
    106 
    107   (void) cmd;
    108   if (NULL != ws->wirewatch_proc)
    109   {
    110     GNUNET_break (0 ==
    111                   GNUNET_OS_process_kill (ws->wirewatch_proc,
    112                                           SIGKILL));
    113     GNUNET_OS_process_wait (ws->wirewatch_proc);
    114     GNUNET_OS_process_destroy (ws->wirewatch_proc);
    115     ws->wirewatch_proc = NULL;
    116   }
    117   GNUNET_free (ws);
    118 }
    119 
    120 
    121 /**
    122  * Offer "wirewatch" CMD internal data to other commands.
    123  *
    124  * @param cls closure.
    125  * @param[out] ret result.
    126  * @param trait name of the trait.
    127  * @param index index number of the object to offer.
    128  * @return #GNUNET_OK on success.
    129  */
    130 static enum GNUNET_GenericReturnValue
    131 wirewatch_traits (void *cls,
    132                   const void **ret,
    133                   const char *trait,
    134                   unsigned int index)
    135 {
    136   struct WirewatchState *ws = cls;
    137   struct TALER_TESTING_Trait traits[] = {
    138     TALER_TESTING_make_trait_process (&ws->wirewatch_proc),
    139     TALER_TESTING_trait_end ()
    140   };
    141 
    142   return TALER_TESTING_get_trait (traits,
    143                                   ret,
    144                                   trait,
    145                                   index);
    146 }
    147 
    148 
    149 struct TALER_TESTING_Command
    150 TALER_TESTING_cmd_exec_wirewatch2 (const char *label,
    151                                    const char *config_filename,
    152                                    const char *account_section)
    153 {
    154   struct WirewatchState *ws;
    155 
    156   ws = GNUNET_new (struct WirewatchState);
    157   ws->config_filename = config_filename;
    158   ws->account_section = account_section;
    159   {
    160     struct TALER_TESTING_Command cmd = {
    161       .cls = ws,
    162       .label = label,
    163       .run = &wirewatch_run,
    164       .cleanup = &wirewatch_cleanup,
    165       .traits = &wirewatch_traits
    166     };
    167 
    168     return cmd;
    169   }
    170 }
    171 
    172 
    173 struct TALER_TESTING_Command
    174 TALER_TESTING_cmd_exec_wirewatch (const char *label,
    175                                   const char *config_filename)
    176 {
    177   return TALER_TESTING_cmd_exec_wirewatch2 (label,
    178                                             config_filename,
    179                                             NULL);
    180 }
    181 
    182 
    183 /* end of testing_api_cmd_exec_wirewatch.c */