github.com/searKing/golang/go@v1.2.117/os/signal/cgo/signal_linux.cgo.cpp (about)

     1  // Copyright (c) 2019 The searKing authors. All Rights Reserved.
     2  //
     3  // Use of this source code is governed by a MIT-style license
     4  // that can be found in the LICENSE file in the root of the source
     5  // tree. An additional intellectual property rights grant can be found
     6  // in the file PATENTS.  All contributing project authors may
     7  // be found in the AUTHORS file in the root of the source tree.
     8  
     9  //go:build cgo && linux
    10  
    11  #include <algorithm>
    12  
    13  #include "signal.cgo.h"
    14  #include "signal_handler_linux.hpp"
    15  
    16  int CGO_SignalHandlerSetSig(int signum) {
    17    return searking::SignalHandler::SetSig(signum);
    18  }
    19  
    20  void CGO_SignalHandlerSetSignalDumpToFd(int fd) {
    21    searking::SignalHandler::GetInstance().SetSignalDumpToFd(fd);
    22  }
    23  
    24  void CGO_SignalHandlerSetStacktraceDumpToFile(char* name) {
    25    searking::SignalHandler::GetInstance().SetStacktraceDumpToFile(name);
    26  }
    27  
    28  void CGO_SignalHandlerDumpPreviousStacktrace() {
    29    searking::SignalHandler::GetInstance().DumpPreviousStacktrace();
    30  }
    31  
    32  // don't forget to free the string after finished using it
    33  char* CGO_PreviousStacktrace() {
    34    auto str = searking::SignalHandler::GetInstance().PreviousStacktrace();
    35  
    36    char* writable = static_cast<char*>(malloc((str.size() + 1) * sizeof(char)));
    37    std::copy(str.begin(), str.end(), writable);
    38    writable[str.size()] = '\0';  // don't forget the terminating 0
    39    return writable;
    40  }
    41  
    42  void CGO_SetSigInvokeChain(const int from, const int to, const int wait,
    43                             const int sleepInSeconds) {
    44    searking::SignalHandler::GetInstance().SetSigInvokeChain(from, to, wait,
    45                                                             sleepInSeconds);
    46  }