MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Functions | Variables
endrun.c File Reference
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include "endrun.h"
#include "system.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <execinfo.h>
Include dependency graph for endrun.c:

Go to the source code of this file.

Functions

static int show_backtrace (void)
 
static void OsSigHandler (int no)
 
static void init_stacktrace (void)
 
void init_endrun (int backtrace)
 
void endrun (int where, const char *fmt,...)
 
void message (int where, const char *fmt,...)
 

Variables

static int ShowBacktrace
 

Function Documentation

◆ endrun()

void endrun ( int  where,
const char *  fmt,
  ... 
)

Definition at line 147 of file endrun.c.

148 {
149 
150  va_list va;
151  va_start(va, fmt);
152  MPIU_Tracev(MPI_COMM_WORLD, where, 1, fmt, va);
153  va_end(va);
154  int ThisTask;
155  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
156  if(ThisTask == 0 || where > 0) {
157  if(ShowBacktrace)
158  show_backtrace();
159  MPI_Abort(MPI_COMM_WORLD, where);
160  }
161  /* This is here so the compiler knows this
162  * function never returns. */
163  exit(1);
164 }
static int show_backtrace(void)
Definition: endrun.c:29
static int ShowBacktrace
Definition: endrun.c:100
void MPIU_Tracev(MPI_Comm comm, int where, int error, const char *fmt, va_list va)
Definition: system.c:149
int ThisTask
Definition: test_exchange.c:23

References MPIU_Tracev(), show_backtrace(), ShowBacktrace, and ThisTask.

Referenced by _bigfile_utils_create_block_from_c_array(), _prepare(), _setup_mpsort_mpi(), _solve_for_layout_mpi(), add_particle_to_tree(), allocator_alloc_va(), allocator_destroy(), allocator_free(), allocator_iter_next(), allocator_realloc_int(), apply_half_kick(), blackhole_feedback_ngbiter(), blackhole_make_one(), check_omega(), check_positions(), check_sorted(), check_units(), cooling_and_starformation(), delta_nu_from_power(), Delta_Tabulated(), delta_tot_first_init(), density_check_neighbours(), density_kernel_init(), density_ngbiter(), density_postprocess(), dloga_from_dti(), do_long_radix_test(), do_mpsort_test(), DoCooling(), domain_assign_balanced(), domain_attempt_decompose(), domain_build_plan(), domain_check_for_local_refine_subsample(), domain_decompose_full(), domain_exchange(), domain_exchange_once(), domain_find_iter_space(), domain_nonrecursively_combine_topTree(), domain_test_id_uniqueness(), domain_toptree_merge(), domain_toptree_split(), drift_all_particles(), ev_begin(), find_last_snapnum(), fof_compile_catalogue(), fof_distribute_particles(), fof_label_secondary(), fof_reduce_groups(), fof_save_particles(), fof_seed_make_one(), fof_try_particle_exchange(), fof_write_header(), force_create_node_for_topnode(), force_exchange_pseudodata(), force_insert_pseudo_particles(), force_tree_build(), force_tree_create_nodes(), force_treeallocate(), force_treeupdate_pseudos(), force_update_node_parallel(), force_update_node_recursive(), force_update_particle_node(), get_delta_nu(), get_local_UVBG(), get_PM_timestep_ti(), get_starformation_rate_full(), get_Tabulated(), get_wind_params(), grav_short_pair_ngbiter(), grav_short_tree(), gravshort_fill_ntab(), growth(), gsl_handler(), hydro_force(), hydro_ngbiter(), init(), init_alloc_particle_slot_memory(), init_powerspectrum(), init_thermalvel(), init_transfer_table(), init_winds(), InitMetalCooling(), is_PM_timestep(), layout_iterate_cells(), layout_prepare(), lightcone_init(), load_heii_reion_hist(), load_treecool(), loga_from_ti(), main(), make_particle_star(), merge_partial_force_trees(), metal_return_ngbiter(), MPIU_write_pids(), mpsort_mpi_histogram_sort(), mpsort_mpi_newarray_impl(), mymalloc_init(), ngb_treefind_threads(), open_outputfiles(), OutputListAction(), param_get_string2(), param_parse_file(), parse_power(), parse_transfer(), particle_alloc_memory(), petaio_build_buffer(), petaio_read_block(), petaio_read_header_internal(), petaio_read_icnutransfer(), petaio_read_neutrinos(), petaio_read_snapshot(), petaio_save_block(), petaio_save_neutrinos(), petaio_save_snapshot(), petaio_write_header(), petapm_init(), pm_apply_transfer_function(), pm_iterate_one(), pm_mark_region_for_node(), read_big_array(), read_parameter_file(), read_parameterfile(), read_power_table(), real_drift_particle(), real_ev(), rebuild_activelist(), recomb_alphad(), recomb_alphaHep(), recomb_alphaHepp(), recomb_alphaHp(), recomb_GammaeH0(), recomb_GammaeHe0(), recomb_GammaeHep(), rho_nu_init(), run(), run_gravity_test(), save_transfer(), saveheader(), scipy_optimize_fixed_point(), set_all_global_params(), set_sfr_params(), setup_smoothinglengths(), sfr_wind_feedback_ngbiter(), slots_check_id_consistency(), slots_convert(), slots_gc_collect(), slots_gc_compact(), slots_gc_mark(), slots_setup_id(), slots_split_particle(), stellar_density(), tamalloc_init(), timestep_eh_slots_fork(), treewalk_build_queue(), treewalk_do_hsml_loop(), treewalk_export_particle(), treewalk_reduce_result(), treewalk_run(), treewalk_visit_ngbiter(), treewalk_visit_nolist_ngbiter(), turn_on_quasars(), update_random_offset(), update_replicas(), and winds_and_feedback().

