testing_api_cmd_exec_donaukeyupdate.c (4673B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it 6 under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 TALER is distributed in the hope that it will be useful, but 11 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 testing/testing_api_cmd_exec_donaukeyupdate.c 21 * @brief run the taler-merchant-donaukeyupdate command 22 * @author Christian Grothoff 23 */ 24 #include "taler/platform.h" 25 #include <taler/taler_json_lib.h> 26 #include <gnunet/gnunet_curl_lib.h> 27 #include <taler/taler_signatures.h> 28 #include "taler/taler_merchant_testing_lib.h" 29 30 31 /** 32 * State for a "donaukeyupdate" CMD. 33 */ 34 struct DonaukeyupdateState 35 { 36 37 /** 38 * Donaukeyupdate process. 39 */ 40 struct GNUNET_Process *donaukeyupdate_proc; 41 42 /** 43 * Configuration file used by the donaukeyupdate. 44 */ 45 const char *config_filename; 46 }; 47 48 49 /** 50 * Run the command. Use the `taler-merchant-donaukeyupdate` program. 51 * 52 * @param cls closure. 53 * @param cmd command being run. 54 * @param is interpreter state. 55 */ 56 static void 57 donaukeyupdate_run (void *cls, 58 const struct TALER_TESTING_Command *cmd, 59 struct TALER_TESTING_Interpreter *is) 60 { 61 struct DonaukeyupdateState *as = cls; 62 63 (void) cmd; 64 as->donaukeyupdate_proc 65 = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ERR); 66 if (GNUNET_OK != 67 GNUNET_process_run_command_va (as->donaukeyupdate_proc, 68 "taler-merchant-donaukeyupdate", 69 "taler-merchant-donaukeyupdate", 70 "-c", as->config_filename, 71 "-L", "INFO", 72 "-t", /* exit when done */ 73 NULL)) 74 { 75 GNUNET_break (0); 76 GNUNET_process_destroy (as->donaukeyupdate_proc); 77 as->donaukeyupdate_proc = NULL; 78 TALER_TESTING_interpreter_fail (is); 79 return; 80 } 81 TALER_TESTING_wait_for_sigchld (is); 82 } 83 84 85 /** 86 * Free the state of a "donaukeyupdate" CMD, and possibly kill its 87 * process if it did not terminate correctly. 88 * 89 * @param cls closure. 90 * @param cmd the command being freed. 91 */ 92 static void 93 donaukeyupdate_cleanup (void *cls, 94 const struct TALER_TESTING_Command *cmd) 95 { 96 struct DonaukeyupdateState *as = cls; 97 98 (void) cmd; 99 if (NULL != as->donaukeyupdate_proc) 100 { 101 GNUNET_break (GNUNET_OK == 102 GNUNET_process_kill (as->donaukeyupdate_proc, 103 SIGKILL)); 104 GNUNET_break (GNUNET_OK == 105 GNUNET_process_wait (as->donaukeyupdate_proc, 106 true, 107 NULL, 108 NULL)); 109 GNUNET_process_destroy (as->donaukeyupdate_proc); 110 as->donaukeyupdate_proc = NULL; 111 } 112 GNUNET_free (as); 113 } 114 115 116 /** 117 * Offer "donaukeyupdate" CMD internal data to other commands. 118 * 119 * @param cls closure. 120 * @param[out] ret result. 121 * @param trait name of the trait. 122 * @param index index number of the object to offer. 123 * @return #GNUNET_OK on success 124 */ 125 static enum GNUNET_GenericReturnValue 126 donaukeyupdate_traits (void *cls, 127 const void **ret, 128 const char *trait, 129 unsigned int index) 130 { 131 struct DonaukeyupdateState *as = cls; 132 struct TALER_TESTING_Trait traits[] = { 133 TALER_TESTING_make_trait_process (&as->donaukeyupdate_proc), 134 TALER_TESTING_trait_end () 135 }; 136 137 return TALER_TESTING_get_trait (traits, 138 ret, 139 trait, 140 index); 141 } 142 143 144 struct TALER_TESTING_Command 145 TALER_TESTING_cmd_exec_donaukeyupdate (const char *label, 146 const char *config_filename) 147 { 148 struct DonaukeyupdateState *as; 149 150 as = GNUNET_new (struct DonaukeyupdateState); 151 as->config_filename = config_filename; 152 { 153 struct TALER_TESTING_Command cmd = { 154 .cls = as, 155 .label = label, 156 .run = &donaukeyupdate_run, 157 .cleanup = &donaukeyupdate_cleanup, 158 .traits = &donaukeyupdate_traits 159 }; 160 161 return cmd; 162 } 163 } 164 165 166 /* end of testing_api_cmd_exec_donaukeyupdate.c */