GNUnet 0.22.2
testing_api_cmd_netjail_start.c File Reference

Command to start the netjail script. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
#include "testing_api_topology.h"
Include dependency graph for testing_api_cmd_netjail_start.c:

Go to the source code of this file.

Data Structures

struct  NetJailState
 Struct to hold information for callbacks. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log (kind, __VA_ARGS__)
 

Functions

static void netjail_start_cleanup (void *cls)
 The cleanup function of this cmd frees resources the cmd allocated. More...
 
static void child_completed_callback (void *cls, enum GNUNET_OS_ProcessStatusType type, unsigned long int exit_code)
 Callback which will be called if the setup script finished. More...
 
static void netjail_start_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 The run method starts the script which setup the network namespaces. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_setup (const char *label, const char *script, const char *topology_cmd_label)
 This command executes a shell script to setup the netjail environment. More...
 

Detailed Description

Command to start the netjail script.

Author
t3sserakt

Definition in file testing_api_cmd_netjail_start.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log (kind, __VA_ARGS__)

Definition at line 31 of file testing_api_cmd_netjail_start.c.

Function Documentation

◆ netjail_start_cleanup()

static void netjail_start_cleanup ( void *  cls)
static

The cleanup function of this cmd frees resources the cmd allocated.

Definition at line 69 of file testing_api_cmd_netjail_start.c.

70{
71 struct NetJailState *ns = cls;
72
74 "netjail_start_cleanup!\n");
75 if (NULL != ns->cwh)
76 {
78 ns->cwh = NULL;
79 }
80 if (NULL != ns->start_proc)
81 {
82 GNUNET_assert (0 ==
83 GNUNET_OS_process_kill (ns->start_proc,
84 SIGKILL));
86 GNUNET_OS_process_wait (ns->start_proc));
87 GNUNET_OS_process_destroy (ns->start_proc);
88 ns->start_proc = NULL;
89 }
91}
static struct GNUNET_NAMECACHE_Handle * ns
Handle to the namecache.
#define GNUNET_log(kind,...)
void GNUNET_wait_child_cancel(struct GNUNET_ChildWaitHandle *cwh)
Stop waiting on this child.
@ GNUNET_OK
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:260
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:210
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:871
Struct to hold information for callbacks.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_OS_process_destroy(), GNUNET_OS_process_kill(), GNUNET_OS_process_wait(), GNUNET_wait_child_cancel(), and ns.

Referenced by GNUNET_TESTING_cmd_netjail_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ child_completed_callback()

static void child_completed_callback ( void *  cls,
enum GNUNET_OS_ProcessStatusType  type,
unsigned long int  exit_code 
)
static

Callback which will be called if the setup script finished.

Definition at line 98 of file testing_api_cmd_netjail_start.c.

101{
102 struct NetJailState *ns = cls;
103
104 GNUNET_OS_process_destroy (ns->start_proc);
105 ns->start_proc = NULL;
106 ns->cwh = NULL;
107 if ( (GNUNET_OS_PROCESS_EXITED != type) ||
108 (0 != exit_code) )
109 {
111 "Child failed with error %lu!\n",
112 exit_code);
114 return;
115 }
117}
static uint32_t type
Type string converted to DNS type value.
static int exit_code
Global exit code.
Definition: gnunet-qr.c:43
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_OS_PROCESS_EXITED
The process exited with a return code.

References exit_code, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OS_process_destroy(), GNUNET_OS_PROCESS_EXITED, GNUNET_TESTING_async_fail(), GNUNET_TESTING_async_finish(), ns, and type.

Referenced by netjail_start_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netjail_start_run()

static void netjail_start_run ( void *  cls,
struct GNUNET_TESTING_Interpreter is 
)
static

The run method starts the script which setup the network namespaces.

Parameters
clsclosure.
isinterpreter state.

Definition at line 127 of file testing_api_cmd_netjail_start.c.