Here is the call graph for this function:

◆ init_endrun()

void init_endrun ( int  backtrace)

Definition at line 132 of file endrun.c.

133 {
134  ShowBacktrace = backtrace;
135  init_stacktrace();
136 }
static void init_stacktrace(void)
Definition: endrun.c:115

References init_stacktrace(), and ShowBacktrace.

Referenced by main().

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

◆ init_stacktrace()

static void init_stacktrace ( void  )
static

Definition at line 115 of file endrun.c.

116 {
117  struct sigaction act, oact;
118 
119  int siglist[] = { SIGSEGV, SIGQUIT, SIGILL, SIGFPE, SIGBUS, 0};
120  sigemptyset(&act.sa_mask);
121 
122  act.sa_handler = OsSigHandler;
123  act.sa_flags = 0;
124 
125  int i;
126  for(i = 0; siglist[i] != 0; i ++) {
127  sigaction(siglist[i], &act, &oact);
128  }
129 }
static void OsSigHandler(int no)
Definition: endrun.c:103

References OsSigHandler().

Referenced by init_endrun().

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

◆ message()

void message ( int  where,
const char *  fmt,
  ... 
)

Definition at line 175 of file endrun.c.

176 {
177  va_list va;
178  va_start(va, fmt);
179  MPIU_Tracev(MPI_COMM_WORLD, where, 0, fmt, va);
180  va_end(va);
181 }

References MPIU_Tracev().

Referenced by _prepare(), allocator_print(), blackhole(), blackhole_dynfric_postprocess(), BlackHoleFeedbackMethodAction(), check_against_force_direct(), check_density_entropy(), check_omega(), check_smoothing_length(), check_units(), collect_BH_info(), cooling_and_starformation(), create_new_node_layer(), delta_nu_from_power(), density_check_neighbours(), displacement_fields(), do_density_test(), do_long_radix_test(), do_mpsort_test(), do_the_short_range_kick(), DoCooling(), domain_allocate(), domain_assign_balanced(), domain_attempt_decompose(), domain_balance(), domain_build_plan(), domain_check_memory_bound(), domain_decompose_full(), domain_determine_global_toptree(), domain_exchange_once(), domain_find_iter_space(), domain_global_refine(), domain_maintain(), domain_test_id_uniqueness(), domain_toptree_merge(), energy_statistics(), ev_begin(), find_last_snapshot(), find_timesteps(), fof_compile_catalogue(), fof_distribute_particles(), fof_finish(), fof_fof(), fof_label_primary(), fof_label_secondary(), fof_save_particles(), fof_seed(), force_tree_build(), force_tree_rebuild(), force_tree_rebuild_mask(), get_local_UVBG(), get_long_range_timestep_dloga(), get_timestep_ti(), glass_evolve(), glass_stats(), grav_short_pair(), grav_short_tree(), gravshort_set_softenings(), hci_query(), init_alloc_particle_slot_memory(), init_cooling_and_star_formation(), init_cooling_rates(), init_powerspectrum(), init_timebins(), init_timeline(), init_transfer_table(), init_winds(), layout_build_and_exchange_cells_to_pfft(), layout_prepare(), lightcone_set_time(), load_heii_reion_hist(), load_treecool(), main(), metal_return_init(), mpsort_mpi_newarray_impl(), mpsort_mpi_report_last_run(), mymalloc_init(), OutputListAction(), param_emit(), param_get_double(), param_get_enum(), param_get_int(), param_get_string(), param_get_string2(), param_validate(), parse_power(), particle_alloc_memory(), petaio_init(), petaio_read_header_internal(), petaio_read_icnutransfer(), petaio_read_snapshot(), petaio_save_block(), petaio_save_snapshot(), petapm_init(), powerspectrum_save(), print_spec(), print_timebin_statistics(), read_parameter_file(), read_parameterfile(), read_power_table(), real_ev(), report_detailed_memory_usage(), run(), run_gravity_test(), set_density_params(), setup(), setup_density_indep_entropy(), sfr_reserve_slots(), slots_check_id_consistency(), slots_gc_base(), slots_gc_slots(), slots_reserve(), StarformationCriterionAction(), stellar_density_check_neighbours(), tamalloc_init(), test_force_flat(), test_mpsort_bits(), test_openmpsort(), test_openmpsort_struct(), test_yields(), treewalk_do_hsml_loop(), turn_on_quasars(), update_random_offset(), and winds_and_feedback().

