GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
testing_api_cmd_netjail_stop_v2.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
Include dependency graph for testing_api_cmd_netjail_stop_v2.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   "./../testing/netjail_stop_v2.sh"
 

Functions

static void netjail_stop_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd)
 The cleanup function of this cmd frees resources the cmd allocated. More...
 
static int netjail_stop_traits (void *cls, const void **ret, const char *trait, unsigned int index)
 Trait function of this cmd does nothing. 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, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
 The run method starts the script which deletes the network namespaces. More...
 
static int netjail_stop_finish (void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
 This function checks the flag NetJailState::finished, if this cmd finished. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label, char *topology_config)
 Create command. More...
 

Variables

static struct GNUNET_ChildWaitHandlecwh
 

Macro Definition Documentation

◆ NETJAIL_STOP_SCRIPT

#define NETJAIL_STOP_SCRIPT   "./../testing/netjail_stop_v2.sh"

Definition at line 31 of file testing_api_cmd_netjail_stop_v2.c.

Function Documentation

◆ netjail_stop_cleanup()

static void netjail_stop_cleanup ( void *  cls,
const struct GNUNET_TESTING_Command cmd 
)
static

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

Definition at line 62 of file testing_api_cmd_netjail_stop_v2.c.

64 {
65  struct NetJailState *ns = cls;
66 
67  if (NULL != cwh)
68  {
70  cwh = NULL;
71  }
72  if (NULL != ns->stop_proc)
73  {
74  GNUNET_assert (0 ==
75  GNUNET_OS_process_kill (ns->stop_proc,
76  SIGKILL));
78  GNUNET_OS_process_wait (ns->stop_proc));
79  GNUNET_OS_process_destroy (ns->stop_proc);
80  ns->stop_proc = NULL;
81  }
82 }
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
Definition: gnunet-abd.c:41
void GNUNET_wait_child_cancel(struct GNUNET_ChildWaitHandle *cwh)
Stop waiting on this child.
@ GNUNET_OK
Definition: gnunet_common.h:95
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:983
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:286
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:224
Struct to hold information for callbacks.
static struct GNUNET_ChildWaitHandle * cwh

References cwh, GNUNET_assert, GNUNET_OK, GNUNET_OS_process_destroy(), GNUNET_OS_process_kill(), GNUNET_OS_process_wait(), GNUNET_wait_child_cancel(), and ns.

Here is the call graph for this function:

◆ netjail_stop_traits()

static int netjail_stop_traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)
static

Trait function of this cmd does nothing.

Definition at line 90 of file testing_api_cmd_netjail_stop_v2.c.

94 {
95  return GNUNET_OK;
96 }

References GNUNET_OK.

◆ 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 104 of file testing_api_cmd_netjail_stop_v2.c.

107 {
108  struct NetJailState *ns = cls;
109 
110  cwh = NULL;
111  if (0 == exit_code)
112  {
113  ns->finished = GNUNET_YES;
114  }
115  else
116  {
117  ns->finished = GNUNET_SYSERR;
118  }
119  GNUNET_OS_process_destroy (ns->stop_proc);
120  ns->stop_proc = NULL;
121 }
static long unsigned int exit_code
Handler exit code.
Definition: gnunet-qr.c:54
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_SYSERR
Definition: gnunet_common.h:93

References cwh, exit_code, GNUNET_OS_process_destroy(), GNUNET_SYSERR, GNUNET_YES, 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,
const struct GNUNET_TESTING_Command cmd,
struct GNUNET_TESTING_Interpreter is 
)
static

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

Parameters
clsclosure.
cmdCMD being run.
isinterpreter state.

Definition at line 132 of file testing_api_cmd_netjail_stop_v2.c.

135 {
136  struct NetJailState *ns = cls;
137  char *pid;
139  "%u",
140  getpid ());
141  char *const script_argv[] = {NETJAIL_STOP_SCRIPT,
142  ns->topology_config,
143  pid,
144  NULL};
145  unsigned int helper_check = GNUNET_OS_check_helper_binary (
147  GNUNET_YES,
148  NULL);
149 
150  if (GNUNET_NO == helper_check)
151  {
153  "No SUID for %s!\n",
156  }
157  else if (GNUNET_NO == helper_check)
158  {
160  "%s not found!\n",
163  }
164 
166  NULL,
167  NULL,
168  NULL,
170  script_argv);
171 
172  cwh = GNUNET_wait_child (ns->stop_proc,
174  ns);
175  GNUNET_break (NULL != cwh);
176 
177 }
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
struct GNUNET_ChildWaitHandle * GNUNET_wait_child(struct GNUNET_OS_Process *proc, GNUNET_ChildCompletedCallback cb, void *cb_cls)
Starts the handling of the child processes.
#define GNUNET_log(kind,...)
@ GNUNET_NO
Definition: gnunet_common.h:94
void GNUNET_TESTING_interpreter_fail()
Current command failed, clean up and fail the test case.
#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.
int GNUNET_OS_check_helper_binary(const char *binary, int 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:604
@ GNUNET_OS_INHERIT_STD_ERR
When this flag is set, the child process will inherit stderr of the parent.
Definition: gnunet_os_lib.h:91
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(), cwh, GNUNET_asprintf(), GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_NO, GNUNET_OS_check_helper_binary(), GNUNET_OS_INHERIT_STD_ERR, GNUNET_OS_start_process_vap(), GNUNET_TESTING_interpreter_fail(), GNUNET_wait_child(), GNUNET_YES, NETJAIL_STOP_SCRIPT, ns, and pid.

Here is the call graph for this function:

◆ netjail_stop_finish()

static int netjail_stop_finish ( void *  cls,
GNUNET_SCHEDULER_TaskCallback  cont,
void *  cont_cls 
)
static

This function checks the flag NetJailState::finished, if this cmd finished.

Definition at line 185 of file testing_api_cmd_netjail_stop_v2.c.

188 {
189  struct NetJailState *ns = cls;
190 
191  if (ns->finished)
192  {
193  cont (cont_cls);
194  }
195  return ns->finished;
196 }

References ns.

◆ GNUNET_TESTING_cmd_netjail_stop_v2()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_stop_v2 ( const char *  label,
char *  topology_config 
)

Create command.

Parameters
labelname for command.
topology_configConfiguration file for the test topology.
Returns
command.

Definition at line 185 of file testing_api_cmd_netjail_stop_v2.c.

209 {
210  struct NetJailState *ns;
211 
212  ns = GNUNET_new (struct NetJailState);
213  ns->topology_config = topology_config;
214 
215  struct GNUNET_TESTING_Command cmd = {
216  .cls = ns,
217  .label = label,
218  .run = &netjail_stop_run,
219  .finish = &netjail_stop_finish,
220  .cleanup = &netjail_stop_cleanup,
221  .traits = &netjail_stop_traits
222  };
223 
224  return cmd;
225 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
A command to be run by the interpreter.
const char * label
Label for the command.
void * cls
Closure for all commands with command-specific context information.
char * topology_config
Configuration file for the test topology.
static int netjail_stop_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Trait function of this cmd does nothing.
static void netjail_stop_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
The cleanup function of this cmd frees resources the cmd allocated.
static int netjail_stop_finish(void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
This function checks the flag NetJailState::finished, if this cmd finished.
static void netjail_stop_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
The run method starts the script which deletes the network namespaces.

Variable Documentation

◆ cwh

struct GNUNET_ChildWaitHandle* cwh
static