aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_netjail_start.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-10-08 21:50:34 +0200
committerChristian Grothoff <christian@grothoff.org>2021-10-08 21:50:34 +0200
commitbd8f79f628b254f4f02c08284ba65d23486d6127 (patch)
tree8729cfd715433db91b0fbb72d0aac164082b7f24 /src/testing/testing_api_cmd_netjail_start.c
parent6ef071b8ccea72da6a9e1eee6483c326b6ebc082 (diff)
downloadgnunet-bd8f79f628b254f4f02c08284ba65d23486d6127.tar.gz
gnunet-bd8f79f628b254f4f02c08284ba65d23486d6127.zip
-clean up testing-NG finish logic
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_start.c')
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c62
1 files changed, 17 insertions, 45 deletions
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index 1815b64d2..4b5592524 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -35,6 +35,11 @@
35 */ 35 */
36struct NetJailState 36struct NetJailState
37{ 37{
38 /**
39 * Context for our asynchronous completion.
40 */
41 struct GNUNET_TESTING_AsyncContext ac;
42
38 // Child Wait handle 43 // Child Wait handle
39 struct GNUNET_ChildWaitHandle *cwh; 44 struct GNUNET_ChildWaitHandle *cwh;
40 45
@@ -67,7 +72,6 @@ netjail_start_cleanup (void *cls)
67 72
68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
69 "netjail_start_cleanup!\n"); 74 "netjail_start_cleanup!\n");
70
71 if (NULL != ns->cwh) 75 if (NULL != ns->cwh)
72 { 76 {
73 GNUNET_wait_child_cancel (ns->cwh); 77 GNUNET_wait_child_cancel (ns->cwh);
@@ -88,20 +92,6 @@ netjail_start_cleanup (void *cls)
88 92
89 93
90/** 94/**
91 * Trait function of this cmd does nothing.
92 *
93 */
94static enum GNUNET_GenericReturnValue
95netjail_start_traits (void *cls,
96 const void **ret,
97 const char *trait,
98 unsigned int index)
99{
100 return GNUNET_NO;
101}
102
103
104/**
105 * Callback which will be called if the setup script finished. 95 * Callback which will be called if the setup script finished.
106 * 96 *
107 */ 97 */
@@ -112,18 +102,18 @@ child_completed_callback (void *cls,
112{ 102{
113 struct NetJailState *ns = cls; 103 struct NetJailState *ns = cls;
114 104
105 GNUNET_OS_process_destroy (ns->start_proc);
106 ns->start_proc = NULL;
115 if (0 == exit_code) 107 if (0 == exit_code)
116 { 108 {
117 ns->finished = GNUNET_YES; 109 GNUNET_TESTING_async_finish (&ns->ac);
118 } 110 }
119 else 111 else
120 { 112 {
121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
122 "Child completed with an error!\n"); 114 "Child completed with an error!\n");
123 ns->finished = GNUNET_SYSERR; 115 GNUNET_TESTING_async_fail (&ns->ac);
124 } 116 }
125 GNUNET_OS_process_destroy (ns->start_proc);
126 ns->start_proc = NULL;
127} 117}
128 118
129 119
@@ -138,10 +128,12 @@ netjail_start_run (void *cls,
138 struct GNUNET_TESTING_Interpreter *is) 128 struct GNUNET_TESTING_Interpreter *is)
139{ 129{
140 struct NetJailState *ns = cls; 130 struct NetJailState *ns = cls;
141 char *const script_argv[] = {NETJAIL_START_SCRIPT, 131 char *const script_argv[] = {
142 ns->local_m, 132 NETJAIL_START_SCRIPT,
143 ns->global_n, 133 ns->local_m,
144 NULL}; 134 ns->global_n,
135 NULL
136 };
145 unsigned int helper_check = GNUNET_OS_check_helper_binary ( 137 unsigned int helper_check = GNUNET_OS_check_helper_binary (
146 NETJAIL_START_SCRIPT, 138 NETJAIL_START_SCRIPT,
147 GNUNET_YES, 139 GNUNET_YES,
@@ -177,25 +169,6 @@ netjail_start_run (void *cls,
177 169
178 170
179/** 171/**
180 * This function checks the flag NetJailState#finished, if this cmd finished.
181 *
182 */
183static enum GNUNET_GenericReturnValue
184netjail_start_finish (void *cls,
185 GNUNET_SCHEDULER_TaskCallback cont,
186 void *cont_cls)
187{
188 struct NetJailState *ns = cls;
189
190 if (ns->finished)
191 {
192 cont (cont_cls);
193 }
194 return ns->finished;
195}
196
197
198/**
199 * Create command. 172 * Create command.
200 * 173 *
201 * @param label name for command. 174 * @param label name for command.
@@ -218,9 +191,8 @@ GNUNET_TESTING_cmd_netjail_start (const char *label,
218 .cls = ns, 191 .cls = ns,
219 .label = label, 192 .label = label,
220 .run = &netjail_start_run, 193 .run = &netjail_start_run,
221 .finish = &netjail_start_finish, 194 .ac = &ns->ac,
222 .cleanup = &netjail_start_cleanup, 195 .cleanup = &netjail_start_cleanup
223 .traits = &netjail_start_traits
224 }; 196 };
225 197
226 return cmd; 198 return cmd;