aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_cmd_netjail_start.c
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-08-17 19:57:12 +0200
committert3sserakt <t3ss@posteo.de>2021-08-17 19:57:12 +0200
commit32a8c505c1fa27bb43c4e7c8d288566d51417f56 (patch)
tree0328fe50b6a099b5020fe6d1e01cbd6b96ecd18a /src/testbed/testbed_api_cmd_netjail_start.c
parent1e063cd73452396778cf00127346b9b08a922317 (diff)
downloadgnunet-32a8c505c1fa27bb43c4e7c8d288566d51417f56.tar.gz
gnunet-32a8c505c1fa27bb43c4e7c8d288566d51417f56.zip
- moved test code from testbed to testing
Diffstat (limited to 'src/testbed/testbed_api_cmd_netjail_start.c')
-rw-r--r--src/testbed/testbed_api_cmd_netjail_start.c218
1 files changed, 0 insertions, 218 deletions
diff --git a/src/testbed/testbed_api_cmd_netjail_start.c b/src/testbed/testbed_api_cmd_netjail_start.c
deleted file mode 100644
index 0cc020275..000000000
--- a/src/testbed/testbed_api_cmd_netjail_start.c
+++ /dev/null
@@ -1,218 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet 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 GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing/testing_api_cmd_hello_world.c
23 * @brief Command to start the netjail script.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testbed_ng_service.h"
30
31#define NETJAIL_START_SCRIPT "./../testing/netjail_start.sh"
32
33struct NetJailState
34{
35 struct GNUNET_ChildWaitHandle *cwh;
36
37 char *local_m;
38
39 char *global_n;
40
41 /**
42 * The process id of the start script.
43 */
44 struct GNUNET_OS_Process *start_proc;
45
46 unsigned int finished;
47};
48
49
50/**
51*
52*
53* @param cls closure
54* @param cmd current CMD being cleaned up.
55*/
56static void
57netjail_start_cleanup (void *cls,
58 const struct GNUNET_TESTING_Command *cmd)
59{
60 struct NetJailState *ns = cls;
61
62 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
63 "netjail_start_cleanup!\n");
64
65 if (NULL != ns->cwh)
66 {
67 GNUNET_wait_child_cancel (ns->cwh);
68 ns->cwh = NULL;
69 }
70 if (NULL != ns->start_proc)
71 {
72 GNUNET_assert (0 ==
73 GNUNET_OS_process_kill (ns->start_proc,
74 SIGKILL));
75 GNUNET_assert (GNUNET_OK ==
76 GNUNET_OS_process_wait (ns->start_proc));
77 GNUNET_OS_process_destroy (ns->start_proc);
78 ns->start_proc = NULL;
79 }
80 GNUNET_free (ns);
81}
82
83
84/**
85*
86*
87* @param cls closure.
88* @param[out] ret result
89* @param trait name of the trait.
90* @param index index number of the object to offer.
91* @return #GNUNET_OK on success.
92*/
93static int
94netjail_start_traits (void *cls,
95 const void **ret,
96 const char *trait,
97 unsigned int index)
98{
99 return GNUNET_OK;
100}
101
102static void
103child_completed_callback (void *cls,
104 enum GNUNET_OS_ProcessStatusType type,
105 long unsigned int exit_code)
106{
107 struct NetJailState *ns = cls;
108
109 if (0 == exit_code)
110 {
111 ns->finished = GNUNET_YES;
112 }
113 else
114 {
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
116 "Child completed with an error!\n");
117 ns->finished = GNUNET_SYSERR;
118 }
119 GNUNET_OS_process_destroy (ns->start_proc);
120 ns->start_proc = NULL;
121}
122
123
124
125/**
126* Run the "hello world" CMD.
127*
128* @param cls closure.
129* @param cmd CMD being run.
130* @param is interpreter state.
131*/
132static void
133netjail_start_run (void *cls,
134 const struct GNUNET_TESTING_Command *cmd,
135 struct GNUNET_TESTING_Interpreter *is)
136{
137 struct NetJailState *ns = cls;
138 char *const script_argv[] = {NETJAIL_START_SCRIPT,
139 ns->local_m,
140 ns->global_n,
141 NULL};
142 unsigned int helper_check = GNUNET_OS_check_helper_binary (
143 NETJAIL_START_SCRIPT,
144 GNUNET_YES,
145 NULL);
146
147 if (GNUNET_NO == helper_check)
148 {
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150 "No SUID for %s!\n",
151 NETJAIL_START_SCRIPT);
152 GNUNET_TESTING_interpreter_fail ();
153 }
154 else if (GNUNET_NO == helper_check)
155 {
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
157 "%s not found!\n",
158 NETJAIL_START_SCRIPT);
159 GNUNET_TESTING_interpreter_fail ();
160 }
161
162 ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
163 NULL,
164 NULL,
165 NULL,
166 NETJAIL_START_SCRIPT,
167 script_argv);
168
169 ns->cwh = GNUNET_wait_child (ns->start_proc,
170 &child_completed_callback,
171 ns);
172 GNUNET_break (NULL != ns->cwh);
173}
174
175static int
176netjail_start_finish (void *cls,
177 GNUNET_SCHEDULER_TaskCallback cont,
178 void *cont_cls)
179{
180 struct NetJailState *ns = cls;
181
182 if (ns->finished)
183 {
184 cont (cont_cls);
185 }
186 return ns->finished;
187}
188
189/**
190 * Create command.
191 *
192 * @param label name for command.
193 * @param binaryname to start.
194 * @return command.
195 */
196struct GNUNET_TESTING_Command
197GNUNET_TESTING_cmd_netjail_start (const char *label,
198 char *local_m,
199 char *global_n)
200{
201 struct NetJailState *ns;
202
203 ns = GNUNET_new (struct NetJailState);
204 ns->local_m = local_m;
205 ns->global_n = global_n;
206 ns->finished = GNUNET_NO;
207
208 struct GNUNET_TESTING_Command cmd = {
209 .cls = ns,
210 .label = label,
211 .run = &netjail_start_run,
212 .finish = &netjail_start_finish,
213 .cleanup = &netjail_start_cleanup,
214 .traits = &netjail_start_traits
215 };
216
217 return cmd;
218}