GNUnet 0.21.1
testing_api_cmd_netjail_stop.c File Reference

Command to stop the netjail script. More...

Include dependency graph for testing_api_cmd_netjail_stop.c:

Go to the source code of this file.

Data Structures

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

Macros

#define NETJAIL_STOP_SCRIPT   "netjail_stop.sh"
 

Functions

static void netjail_stop_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, long unsigned int exit_code)
 Callback which will be called if the setup script finished. More...
 
static void netjail_stop_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 The run method starts the script which deletes the network namespaces. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_stop (const char *label, char *topology_config, unsigned int *read_file)
 This command executes a shell script to remove the netjail environment. More...
 

Detailed Description

Command to stop the netjail script.

Author
t3sserakt

Definition in file testing_api_cmd_netjail_stop.c.

Macro Definition Documentation

◆ NETJAIL_STOP_SCRIPT

#define NETJAIL_STOP_SCRIPT   "netjail_stop.sh"

Definition at line 34 of file testing_api_cmd_netjail_stop.c.

Function Documentation

◆ netjail_stop_cleanup()

static void netjail_stop_cleanup ( void *  cls)
static

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

Definition at line 73 of file testing_api_cmd_netjail_stop.c.

74{
75 struct NetJailState *ns = cls;
76
77 if (NULL != ns->cwh)
78 {
80 ns->cwh = NULL;
81 }
82 if (NULL != ns->stop_proc)
83 {
84 GNUNET_assert (0 ==
85 GNUNET_OS_process_kill (ns->stop_proc,
86 SIGKILL));
88 GNUNET_OS_process_wait (ns->stop_proc));
89 GNUNET_OS_process_destroy (ns->stop_proc);
90 ns->stop_proc = NULL;
91 }
93}
static struct GNUNET_NAMECACHE_Handle * ns
Handle to the namecache.
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.
#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:877
Struct to hold information for callbacks.

References GNUNET_assert, GNUNET_free, 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_stop().

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,
long unsigned int  exit_code 
)
static

Callback which will be called if the setup script finished.

Definition at line 101 of file testing_api_cmd_netjail_stop.c.

104{
105 struct NetJailState *ns = cls;
106
107 ns->cwh = NULL;
108 GNUNET_OS_process_destroy (ns->stop_proc);
109 ns->stop_proc = NULL;
110 if (0 == exit_code)
111 {
113 }
114 else
115 {
117 }
118}
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.

References exit_code, GNUNET_OS_process_destroy(), GNUNET_TESTING_async_fail(), GNUNET_TESTING_async_finish(), and ns.

Referenced by netjail_stop_run().

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

◆ netjail_stop_run()

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

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

Parameters
clsclosure.
isinterpreter state.

Definition at line 128 of file testing_api_cmd_netjail_stop.c.

130{
131 struct NetJailState *ns = cls;
132 char *pid;
133 char *data_dir;
134 char *script_name;
135 char *read_file;
136
137
139 GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_STOP_SCRIPT);
140 GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
141 unsigned int helper_check = GNUNET_OS_check_helper_binary (
142 script_name,
144 NULL);
145
146 if (GNUNET_NO == helper_check)
147 {
149 "No SUID for %s!\n",
150 script_name);
152 }
153 else if (GNUNET_NO == helper_check)
154 {
156 "%s not found!\n",
157 script_name);
159 }
160
162 "%u",
163 getpid ());
164 {
165 char *const script_argv[] = {script_name,
166 ns->topology_config,
167 pid,
168 read_file,
169 NULL};
171 NULL,
172 NULL,
173 NULL,
174 script_name,
175 script_argv);
176 }
177 ns->cwh = GNUNET_wait_child (ns->stop_proc,
179 ns);
180 GNUNET_break (NULL != ns->cwh);
183}
struct GNUNET_TESTING_Interpreter * is
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
#define GNUNET_log(kind,...)
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_YES
@ GNUNET_NO
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
char * GNUNET_OS_installation_get_path(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:573
@ 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/)
enum GNUNET_GenericReturnValue read_file(char const *const filename, char **buffer)
Definition: pabc_helper.c:71
static void child_completed_callback(void *cls, enum GNUNET_OS_ProcessStatusType type, long unsigned int exit_code)
Callback which will be called if the setup script finished.
#define NETJAIL_STOP_SCRIPT

References child_completed_callback(), GNUNET_asprintf(), GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OS_check_helper_binary(), GNUNET_OS_INHERIT_STD_ERR, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_DATADIR, GNUNET_OS_start_process_vap(), GNUNET_TESTING_interpreter_fail(), GNUNET_wait_child(), GNUNET_YES, is, NETJAIL_STOP_SCRIPT, ns, pid, and read_file().

Referenced by GNUNET_TESTING_cmd_netjail_stop().

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

◆ GNUNET_TESTING_cmd_netjail_stop()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_stop ( const char *  label,
char *  topology_config,
unsigned int *  read_file 
)

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

Parameters
labelname for command.
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 187 of file testing_api_cmd_netjail_stop.c.

190{
191 struct NetJailState *ns;
192
193 ns = GNUNET_new (struct NetJailState);
194 ns->topology_config = topology_config;
195 ns->read_file = read_file;
196 return GNUNET_TESTING_command_new (ns, label,
199 NULL, &ns->ac);
200}
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new(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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
char * topology_config
Configuration file for the test topology.
static void netjail_stop_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
static void netjail_stop_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method starts the script which deletes the network namespaces.

References GNUNET_new, GNUNET_TESTING_command_new(), netjail_stop_cleanup(), netjail_stop_run(), ns, read_file(), and NetJailState::topology_config.

Here is the call graph for this function: