testing_api_cmd_exec_router.c (4063B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022 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_router.c 21 * @brief run the taler-exchange-router 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 "router" CMD. 34 */ 35 struct RouterState 36 { 37 38 /** 39 * Process for the routerer. 40 */ 41 struct GNUNET_OS_Process *router_proc; 42 43 /** 44 * Configuration file used by the routerer. 45 */ 46 const char *config_filename; 47 }; 48 49 50 /** 51 * Run the command; use the `taler-exchange-router' program. 52 * 53 * @param cls closure. 54 * @param cmd command currently being executed. 55 * @param is interpreter state. 56 */ 57 static void 58 router_run (void *cls, 59 const struct TALER_TESTING_Command *cmd, 60 struct TALER_TESTING_Interpreter *is) 61 { 62 struct RouterState *ws = cls; 63 64 (void) cmd; 65 ws->router_proc 66 = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL, 67 NULL, NULL, NULL, 68 "taler-exchange-router", 69 "taler-exchange-router", 70 "-c", ws->config_filename, 71 "-t", /* exit when done */ 72 NULL); 73 if (NULL == ws->router_proc) 74 { 75 GNUNET_break (0); 76 TALER_TESTING_interpreter_fail (is); 77 return; 78 } 79 TALER_TESTING_wait_for_sigchld (is); 80 } 81 82 83 /** 84 * Free the state of a "router" CMD, and possibly 85 * kills its process if it did not terminate regularly. 86 * 87 * @param cls closure. 88 * @param cmd the command being freed. 89 */ 90 static void 91 router_cleanup (void *cls, 92 const struct TALER_TESTING_Command *cmd) 93 { 94 struct RouterState *ws = cls; 95 96 (void) cmd; 97 if (NULL != ws->router_proc) 98 { 99 GNUNET_break (0 == 100 GNUNET_OS_process_kill (ws->router_proc, 101 SIGKILL)); 102 GNUNET_OS_process_wait (ws->router_proc); 103 GNUNET_OS_process_destroy (ws->router_proc); 104 ws->router_proc = NULL; 105 } 106 GNUNET_free (ws); 107 } 108 109 110 /** 111 * Offer "router" CMD internal data to other commands. 112 * 113 * @param cls closure. 114 * @param[out] ret result. 115 * @param trait name of the trait. 116 * @param index index number of the object to offer. 117 * @return #GNUNET_OK on success. 118 */ 119 static enum GNUNET_GenericReturnValue 120 router_traits (void *cls, 121 const void **ret, 122 const char *trait, 123 unsigned int index) 124 { 125 struct RouterState *ws = cls; 126 struct TALER_TESTING_Trait traits[] = { 127 TALER_TESTING_make_trait_process (&ws->router_proc), 128 TALER_TESTING_trait_end () 129 }; 130 131 return TALER_TESTING_get_trait (traits, 132 ret, 133 trait, 134 index); 135 } 136 137 138 struct TALER_TESTING_Command 139 TALER_TESTING_cmd_exec_router (const char *label, 140 const char *config_filename) 141 { 142 struct RouterState *ws; 143 144 ws = GNUNET_new (struct RouterState); 145 ws->config_filename = config_filename; 146 147 { 148 struct TALER_TESTING_Command cmd = { 149 .cls = ws, 150 .label = label, 151 .run = &router_run, 152 .cleanup = &router_cleanup, 153 .traits = &router_traits 154 }; 155 156 return cmd; 157 } 158 } 159 160 161 /* end of testing_api_cmd_exec_router.c */