Here is the call graph for this function:

◆ OsSigHandler()

static void OsSigHandler ( int  no)
static

Definition at line 103 of file endrun.c.

104 {
105  const char btline[] = "Killed by Signal %d\n";
106  char buf[128];
107  sprintf(buf, btline, no);
108  write(STDOUT_FILENO, buf, strlen(buf));
109  if(ShowBacktrace)
110  show_backtrace();
111  MPI_Abort(MPI_COMM_WORLD, no);
112 }

References show_backtrace(), and ShowBacktrace.

Referenced by init_stacktrace().

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

◆ show_backtrace()

static int show_backtrace ( void  )
static

Definition at line 29 of file endrun.c.

30 {
31  pid_t kidpid;
32  int pipefd[2];
33 
34  if (pipe(pipefd) != 0) {
35  return -1;
36  }
37 
38  kidpid = fork();
39 
40  if (kidpid == -1) {
41  /* ERROR */
42  return -1;
43  } else if (kidpid == 0) {
44  /* CHILD */
45  char parent[16];
46  char buf[512];
47  close(STDIN_FILENO);
48  close(STDOUT_FILENO);
49  dup2(pipefd[1],STDOUT_FILENO);
50  dup2(pipefd[1],STDERR_FILENO);
51 
52  snprintf(parent, sizeof(parent), "%d", getppid());
53 
54  /* YF: xorg didn't have the last NULL; which seems to be wrong;
55  * causing random failures in execle. */
56 
57  /* try a few tools in order; */
58  execle("/usr/bin/pstack", "pstack", parent, NULL, NULL);
59  execle("/usr/bin/eu-stack", "eu-stack", "-p", parent, NULL, NULL);
60 
61  sprintf(buf, "No tools to pretty print a stack trace for pid %d.\n"
62  "Fallback to glibc backtrace which may not contain all symbols.\n "
63  "run eu-addr2line to pretty print the output.\n", getppid());
64 
65  write(STDOUT_FILENO, buf, strlen(buf));
66  exit(EXIT_FAILURE);
67  } else {
68  /* PARENT */
69  char btline[256];
70  int kidstat = 0;
71  int bytesread;
72  int done = 0;
73 
74  close(pipefd[1]);
75 
76  while (!done) {
77  bytesread = read(pipefd[0], btline, sizeof(btline) - 1);
78 
79  if (bytesread > 0) {
80  btline[bytesread] = 0;
81  write(STDOUT_FILENO, btline, strlen(btline));
82  }
83  else if ((bytesread < 0) ||
84  ((errno != EINTR) && (errno != EAGAIN)))
85  done = 1;
86  }
87  close(pipefd[0]);
88 
89  waitpid(kidpid, &kidstat, 0);
90 
91  if (WIFEXITED(kidstat) && (WEXITSTATUS(kidstat) == EXIT_FAILURE)) {
92  void * buf[100];
93  backtrace_symbols_fd(buf, 100, STDOUT_FILENO);
94  return -1;
95  }
96  }
97  return 0;
98 }

Referenced by endrun(), and OsSigHandler().

Here is the caller graph for this function:

Variable Documentation

◆ ShowBacktrace

int ShowBacktrace
static