1
// Copyright 2021 The Gitea Authors. All rights reserved.
2
// SPDX-License-Identifier: MIT
10
// Context is a wrapper around context.Context and contains the current pid for this context
16
// GetPID returns the PID for this context
17
func (c *Context) GetPID() IDType {
21
// GetParent returns the parent process context (if any)
22
func (c *Context) GetParent() *Context {
23
return GetContext(c.Context)
26
// Value is part of the interface for context.Context. We mostly defer to the internal context - but we return this in response to the ProcessContextKey
27
func (c *Context) Value(key any) any {
28
if key == ProcessContextKey {
31
return c.Context.Value(key)
34
// ProcessContextKey is the key under which process contexts are stored
35
var ProcessContextKey any = "process-context"
37
// GetContext will return a process context if one exists
38
func GetContext(ctx context.Context) *Context {
39
if pCtx, ok := ctx.(*Context); ok {
42
pCtxInterface := ctx.Value(ProcessContextKey)
43
if pCtxInterface == nil {
46
if pCtx, ok := pCtxInterface.(*Context); ok {
52
// GetPID returns the PID for this context
53
func GetPID(ctx context.Context) IDType {
54
pCtx := GetContext(ctx)
61
// GetParentPID returns the ParentPID for this context
62
func GetParentPID(ctx context.Context) IDType {
64
if parentProcess := GetContext(ctx); parentProcess != nil {
65
parentPID = parentProcess.GetPID()