github.com/criyle/go-sandbox@v0.10.3/pkg/forkexec/errloc_linux.go (about)

     1  package forkexec
     2  
     3  import (
     4  	"fmt"
     5  	"syscall"
     6  )
     7  
     8  // ErrorLocation defines the location where child process failed to exec
     9  type ErrorLocation int
    10  
    11  // ChildError defines the specific error and location where it failed
    12  type ChildError struct {
    13  	Err      syscall.Errno
    14  	Location ErrorLocation
    15  	Index    int
    16  }
    17  
    18  // Location constants
    19  const (
    20  	LocClone ErrorLocation = iota + 1
    21  	LocCloseWrite
    22  	LocUnshareUserRead
    23  	LocGetPid
    24  	LocKeepCapability
    25  	LocSetGroups
    26  	LocSetGid
    27  	LocSetUid
    28  	LocDup3
    29  	LocFcntl
    30  	LocSetSid
    31  	LocIoctl
    32  	LocMountRoot
    33  	LocMountTmpfs
    34  	LocMountChdir
    35  	LocMount
    36  	LocMountMkdir
    37  	LocPivotRoot
    38  	LocUmount
    39  	LocUnlink
    40  	LocMountRootReadonly
    41  	LocChdir
    42  	LocSetRlimit
    43  	LocSetNoNewPrivs
    44  	LocDropCapability
    45  	LocSetCap
    46  	LocPtraceMe
    47  	LocStop
    48  	LocSeccomp
    49  	LocSyncWrite
    50  	LocSyncRead
    51  	LocExecve
    52  )
    53  
    54  var locToString = []string{
    55  	"unknown",
    56  	"clone",
    57  	"close_write",
    58  	"unshare_user_read",
    59  	"getpid",
    60  	"keep_capability",
    61  	"setgroups",
    62  	"setgid",
    63  	"setuid",
    64  	"dup3",
    65  	"fcntl",
    66  	"setsid",
    67  	"ioctl",
    68  	"mount(root)",
    69  	"mount(tmpfs)",
    70  	"mount(chdir)",
    71  	"mount",
    72  	"mount(mkdir)",
    73  	"pivot_root",
    74  	"umount",
    75  	"unlink",
    76  	"mount(readonly)",
    77  	"chdir",
    78  	"setrlimt",
    79  	"set_no_new_privs",
    80  	"drop_capability",
    81  	"set_cap",
    82  	"ptrace_me",
    83  	"stop",
    84  	"seccomp",
    85  	"sync_write",
    86  	"sync_read",
    87  	"execve",
    88  }
    89  
    90  func (e ErrorLocation) String() string {
    91  	if e >= LocClone && e <= LocExecve {
    92  		return locToString[e]
    93  	}
    94  	return "unknown"
    95  }
    96  
    97  func (e ChildError) Error() string {
    98  	if e.Index > 0 {
    99  		return fmt.Sprintf("%s(%d): %s", e.Location.String(), e.Index, e.Err.Error())
   100  	}
   101  	return fmt.Sprintf("%s: %s", e.Location.String(), e.Err.Error())
   102  }