glog_file_linux.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Go support for leveled logs, analogous to https://github.com/google/glog.
  2. //
  3. // Copyright 2023 Google Inc. All Rights Reserved.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //go:build linux
  17. package glog
  18. import (
  19. "errors"
  20. "runtime"
  21. "syscall"
  22. )
  23. // abortProcess attempts to kill the current process in a way that will dump the
  24. // currently-running goroutines someplace useful (like stderr).
  25. //
  26. // It does this by sending SIGABRT to the current thread.
  27. //
  28. // If successful, abortProcess does not return.
  29. func abortProcess() error {
  30. runtime.LockOSThread()
  31. if err := syscall.Tgkill(syscall.Getpid(), syscall.Gettid(), syscall.SIGABRT); err != nil {
  32. return err
  33. }
  34. return errors.New("log: killed current thread with SIGABRT, but still running")
  35. }