]> Cypherpunks.ru repositories - gostls13.git/commit
runtime: add an exit hook facility
authorThan McIntosh <thanm@google.com>
Fri, 8 Oct 2021 15:51:40 +0000 (11:51 -0400)
committerThan McIntosh <thanm@google.com>
Mon, 26 Sep 2022 21:49:14 +0000 (21:49 +0000)
commit07bdf1dc545c6f6e59f5780a9024e6f230d9b434
treee3695600b93acdc672438ebd432389b15bead6ef
parentcf83a490e495e5bfa7065cd97811e689101a687e
runtime: add an exit hook facility

Add a new API (not public/exported) for registering a function with
the runtime that should be called when program execution terminates,
to be used in the new code coverage re-implementation. The API looks
like

  func addExitHook(f func(), runOnNonZeroExit bool)

The first argument is the function to be run, second argument controls
whether the function is invoked even if there is a call to os.Exit
with a non-zero status. Exit hooks are run in reverse order of
registration, e.g. the first hook to be registered will be the last to
run. Exit hook functions are not allowed to panic or to make calls to
os.Exit.

Updates #51430.

Change-Id: I906f8c5184b7c1666f05a62cfc7833bf1a4300c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/354790
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/os/proc.go
src/runtime/ehooks_test.go [new file with mode: 0644]
src/runtime/exithook.go [new file with mode: 0644]
src/runtime/proc.go
src/runtime/testdata/testexithooks/testexithooks.go [new file with mode: 0644]