Line data Source code
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_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 62 : wirewatch_run (void *cls,
63 : const struct TALER_TESTING_Command *cmd,
64 : struct TALER_TESTING_Interpreter *is)
65 : {
66 62 : struct WirewatchState *ws = cls;
67 :
68 : (void) cmd;
69 62 : ws->wirewatch_proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ERR);
70 62 : if (GNUNET_OK !=
71 62 : GNUNET_process_run_command_va (
72 : ws->wirewatch_proc,
73 : "taler-exchange-wirewatch",
74 : "taler-exchange-wirewatch",
75 : "-c", ws->config_filename,
76 : "-L", "INFO",
77 : "-S", "1",
78 : "-w", "0",
79 : "-t", /* exit when done */
80 62 : (NULL == ws->account_section)
81 : ? NULL
82 : : "-a",
83 : ws->account_section,
84 : NULL))
85 : {
86 0 : GNUNET_break (0);
87 0 : GNUNET_process_destroy (ws->wirewatch_proc);
88 0 : ws->wirewatch_proc = NULL;
89 0 : TALER_TESTING_interpreter_fail (is);
90 0 : return;
91 : }
92 62 : TALER_TESTING_wait_for_sigchld (is);
93 : }
94 :
95 :
96 : /**
97 : * Free the state of a "wirewatch" CMD, and possibly
98 : * kills its process if it did not terminate regularly.
99 : *
100 : * @param cls closure.
101 : * @param cmd the command being freed.
102 : */
103 : static void
104 62 : wirewatch_cleanup (void *cls,
105 : const struct TALER_TESTING_Command *cmd)
106 : {
107 62 : struct WirewatchState *ws = cls;
108 :
109 : (void) cmd;
110 62 : if (NULL != ws->wirewatch_proc)
111 : {
112 0 : GNUNET_break (GNUNET_OK ==
113 : GNUNET_process_kill (ws->wirewatch_proc,
114 : SIGKILL));
115 0 : GNUNET_process_wait (ws->wirewatch_proc,
116 : true,
117 : NULL,
118 : NULL);
119 0 : GNUNET_process_destroy (ws->wirewatch_proc);
120 0 : ws->wirewatch_proc = NULL;
121 : }
122 62 : GNUNET_free (ws);
123 62 : }
124 :
125 :
126 : /**
127 : * Offer "wirewatch" CMD internal data to other commands.
128 : *
129 : * @param cls closure.
130 : * @param[out] ret result.
131 : * @param trait name of the trait.
132 : * @param index index number of the object to offer.
133 : * @return #GNUNET_OK on success.
134 : */
135 : static enum GNUNET_GenericReturnValue
136 196 : wirewatch_traits (void *cls,
137 : const void **ret,
138 : const char *trait,
139 : unsigned int index)
140 : {
141 196 : struct WirewatchState *ws = cls;
142 : struct TALER_TESTING_Trait traits[] = {
143 196 : TALER_TESTING_make_trait_process (&ws->wirewatch_proc),
144 196 : TALER_TESTING_trait_end ()
145 : };
146 :
147 196 : return TALER_TESTING_get_trait (traits,
148 : ret,
149 : trait,
150 : index);
151 : }
152 :
153 :
154 : struct TALER_TESTING_Command
155 62 : TALER_TESTING_cmd_exec_wirewatch2 (const char *label,
156 : const char *config_filename,
157 : const char *account_section)
158 : {
159 : struct WirewatchState *ws;
160 :
161 62 : ws = GNUNET_new (struct WirewatchState);
162 62 : ws->config_filename = config_filename;
163 62 : ws->account_section = account_section;
164 : {
165 62 : struct TALER_TESTING_Command cmd = {
166 : .cls = ws,
167 : .label = label,
168 : .run = &wirewatch_run,
169 : .cleanup = &wirewatch_cleanup,
170 : .traits = &wirewatch_traits
171 : };
172 :
173 62 : return cmd;
174 : }
175 : }
176 :
177 :
178 : struct TALER_TESTING_Command
179 2 : TALER_TESTING_cmd_exec_wirewatch (const char *label,
180 : const char *config_filename)
181 : {
182 2 : return TALER_TESTING_cmd_exec_wirewatch2 (label,
183 : config_filename,
184 : NULL);
185 : }
186 :
187 :
188 : /* end of testing_api_cmd_exec_wirewatch.c */
|