GNUnet  0.17.6
Data Structures | Macros | Functions
testing_api_cmd_netjail_stop.c File Reference

Command to stop 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_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)
 Create command. 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 32 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 71 of file testing_api_cmd_netjail_stop.c.

72 {
73  struct NetJailState *ns = cls;
74 
75  if (NULL != ns->cwh)
76  {
78  ns->cwh = NULL;
79  }
80  if (NULL != ns->stop_proc)
81  {
82  GNUNET_assert (0 ==
83  GNUNET_OS_process_kill (ns->stop_proc,
84  SIGKILL));
86  GNUNET_OS_process_wait (ns->stop_proc));
87  GNUNET_OS_process_destroy (ns->stop_proc);
88  ns->stop_proc = NULL;
89  }
90  GNUNET_free (ns);
91 }
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:99
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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_free, 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 99 of file testing_api_cmd_netjail_stop.c.

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

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 126 of file testing_api_cmd_netjail_stop.c.

128 {
129  struct NetJailState *ns = cls;
130  char *pid;
131  char *data_dir;
132  char *script_name;
133  char *read_file;
134 
135 
137  GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_STOP_SCRIPT);
138  GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
139  unsigned int helper_check = GNUNET_OS_check_helper_binary (
140  script_name,
141  GNUNET_YES,
142  NULL);
143 
144  if (GNUNET_NO == helper_check)
145  {
147  "No SUID for %s!\n",
148  script_name);
150  }
151  else if (GNUNET_NO == helper_check)
152  {
154  "%s not found!\n",
155  script_name);
157  }
158 
160  "%u",
161  getpid ());
162  {
163  char *const script_argv[] = {script_name,
164  ns->topology_config,
165  pid,
166  read_file,
167  NULL};
169  NULL,
170  NULL,
171  NULL,
172  script_name,
173  script_argv);
174  }
175  ns->cwh = GNUNET_wait_child (ns->stop_proc,
177  ns);
178  GNUNET_break (NULL != ns->cwh);
179 }
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.
#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
Definition: gnunet_common.h:98
#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.
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 NETJAIL_STOP_SCRIPT

References child_completed_callback(), GNUNET_asprintf(), GNUNET_break, GNUNET_ERROR_TYPE_ERROR, 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().

Here is the call 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 
)

Create command.

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 126 of file testing_api_cmd_netjail_stop.c.

186 {
187  struct NetJailState *ns;
188 
189  ns = GNUNET_new (struct NetJailState);
190  ns->topology_config = topology_config;
191  ns->read_file = read_file;
192  {
193  struct GNUNET_TESTING_Command cmd = {
194  .cls = ns,
195  .label = label,
196  .run = &netjail_stop_run,
197  .ac = &ns->ac,
198  .cleanup = &netjail_stop_cleanup
199  };
200 
201  return cmd;
202  }
203 }
#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_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.