129{
130 struct NetJailState *ns = cls;
131 const struct GNUNET_TESTING_Command *topo_cmd;
132 char pid[15];
133 enum GNUNET_GenericReturnValue helper_check;
134 char *data_dir;
135 char *script_name;
136 const char *topology_data;
137
139 is,
140 ns->topology_cmd_label);
141 if (NULL == topo_cmd)
143 if (GNUNET_OK !=
144 GNUNET_TESTING_get_trait_topology_string (topo_cmd,
145 &topology_data))
150 GNUNET_asprintf (&script_name,
151 "%s%s",
152 data_dir,
153 ns->script);
154 helper_check = GNUNET_OS_check_helper_binary (
155 script_name,
156 true,
157 NULL);
158 if (GNUNET_NO == helper_check)
159 {
161 "No SUID for %s!\n",
162 script_name);
164 return;
165 }
166 if (GNUNET_SYSERR == helper_check)
167 {
169 "%s not found!\n",
170 script_name);
172 return;
173 }
174
176 sizeof (pid),
177 "%u",
178 getpid ());
179 {
180 char *const script_argv[] = {
181 script_name,
182 (char *) topology_data,
183 pid,
184 (char*) "0",
185 NULL
186 };
187
188 ns->start_proc
190 NULL,
191 NULL,
192 NULL,
193 script_name,
194 script_argv);
195
196 }
197 ns->cwh = GNUNET_wait_child (ns->start_proc,
199 ns);
200 GNUNET_break (NULL != ns->cwh);
201 GNUNET_free (script_name);
202 GNUNET_free (data_dir);
203}
static struct GNUNET_TESTING_Interpreter * is
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
#define GNUNET_TESTING_FAIL(is)
Print failing line number and trigger shutdown.
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
void GNUNET_TESTING_interpreter_skip(struct GNUNET_TESTING_Interpreter *is)
Skips the current test, the environment is not prepared correctly.
struct GNUNET_ChildWaitHandle * GNUNET_wait_child(struct GNUNET_OS_Process *proc, GNUNET_ChildCompletedCallback cb, void *cb_cls)
Starts the handling of the child processes.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
enum GNUNET_GenericReturnValue GNUNET_OS_check_helper_binary(const char *binary, bool check_suid, const char *params)
Check whether an executable exists and possibly if the suid bit is set on the file.
struct GNUNET_OS_Process * GNUNET_OS_start_process_vap(enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, char *const argv[])
Start a process.
Definition: os_priority.c:567
@ GNUNET_OS_INHERIT_STD_ERR
When this flag is set, the child process will inherit stderr of the parent.
Definition: gnunet_os_lib.h:95
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
A command to be run by the interpreter.
static void child_completed_callback(void *cls, enum GNUNET_OS_ProcessStatusType type, unsigned long int exit_code)
Callback which will be called if the setup script finished.

References child_completed_callback(), GNUNET_asprintf(), GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_OS_check_helper_binary(), GNUNET_OS_INHERIT_STD_ERR, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_DATADIR, GNUNET_OS_project_data_gnunet(), GNUNET_OS_start_process_vap(), GNUNET_snprintf(), GNUNET_SYSERR, GNUNET_TESTING_FAIL, GNUNET_TESTING_interpreter_lookup_command(), GNUNET_TESTING_interpreter_skip(), GNUNET_wait_child(), is, ns, and pid.

Referenced by GNUNET_TESTING_cmd_netjail_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_netjail_setup()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_setup ( const char *  label,
const char *  script,
const char *  topology_cmd_label 
)

This command executes a shell script to setup the netjail environment.

Parameters
labelname for command.
scriptwhich script to run, e.g. GNUNET_TESTING_NETJAIL_START_SCRIPT
topology_configConfiguration file for the test topology.
read_fileFlag indicating if the the name of the topology file is send to the helper, or a string with the topology data.
Returns
command.

Definition at line 207 of file testing_api_cmd_netjail_start.c.

211{
212 struct NetJailState *ns;
213
214 ns = GNUNET_new (struct NetJailState);
215 ns->script = script;
216 ns->topology_cmd_label = topology_cmd_label;
218 ns,
219 label,
222 NULL,
223 &ns->ac);
224}
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new_ac(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command that may be asynchronous.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
const char * topology_cmd_label
Configuration file for the test topology.
const char * script
Start or stop?
static void netjail_start_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method starts the script which setup the network namespaces.
static void netjail_start_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.

References GNUNET_new, GNUNET_TESTING_command_new_ac(), netjail_start_cleanup(), netjail_start_run(), ns, NetJailState::script, and NetJailState::topology_cmd_label.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function: