GNUnet  0.17.6
Data Structures | Macros | Functions
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_ng_lib.h"
#include "gnunet_testing_netjail_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   "netjail_start.sh"
 
#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, long unsigned 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_start (const char *label, char *topology_config, unsigned int *read_file)
 Create command. More...
 

Detailed Description

Command to start the netjail script.

Author
t3sserakt

Definition in file testing_api_cmd_netjail_start.c.

Macro Definition Documentation

◆ NETJAIL_START_SCRIPT

#define NETJAIL_START_SCRIPT   "netjail_start.sh"

Definition at line 31 of file testing_api_cmd_netjail_start.c.

◆ LOG

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

Definition at line 33 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 71 of file testing_api_cmd_netjail_start.c.

72 {
73  struct NetJailState *ns = cls;
74 
76  "netjail_start_cleanup!\n");
77 
78  if (NULL != ns->cwh)
79  {
81  "Cancel child\n");
83  ns->cwh = NULL;
84  }
85  if (NULL != ns->start_proc)
86  {
88  "Kill process\n");
89  GNUNET_assert (0 ==
90  GNUNET_OS_process_kill (ns->start_proc,
91  SIGKILL));
93  GNUNET_OS_process_wait (ns->start_proc));
94  GNUNET_OS_process_destroy (ns->start_proc);
95  ns->start_proc = NULL;
96  }
97  GNUNET_free (ns);
98 }
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
Definition: gnunet-abd.c:41
#define GNUNET_log(kind,...)
void GNUNET_wait_child_cancel(struct GNUNET_ChildWaitHandle *cwh)
Stop waiting on this child.
@ GNUNET_OK
Definition: gnunet_common.h:99
#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:981
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:280
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:217
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:

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

109 {
110  struct NetJailState *ns = cls;
111 
112  GNUNET_OS_process_destroy (ns->start_proc);
113  ns->start_proc = NULL;
114  ns->cwh = NULL;
115  if (0 == exit_code)
116  {
118  }
119  else
120  {
122  "Child failed with error %lu!\n",
123  exit_code);
125  }
126 }
static int exit_code
Global exit code.
Definition: gnunet-qr.c:42
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

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

Here is the call 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 136 of file testing_api_cmd_netjail_start.c.

138 {
139  struct NetJailState *ns = cls;
140  char pid[15];
141  enum GNUNET_GenericReturnValue helper_check;
142  char *data_dir;
143  char *script_name;
144  char *read_file;
145 
147  GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_START_SCRIPT);
148  GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
149 
150  helper_check = GNUNET_OS_check_helper_binary (
151  script_name,
152  GNUNET_YES,
153  NULL);
154 
156  "script_name %s\n",
157  script_name);
158 
159  if (GNUNET_NO == helper_check)
160  {
162  "No SUID for %s!\n",
163  script_name);
165  return;
166  }
167  if (GNUNET_SYSERR == helper_check)
168  {
170  "%s not found!\n",
171  script_name);
173  return;
174  }
175 
177  sizeof (pid),
178  "%u",
179  getpid ());
180  {
181  char *const script_argv[] = {
182  script_name,
183  ns->topology_config,
184  pid,
185  read_file,
186  NULL
187  };
188 
189  ns->start_proc
191  NULL,
192  NULL,
193  NULL,
194  script_name,
195  script_argv);
196 
197  }
198  ns->cwh = GNUNET_wait_child (ns->start_proc,
200  ns);
201  GNUNET_break (NULL != ns->cwh);
203  GNUNET_free (script_name);
204  GNUNET_free (data_dir);
205 }
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
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.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:96
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
Definition: gnunet_common.h:98
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
#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.
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:598
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.
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,...
@ 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:70
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 LOG(kind,...)
#define NETJAIL_START_SCRIPT

◆ GNUNET_TESTING_cmd_netjail_start()

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

Create command.

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

Definition at line 136 of file testing_api_cmd_netjail_start.c.

219 {
220  struct NetJailState *ns;
221 
222  ns = GNUNET_new (struct NetJailState);
223  ns->topology_config = topology_config;
224  ns->read_file = read_file;
225  {
226  struct GNUNET_TESTING_Command cmd = {
227  .cls = ns,
228  .label = label,
229  .run = &netjail_start_run,
230  .ac = &ns->ac,
231  .cleanup = &netjail_start_cleanup
232  };
233 
234  return cmd;
235  }
236 }
#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 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.