github.com/m3db/m3@v1.5.0/src/x/panicmon/handler.go (about)

     1  // Copyright (c) 2017 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package panicmon
    22  
    23  // Handler is composed of a ProcessHandler and SignalHandler.
    24  type Handler struct {
    25  	ProcessHandler
    26  	SignalHandler
    27  }
    28  
    29  // ProcessHandler is implemented by clients that would like to subscribe to
    30  // process-related events (start, exit, etc.).
    31  type ProcessHandler interface {
    32  	// ProcessStarted is called immediately prior to a process being started.
    33  	ProcessStarted(ProcessStartEvent)
    34  
    35  	// ProcessFailed is called when a process cannot successfully be started.
    36  	// It receives the error returned by os/exec.
    37  	ProcessFailed(ProcessFailedEvent)
    38  
    39  	// ProcessExited is called when a process has been successfully started and
    40  	// has ran to completion (regardless of exit status). It receives the status
    41  	// code returned by the process.
    42  	ProcessExited(ProcessExitedEvent)
    43  }
    44  
    45  // NoopProcessHandler implements ProcessHandler and does nothing.
    46  type NoopProcessHandler struct{}
    47  
    48  // ProcessStarted is a noop.
    49  func (NoopProcessHandler) ProcessStarted(_ ProcessStartEvent) {}
    50  
    51  // ProcessFailed is a noop.
    52  func (NoopProcessHandler) ProcessFailed(_ ProcessFailedEvent) {}
    53  
    54  // ProcessExited is a noop.
    55  func (NoopProcessHandler) ProcessExited(_ ProcessExitedEvent) {}
    56  
    57  // SignalHandler is implemented by clients that would like to subscribe to
    58  // signal-related events, specifically when signals are received by panicmon
    59  // and whether or not they are successfully passed to the child.
    60  type SignalHandler interface {
    61  	// SignalReceived is called immediately after a signal is intercepted by
    62  	// panicmon.
    63  	SignalReceived(SignalReceivedEvent)
    64  
    65  	// SignalPassed is called when a signal has been successfully forwarded to a
    66  	// child process.
    67  	SignalPassed(SignalPassedEvent)
    68  
    69  	// SignalFailed is called when panicmon encounters an error passing a signal
    70  	// to a child.
    71  	SignalFailed(SignalFailedEvent)
    72  }
    73  
    74  // NoopSignalHandler implements SignalHandler and does nothing.
    75  type NoopSignalHandler struct{}
    76  
    77  // SignalReceived is a noop.
    78  func (NoopSignalHandler) SignalReceived(_ SignalReceivedEvent) {}
    79  
    80  // SignalPassed is a noop.
    81  func (NoopSignalHandler) SignalPassed(_ SignalPassedEvent) {}
    82  
    83  // SignalFailed is a noop.
    84  func (NoopSignalHandler) SignalFailed(_ SignalFailedEvent) {}