GNUnet  0.11.x
Macros | Functions | Variables
gnunet_testbed_mpi_spawn.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testbed_service.h"
Include dependency graph for gnunet_testbed_mpi_spawn.c:

Go to the source code of this file.


#define LOG(kind, ...)    GNUNET_log (kind, __VA_ARGS__)
 Generic logging shorthand. More...
 Debug logging shorthand. More...


static void shutdown_task (void *cls)
 The shutdown task. More...
static void terminate_task (void *cls)
static void child_death_task (void *cls)
 Task triggered whenever we receive a SIGCHLD (child process died). More...
static void destroy_hosts (struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts)
static void run (void *cls)
 The main scheduler run task. More...
static void sighandler_child_death ()
 Signal handler called for SIGCHLD. More...
int main (int argc, char *argv[])
 Execution start point. More...


static int ret
 Global result. More...
static struct GNUNET_OS_Processchild
 The child process we spawn. More...
static char ** argv2
 The arguments including the binary to spawn. More...
static struct GNUNET_DISK_PipeHandlesigpipe
 Pipe used to communicate shutdown via signal. More...
static char * fn
 Filename of the unique file. More...
static int fh
 Handle to the unique file. More...
static unsigned long child_exit_code
 The return code of the binary. More...
static enum GNUNET_OS_ProcessStatusType child_status
 The process status of the child. More...
static struct GNUNET_SCHEDULER_Taskterminate_task_id
 Task to kill the child. More...
static struct GNUNET_SCHEDULER_Taskchild_death_task_id
 Task to kill the child. More...

Macro Definition Documentation


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

Generic logging shorthand.

Definition at line 9 of file gnunet_testbed_mpi_spawn.c.



Debug logging shorthand.

Definition at line 15 of file gnunet_testbed_mpi_spawn.c.

Function Documentation

◆ shutdown_task()

static void shutdown_task ( void *  cls)

The shutdown task.

Definition at line 72 of file gnunet_testbed_mpi_spawn.c.

73 {
74  if (0 != child_exit_code)
75  {
76  LOG (GNUNET_ERROR_TYPE_WARNING, "Child exited with error code: %lu\n",
78  ret = 128 + (int) child_exit_code;
79  }
80  if (0 != fh)
81  {
82  close (fh);
83  }
84  if ((NULL != fn) && (0 != unlink (fn)))
85  {
88  }
89 }
Definition: gnunet_common.h:93
static int ret
Global result.
static char * fn
Filename of the unique file.
static int fh
Handle to the unique file.
#define LOG(kind,...)
Generic logging shorthand.
static unsigned long child_exit_code
The return code of the binary.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...

References child_exit_code, fh, fn, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log_strerror, GNUNET_SYSERR, consensus-simulation::int, LOG, and ret.

Referenced by child_death_task(), and run().

Here is the caller graph for this function:

◆ terminate_task()

static void terminate_task ( void *  cls)

Definition at line 93 of file gnunet_testbed_mpi_spawn.c.

94 {
95  static int hard_kill;
97  GNUNET_assert (NULL != child);
100  if (0 != hard_kill)
101  {
102  switch (hard_kill)
103  {
104  case 1:
105  case 2:
107  "%d more interrupts needed to send SIGKILL to the child\n",
108  3 - hard_kill);
109  hard_kill++;
110  return;
112  case 3:
113  GNUNET_break (0 == GNUNET_OS_process_kill (child, SIGKILL));
114  return;
115  }
116  }
117  hard_kill++;
119  LOG (GNUNET_ERROR_TYPE_INFO, _ ("Waiting for child to exit.\n"));
120 }
static void terminate_task(void *cls)
static struct GNUNET_OS_Process * child
The child process we spawn.
static struct GNUNET_SCHEDULER_Task * terminate_task_id
Task to kill the child.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:224
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1331
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
The termination signal.
Definition: platform.h:233

