GNUnet 0.21.1
testing_api_cmd_exec_bash_script.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
Include dependency graph for testing_api_cmd_exec_bash_script.c:

Go to the source code of this file.

Data Structures

struct  BashScriptState
 

Macros

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

Functions

static void exec_bash_script_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 exec_bash_script_run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 Run method of the command created by the interpreter to wait for another command to finish. More...
 
const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_exec_bash_script (const char *label, const char *script, char *const script_argv[], int argc, GNUNET_ChildCompletedCallback cb)
 Command to execute a script synchronously. More...
 

Macro Definition Documentation

◆ LOG

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

Definition at line 30 of file testing_api_cmd_exec_bash_script.c.

Function Documentation

◆ exec_bash_script_cleanup()

static void exec_bash_script_cleanup ( void *  cls)
static

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

Definition at line 75 of file testing_api_cmd_exec_bash_script.c.

76{
77 struct BashScriptState *bss = cls;
78
79 if (NULL != bss->cwh)
80 {
82 "Cancel child\n");
84 bss->cwh = NULL;
85 }
86 if (NULL != bss->start_proc)
87 {
89 "Kill process\n");
90 GNUNET_assert (0 ==
92 SIGKILL));
96 bss->start_proc = NULL;
97 }
98 GNUNET_free (bss);
99}
#define GNUNET_log(kind,...)
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.
@ GNUNET_ERROR_TYPE_DEBUG
#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 GNUNET_ChildWaitHandle * cwh
struct GNUNET_OS_Process * start_proc
The process id of the script.

References BashScriptState::cwh, 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 BashScriptState::start_proc.

Referenced by GNUNET_TESTING_cmd_exec_bash_script().

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

109{
110 struct BashScriptState *bss = cls;
111
113 bss->start_proc = NULL;
114 bss->cwh = NULL;
115 if (0 == exit_code)
116 {
118 "Child succeeded!\n");
120 }
121 else
122 {
124 "Child failed with error %lu!\n",
125 exit_code);
127 }
128 bss->cb (cls, type, exit_code);
129}
static uint32_t type
Type string converted to DNS type value.
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.
@ GNUNET_ERROR_TYPE_ERROR
struct GNUNET_TESTING_AsyncContext ac
Context for our asynchronous completion.
GNUNET_ChildCompletedCallback cb
Callback handed over to the command, which should be called upon death or completion of the script.

References BashScriptState::ac, BashScriptState::cb, BashScriptState::cwh, exit_code, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OS_process_destroy(), GNUNET_TESTING_async_fail(), GNUNET_TESTING_async_finish(), BashScriptState::start_proc, and type.

Referenced by exec_bash_script_run().

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

◆ exec_bash_script_run()

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

Run method of the command created by the interpreter to wait for another command to finish.

Definition at line 137 of file testing_api_cmd_exec_bash_script.c.

139{
140 struct BashScriptState *bss = cls;
141 enum GNUNET_GenericReturnValue helper_check;
142 char *argv[bss->argc + 2];
143
144 char *data_dir;
145 char *script_name;
146
148 GNUNET_asprintf (&script_name, "%s%s", data_dir, bss->script);
149
150 helper_check = GNUNET_OS_check_helper_binary (
151 script_name,
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 argv[0] = script_name;
176 if (NULL != bss->script_argv)
177 {
178 for (int i = 0; i < bss->argc;i++)
179 argv[i + 1] = bss->script_argv[i];
180 }
181 argv[bss->argc] = NULL;
182
184 NULL,
185 NULL,
186 NULL,
187 script_name,
188 argv);
189 bss->cwh = GNUNET_wait_child (bss->start_proc,
191 bss);
192 GNUNET_break (NULL != bss->cwh);
193}
struct GNUNET_TESTING_Interpreter * is
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
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_GenericReturnValue
Named constants for return values.
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#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.
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/)
const char * script
Script this cmd will execute.
char *const * script_argv
Arguments for the script.
int argc
Size of script_argv.
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,...)

References BashScriptState::argc, child_completed_callback(), BashScriptState::cwh, GNUNET_asprintf(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, 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_SYSERR, GNUNET_TESTING_interpreter_fail(), GNUNET_wait_child(), GNUNET_YES, is, LOG, BashScriptState::script, BashScriptState::script_argv, and BashScriptState::start_proc.

Referenced by GNUNET_TESTING_cmd_exec_bash_script().

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

◆ GNUNET_TESTING_cmd_exec_bash_script()

const struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_exec_bash_script ( const char *  label,
const char *  script,
char *const  script_argv[],
int  argc,
GNUNET_ChildCompletedCallback  cb 
)

Command to execute a script synchronously.

FIXME: is this accurate? How is this limited to BASH scripts or even scripts?

Parameters
labelLabel of the command.
scriptThe name of the script.
script_argvThe arguments of the script.

Definition at line 196 of file testing_api_cmd_exec_bash_script.c.

201{
202 struct BashScriptState *bss;
203
204 bss = GNUNET_new (struct BashScriptState);
205 bss->script = script;
206 bss->script_argv = script_argv; // FIXME this is not just a cast to fix
207 bss->argc = argc;
208 bss->cb = cb;
209
210 return GNUNET_TESTING_command_new (bss,
211 label,
214 NULL,
215 &bss->ac);
216}
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.
static void exec_bash_script_cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
static void exec_bash_script_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
Run method of the command created by the interpreter to wait for another command to finish.

References BashScriptState::ac, BashScriptState::argc, BashScriptState::cb, exec_bash_script_cleanup(), exec_bash_script_run(), GNUNET_new, GNUNET_TESTING_command_new(), BashScriptState::script, and BashScriptState::script_argv.

Here is the call graph for this function: