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