References _, child, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_OS_process_kill(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_TERM_SIG, LOG, and terminate_task_id.

Referenced by run().

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

◆ child_death_task()

static void child_death_task ( void *  cls)

Task triggered whenever we receive a SIGCHLD (child process died).

clsclosure, NULL if we need to self-restart

Definition at line 130 of file gnunet_testbed_mpi_spawn.c.

131 {
132  const struct GNUNET_DISK_FileHandle *pr;
133  char c[16];
134  const struct GNUNET_SCHEDULER_TaskContext *tc;
138  child_death_task_id = NULL;
141  {
144  pr, &child_death_task, NULL);
145  return;
146  }
147  /* consume the signal */
148  GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c)));
149  LOG_DEBUG ("Child died\n");
151  terminate_task_id = NULL;
153  &child_exit_code));
155  child = NULL;
157 }
Definition: gnunet_common.h:95
static struct GNUNET_SCHEDULER_Task * child_death_task_id
Task to kill the child.
static void shutdown_task(void *cls)
The shutdown task.
static void child_death_task(void *cls)
Task triggered whenever we receive a SIGCHLD (child process died).
#define LOG_DEBUG(...)
Debug logging shorthand.
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
static enum GNUNET_OS_ProcessStatusType child_status
The process status of the child.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:622
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:1616
The reading-end of a pipe.
int GNUNET_OS_process_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Retrieve the status of a process.
Definition: os_priority.c:946
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
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1667
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:752
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
The reading socket is ready.
Constant used to specify "forever".
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:423
Handle used to access files (and pipes).
Context information passed to each scheduler task.
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.

