GNUnet  0.11.x
Data Structures | Macros | Functions
testing_api_cmd_netjail_start.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_start.c:

Go to the source code of this file.

Data Structures

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

Macros

#define NETJAIL_START_SCRIPT   "./../testing/netjail_start.sh"
 

Functions

static void netjail_start_cleanup (void *cls, const struct GNUNET_TESTING_Command *cmd)
 The cleanup function of this cmd frees resources the cmd allocated. More...
 
static int netjail_start_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_start_run (void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
 The run method starts the script which setup the network namespaces. More...
 
static int netjail_start_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_start (const char *label, char *local_m, char *global_n)
 Create command. More...
 

Macro Definition Documentation

◆ NETJAIL_START_SCRIPT

#define NETJAIL_START_SCRIPT   "./../testing/netjail_start.sh"

Definition at line 30 of file testing_api_cmd_netjail_start.c.

Function Documentation

◆ netjail_start_cleanup()

static void netjail_start_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_start.c.

64 {
65  struct NetJailState *ns = cls;
66 
68  "netjail_start_cleanup!\n");
69 
70  if (NULL != ns->cwh)
71  {
73  ns->cwh = NULL;
74  }
75  if (NULL != ns->start_proc)
76  {
77  GNUNET_assert (0 ==
78  GNUNET_OS_process_kill (ns->start_proc,
79  SIGKILL));
81  GNUNET_OS_process_wait (ns->start_proc));
82  GNUNET_OS_process_destroy (ns->start_proc);
83  ns->start_proc = NULL;
84  }
85  GNUNET_free (ns);
86 }
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.
#define GNUNET_log(kind,...)
@ GNUNET_OK
Definition: gnunet_common.h:95
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
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.

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.

Here is the call graph for this function:

◆ netjail_start_traits()

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

Trait function of this cmd does nothing.

Definition at line 94 of file testing_api_cmd_netjail_start.c.

98 {
99  return GNUNET_OK;
100 }

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 108 of file testing_api_cmd_netjail_start.c.

111 {
112  struct NetJailState *ns = cls;
113 
114  if (0 == exit_code)
115  {
116  ns->finished = GNUNET_YES;
117  }
118  else
119  {
121  "Child completed with an error!\n");
122  ns->finished = GNUNET_SYSERR;
123  }
124  GNUNET_OS_process_destroy (ns->start_proc);
125  ns->start_proc = NULL;
126 }
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
@ GNUNET_ERROR_TYPE_ERROR

References exit_code, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OS_process_destroy(), GNUNET_SYSERR, GNUNET_YES, and ns.

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,
const struct GNUNET_TESTING_Command cmd,
struct GNUNET_TESTING_Interpreter is 
)
static

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

Parameters
clsclosure.
cmdCMD being run.
isinterpreter state.

Definition at line 138 of file testing_api_cmd_netjail_start.c.

141 {
142  struct NetJailState *ns = cls;
143  char *const script_argv[] = {NETJAIL_START_SCRIPT,
144  ns->local_m,
145  ns->global_n,
146  NULL};
147  unsigned int helper_check = GNUNET_OS_check_helper_binary (
149  GNUNET_YES,
150  NULL);
151 
152  if (GNUNET_NO == helper_check)
153  {
155  "No SUID for %s!\n",
158  }
159  else if (GNUNET_NO == helper_check)
160  {
162  "%s not found!\n",
165  }
166 
168  NULL,
169  NULL,
170  NULL,
172  script_argv);
173 
174  ns->cwh = GNUNET_wait_child (ns->start_proc,
176  ns);
177  GNUNET_break (NULL != ns->cwh);
178 }
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_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.
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_START_SCRIPT

References child_completed_callback(), 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_START_SCRIPT, and ns.

Here is the call graph for this function:

◆ netjail_start_finish()

static int netjail_start_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 186 of file testing_api_cmd_netjail_start.c.

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

References ns.

◆ GNUNET_TESTING_cmd_netjail_start()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_netjail_start ( const char *  label,
char *  local_m,
char *  global_n 
)

Create command.

Parameters
labelname for command.
local_mNumber of local nodes in each namespace.
global_nThe number of namespaces.
Returns
command.

Definition at line 186 of file testing_api_cmd_netjail_start.c.

211 {
212  struct NetJailState *ns;
213 
214  ns = GNUNET_new (struct NetJailState);
215  ns->local_m = local_m;
216  ns->global_n = global_n;
217  ns->finished = GNUNET_NO;
218 
219  struct GNUNET_TESTING_Command cmd = {
220  .cls = ns,
221  .label = label,
222  .run = &netjail_start_run,
223  .finish = &netjail_start_finish,
224  .cleanup = &netjail_start_cleanup,
225  .traits = &netjail_start_traits
226  };
227 
228  return cmd;
229 }
#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 * local_m
Number of nodes in a network namespace.
char * global_n
Number of network namespaces.
static int netjail_start_traits(void *cls, const void **ret, const char *trait, unsigned int index)
Trait function of this cmd does nothing.
static void netjail_start_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
The cleanup function of this cmd frees resources the cmd allocated.
static int netjail_start_finish(void *cls, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
This function checks the flag NetJailState::finished, if this cmd finished.
static void netjail_start_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
The run method starts the script which setup the network namespaces.