Skip to content

Commit

Permalink
Merge pull request #978 from darshan-hpc/snyder/_exit-intercept
Browse files Browse the repository at this point in the history
ENH: wrap _exit in Darshan's shared library
  • Loading branch information
shanedsnyder authored Mar 19, 2024
2 parents 84862c8 + c35da51 commit 5ad30d5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions darshan-runtime/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,18 @@ if test "x$enable_darshan_runtime" = xyes ; then
# look for glibc-specific functions
AC_CHECK_FUNCS([pwritev preadv pwritev2 preadv2])

# allow users to opt out of wrapping of _exit as a shutdown hook in
# Darshan's non-MPI mode, in case this functionality is problematic
AC_ARG_ENABLE([exit-wrapper],
[AS_HELP_STRING([--disable-exit-wrapper],
[Disables wrapping of _exit() calls as last ditch shutdown
hook for the Darshan library when used in non-MPI mode.])],
[], [enable_exit_wrapper=yes])
if test "x$enable_exit_wrapper" = "xyes" ; then
AC_DEFINE([__DARSHAN_ENABLE_EXIT_WRAPPER], 1,
[Define if the Darshan runtime library should wrap _exit() calls])
fi

DARSHAN_VERSION="AC_PACKAGE_VERSION"
AC_SUBST(LDFLAGS)
AC_SUBST(__DARSHAN_LOG_PATH)
Expand Down
2 changes: 2 additions & 0 deletions darshan-runtime/doc/darshan-runtime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ make install
* `--disable-ld-preload`: disables building of the Darshan LD_PRELOAD library
* `--enable-group-readable-logs`: sets Darshan log file permissions to allow
group read access.
* `--disable-exit-wrapper`: disables wrapping of `_exit()` calls as last ditch
shutdown hook for the Darshan library when used in non-MPI mode.
* `CC=`: specifies the C compiler to use for compilation.

.Configure arguments for controlling which Darshan modules to use:
Expand Down
15 changes: 15 additions & 0 deletions darshan-runtime/lib/darshan-core-init-finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ __attribute__((destructor)) void serial_finalize(void)
}
#endif

#if defined(DARSHAN_PRELOAD) && defined(__DARSHAN_ENABLE_EXIT_WRAPPER)
void (*__real__exit)(int status) __attribute__ ((noreturn)) = NULL;
void _exit(int status)
{
MAP_OR_FAIL(_exit);
(void)__darshan_disabled;

char *no_mpi = getenv("DARSHAN_ENABLE_NONMPI");
if (no_mpi)
darshan_core_shutdown(1);

__real__exit(status);
}
#endif

/*
* Local variables:
* c-indent-level: 4
Expand Down

0 comments on commit 5ad30d5

Please sign in to comment.