References child, child_death_task_id, child_exit_code, child_status, GNUNET_assert, GNUNET_break, GNUNET_DISK_file_read(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_pipe_handle(), GNUNET_OK, GNUNET_OS_process_destroy(), GNUNET_OS_process_status(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_READ_READY, GNUNET_TIME_UNIT_FOREVER_REL, LOG_DEBUG, GNUNET_SCHEDULER_TaskContext::reason, shutdown_task(), sigpipe, tc, and terminate_task_id.

Referenced by run().

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

◆ destroy_hosts()

static void destroy_hosts ( struct GNUNET_TESTBED_Host **  hosts,
unsigned int  nhosts 

Definition at line 161 of file gnunet_testbed_mpi_spawn.c.

162 {
163  unsigned int host;
165  GNUNET_assert (NULL != hosts);
166  for (host = 0; host < nhosts; host++)
167  if (NULL != hosts[host])
168  GNUNET_TESTBED_host_destroy (hosts[host]);
169  GNUNET_free (hosts);
170  hosts = NULL;
171 }
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_TESTBED_host_destroy(struct GNUNET_TESTBED_Host *host)
Destroy a host handle.

References GNUNET_assert, GNUNET_free, and GNUNET_TESTBED_host_destroy().

Referenced by run().

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

◆ run()

static void run ( void *  cls)

The main scheduler run task.


Definition at line 180 of file gnunet_testbed_mpi_spawn.c.

181 {
182  struct GNUNET_TESTBED_Host **hosts;
183  const struct GNUNET_CONFIGURATION_Handle *null_cfg;
184  char *tmpdir;
185  char *hostname;
186  size_t hostname_len;
187  unsigned int nhosts;
189  null_cfg = GNUNET_CONFIGURATION_create ();
190  nhosts = GNUNET_TESTBED_hosts_load_from_loadleveler (null_cfg, &hosts);
191  if (0 == nhosts)
192  {
193  GNUNET_break (0);
194  ret = GNUNET_SYSERR;
195  return;
196  }
197  hostname_len = GNUNET_OS_get_hostname_max_length ();
198  hostname = GNUNET_malloc (hostname_len);
199  if (0 != gethostname (hostname, hostname_len))
200  {
201  LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname. Exiting\n");
203  destroy_hosts (hosts, nhosts);
204  ret = GNUNET_SYSERR;
205  return;
206  }
207  if (NULL == strstr (GNUNET_TESTBED_host_get_hostname (hosts[0]), hostname))
208  {
209  LOG_DEBUG ("Exiting as `%s' is not the lowest host\n", hostname);
211  ret = GNUNET_OK;
212  return;
213  }
214  LOG_DEBUG ("Will be executing `%s' on host `%s'\n", argv2[0], hostname);
216  destroy_hosts (hosts, nhosts);
217  tmpdir = getenv ("TMPDIR");
218  if (NULL == tmpdir)
219  tmpdir = getenv ("TMP");
220  if (NULL == tmpdir)
221  tmpdir = getenv ("TEMP");
222  if (NULL == tmpdir)
223  tmpdir = "/tmp";
224  (void) GNUNET_asprintf (&fn, "%s/gnunet-testbed-spawn.lock", tmpdir);
225  /* Open the unique file; we can create it then we can spawn the child process
226  else we exit */
227  fh = open (fn, O_CREAT | O_EXCL | O_CLOEXEC,
229  if (-1 == fh)
230  {
231  if (EEXIST == errno)
232  {
233  LOG_DEBUG ("Lock file already created by other process. Exiting\n");
234  ret = GNUNET_OK;
235  return;
236  }
238  ret = GNUNET_SYSERR;
239  return;
240  }
241  /* Spawn the new process here */
242  LOG (GNUNET_ERROR_TYPE_INFO, _ ("Spawning process `%s'\n"), argv2[0]);
244  NULL,
245  NULL, NULL,
246  argv2[0], argv2);
247  if (NULL == child)
248  {
249  GNUNET_break (0);
250  ret = GNUNET_SYSERR;
252  return;
253  }
254  ret = GNUNET_OK;
261  &child_death_task, NULL);
262 }
char * getenv()
static char * hostname
Our hostname; we give this to all the peers we start.
Definition: gnunet_common.h:94
static void destroy_hosts(struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts)
static char ** argv2
The arguments including the binary to spawn.
Create a new configuration object.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_malloc(size)
Wrapper around malloc.
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
#define GNUNET_OS_get_hostname_max_length()
Get maximum string length returned by gethostname()
Use this option to have all of the standard streams (stdin, stdout and stderror) be inherited.
unsigned int GNUNET_TESTBED_hosts_load_from_loadleveler(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTBED_Host ***hosts)
Loads the set of host allocated by the LoadLeveler Job Scheduler.
const char * GNUNET_TESTBED_host_get_hostname(const struct GNUNET_TESTBED_Host *host)
Obtain the host's hostname.
Opaque handle to a host running experiments managed by the testing framework.

References _, argv2, child, child_death_task(), child_death_task_id, destroy_hosts(), fh, fn, getenv(), GNUNET_asprintf(), GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_pipe_handle(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log_strerror, GNUNET_malloc, GNUNET_NO, GNUNET_OK, GNUNET_OS_get_hostname_max_length, GNUNET_OS_INHERIT_STD_ALL, GNUNET_OS_start_process_vap(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SYSERR, GNUNET_TESTBED_host_get_hostname(), GNUNET_TESTBED_hosts_load_from_loadleveler(), GNUNET_TIME_UNIT_FOREVER_REL, hostname, LOG, LOG_DEBUG, ret, shutdown_task(), sigpipe, terminate_task(), and terminate_task_id.

Referenced by main().

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

◆ sighandler_child_death()

static void sighandler_child_death ( void  )

Signal handler called for SIGCHLD.

Definition at line 269 of file gnunet_testbed_mpi_spawn.c.

270 {
271  static char c;
272  int old_errno = errno; /* back-up errno */
274  GNUNET_break (1 ==
277  &c, sizeof(c)));
278  errno = old_errno; /* restore errno */
279 }
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:686
The writing-end of a pipe.

References GNUNET_break, GNUNET_DISK_file_write(), GNUNET_DISK_PIPE_END_WRITE, GNUNET_DISK_pipe_handle(), and sigpipe.

Referenced by main().

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

◆ main()

int main ( int  argc,
char *  argv[] 

Execution start point.

Definition at line 286 of file gnunet_testbed_mpi_spawn.c.

287 {
289  unsigned int cnt;
291  ret = -1;
292  if (argc < 2)
293  {
294  printf ("Need arguments: gnunet-testbed-mpi-spawn <cmd> <cmd_args>");
295  return 1;
296  }
297  if (GNUNET_OK != GNUNET_log_setup ("gnunet-testbed-spawn", NULL, NULL))
298  {
299  GNUNET_break (0);
300  return 1;
301  }
302  if (NULL == (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE)))
303  {
304  GNUNET_break (0);
305  ret = GNUNET_SYSERR;
306  return 1;
307  }
308  shc_chld =
310  if (NULL == shc_chld)
311  {
312  LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot install a signal handler\n");
313  return 1;
314  }
315  argv2 = GNUNET_malloc (sizeof(char *) * argc);
316  for (cnt = 1; cnt < argc; cnt++)
317  argv2[cnt - 1] = argv[cnt];
318  GNUNET_SCHEDULER_run (run, NULL);
319  GNUNET_free (argv2);
321  shc_chld = NULL;
323  GNUNET_free (fn);
324  if (GNUNET_OK != ret)
325  return ret;
326  return 0;
327 }
static struct GNUNET_SIGNAL_Context * shc_chld
static void run(void *cls)
The main scheduler run task.
static void sighandler_child_death()
Signal handler called for SIGCHLD.
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1585
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition: disk.c:1442
No special options, use non-blocking read/write operations.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:720
struct GNUNET_SIGNAL_Context * GNUNET_SIGNAL_handler_install(int signal, GNUNET_SIGNAL_Handler handler)
Install a signal handler that will be run if the given signal is received.
Definition: signal.c:51
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal handler.
Definition: signal.c:77
Definition: platform.h:42

References argv2, fn, GNUNET_break, GNUNET_DISK_PF_NONE, GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_setup(), GNUNET_malloc, GNUNET_OK, GNUNET_SCHEDULER_run(), GNUNET_SIGCHLD, GNUNET_SIGNAL_handler_install(), GNUNET_SIGNAL_handler_uninstall(), GNUNET_SYSERR, LOG, ret, run(), shc_chld, sighandler_child_death(), and sigpipe.

Here is the call graph for this function:

Variable Documentation

◆ ret

int ret

Global result.

Definition at line 21 of file gnunet_testbed_mpi_spawn.c.

Referenced by main(), run(), and shutdown_task().

◆ child

struct GNUNET_OS_Process* child

The child process we spawn.

Definition at line 26 of file gnunet_testbed_mpi_spawn.c.

Referenced by child_death_task(), get_file_information(), mark_as_reachable(), run(), and terminate_task().

◆ argv2

char** argv2

The arguments including the binary to spawn.

Definition at line 31 of file gnunet_testbed_mpi_spawn.c.

Referenced by GNUNET_TESTBED_test_run(), join_argv(), main(), and run().

◆ sigpipe

struct GNUNET_DISK_PipeHandle* sigpipe

Pipe used to communicate shutdown via signal.

Definition at line 36 of file gnunet_testbed_mpi_spawn.c.

Referenced by child_death_task(), main(), run(), and sighandler_child_death().

◆ fn

char* fn

Filename of the unique file.

Definition at line 41 of file gnunet_testbed_mpi_spawn.c.

Referenced by add_host_to_known_hosts(), check_client_index_start(), create_keys(), deserialize_fi_node(), deserialize_file_information(), discard_hosts_helper(), get_host_filename(), get_read_handle(), get_write_handle(), get_write_handle_in_dir(), GNUNET_BIO_read_open_file(), GNUNET_BIO_write_open_file(), GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_DISK_directory_create(), GNUNET_DISK_file_change_owner(), GNUNET_DISK_file_close(), GNUNET_DISK_fix_permissions(), GNUNET_DISK_fn_read(), GNUNET_DISK_mkdtemp(), GNUNET_FRIENDS_parse(), GNUNET_FRIENDS_write_start(), GNUNET_FS_download_sync_(), GNUNET_FS_file_information_create_from_file(), GNUNET_FS_file_information_sync_(), GNUNET_FS_handle_on_demand_block(), GNUNET_FS_indexing_send_list(), GNUNET_FS_publish_main_(), GST_stats_init(), handle_client_index_start(), handle_create_message(), handle_delete_message(), hash_for_index_cb(), libgnunet_plugin_datacache_sqlite_init(), libgnunet_plugin_datastore_sqlite_done(), load(), load_state(), logger_run(), main(), make_serialization_file_name(), make_serialization_file_name_in_dir(), mktemp_name(), print_filename_option(), process_ego_file(), publish_inspector(), read_host_file(), read_index_list(), read_update_information_graph(), run(), save(), save_state(), setup_log_file(), shutdown_task(), trigger_recursive_download(), try_match_block(), update_hello(), write_index_list(), and write_update_information_graph().

◆ fh

int fh

◆ child_exit_code

unsigned long child_exit_code

The return code of the binary.

Definition at line 51 of file gnunet_testbed_mpi_spawn.c.

Referenced by child_death_task(), and shutdown_task().

◆ child_status

enum GNUNET_OS_ProcessStatusType child_status

The process status of the child.

Definition at line 51 of file gnunet_testbed_mpi_spawn.c.

Referenced by child_death_task().

◆ terminate_task_id

struct GNUNET_SCHEDULER_Task* terminate_task_id

Task to kill the child.

Definition at line 61 of file gnunet_testbed_mpi_spawn.c.

Referenced by child_death_task(), run(), and terminate_task().

◆ child_death_task_id

struct GNUNET_SCHEDULER_Task* child_death_task_id

Task to kill the child.

Definition at line 66 of file gnunet_testbed_mpi_spawn.c.

Referenced by child_death_task(), and run().