aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_netjail_stop_v2.c
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-10-14 16:39:24 +0200
committert3sserakt <t3ss@posteo.de>2021-10-14 16:39:24 +0200
commitd64ac269856744b9bab170964e1d6f36896ecc55 (patch)
treeed5aa79b91fe3cf9388433a5611581b7ce3b846c /src/testing/testing_api_cmd_netjail_stop_v2.c
parent003910fc614cd347919707d1bf3c37a939978459 (diff)
downloadgnunet-d64ac269856744b9bab170964e1d6f36896ecc55.tar.gz
gnunet-d64ac269856744b9bab170964e1d6f36896ecc55.zip
removed versioned artefacts with v2 and v3. changes to reflect the changes in testing_api_loop.c
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_stop_v2.c')
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_v2.c185
1 files changed, 0 insertions, 185 deletions
diff --git a/src/testing/testing_api_cmd_netjail_stop_v2.c b/src/testing/testing_api_cmd_netjail_stop_v2.c
deleted file mode 100644
index a0e2657cb..000000000
--- a/src/testing/testing_api_cmd_netjail_stop_v2.c
+++ /dev/null
@@ -1,185 +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_netjail_stop_v2.c
23 * @brief Command to stop 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
30
31#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop_v2.sh"
32
33// Child Wait handle
34static struct GNUNET_ChildWaitHandle *cwh;
35
36/**
37 * Struct to hold information for callbacks.
38 *
39 */
40struct NetJailState
41{
42 /**
43 * Context for our asynchronous completion.
44 */
45 struct GNUNET_TESTING_AsyncContext ac;
46
47 /**
48 * Configuration file for the test topology.
49 */
50 char *topology_config;
51
52 /**
53 * The process id of the start script.
54 */
55 struct GNUNET_OS_Process *stop_proc;
56
57};
58
59
60/**
61 * The cleanup function of this cmd frees resources the cmd allocated.
62 *
63 */
64static void
65netjail_stop_cleanup (void *cls)
66{
67 struct NetJailState *ns = cls;
68
69 if (NULL != cwh)
70 {
71 GNUNET_wait_child_cancel (cwh);
72 cwh = NULL;
73 }
74 if (NULL != ns->stop_proc)
75 {
76 GNUNET_assert (0 ==
77 GNUNET_OS_process_kill (ns->stop_proc,
78 SIGKILL));
79 GNUNET_assert (GNUNET_OK ==
80 GNUNET_OS_process_wait (ns->stop_proc));
81 GNUNET_OS_process_destroy (ns->stop_proc);
82 ns->stop_proc = NULL;
83 }
84}
85
86
87/**
88 * Callback which will be called if the setup script finished.
89 *
90 */
91static void
92child_completed_callback (void *cls,
93 enum GNUNET_OS_ProcessStatusType type,
94 long unsigned int exit_code)
95{
96 struct NetJailState *ns = cls;
97
98 cwh = NULL; // WTF? globals!?!?!
99 GNUNET_OS_process_destroy (ns->stop_proc);
100 ns->stop_proc = NULL;
101 if (0 == exit_code)
102 {
103 GNUNET_TESTING_async_finish (&ns->ac);
104 }
105 else
106 {
107 GNUNET_TESTING_async_fail (&ns->ac);
108 }
109}
110
111
112/**
113* The run method starts the script which deletes the network namespaces.
114*
115* @param cls closure.
116* @param is interpreter state.
117*/
118static void
119netjail_stop_run (void *cls,
120 struct GNUNET_TESTING_Interpreter *is)
121{
122 struct NetJailState *ns = cls;
123 char *pid;
124
125 GNUNET_asprintf (&pid,
126 "%u",
127 getpid ());
128 char *const script_argv[] = {NETJAIL_STOP_SCRIPT,
129 ns->topology_config,
130 pid,
131 NULL};
132 unsigned int helper_check = GNUNET_OS_check_helper_binary (
133 NETJAIL_STOP_SCRIPT,
134 GNUNET_YES,
135 NULL);
136
137 if (GNUNET_NO == helper_check)
138 {
139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
140 "No SUID for %s!\n",
141 NETJAIL_STOP_SCRIPT);
142 GNUNET_TESTING_interpreter_fail (is);
143 }
144 else if (GNUNET_NO == helper_check)
145 {
146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
147 "%s not found!\n",
148 NETJAIL_STOP_SCRIPT);
149 GNUNET_TESTING_interpreter_fail (is);
150 }
151
152 ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
153 NULL,
154 NULL,
155 NULL,
156 NETJAIL_STOP_SCRIPT,
157 script_argv);
158
159 cwh = GNUNET_wait_child (ns->stop_proc,
160 &child_completed_callback,
161 ns);
162 GNUNET_break (NULL != cwh);
163}
164
165
166struct GNUNET_TESTING_Command
167GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label,
168 char *topology_config)
169{
170 struct NetJailState *ns;
171
172 ns = GNUNET_new (struct NetJailState);
173 ns->topology_config = topology_config;
174 {
175 struct GNUNET_TESTING_Command cmd = {
176 .cls = ns,
177 .label = label,
178 .run = &netjail_stop_run,
179 .ac = &ns->ac,
180 .cleanup = &netjail_stop_cleanup
181 };
182
183 return cmd;
184 }
185}