github.com/thediveo/gons@v0.9.9/gons.go (about) 1 // Copyright 2019 Harald Albrecht. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //go:build linux 16 // +build linux 17 18 package gons 19 20 /* 21 extern void gonamespaces(void); 22 extern char *gonsmsg; 23 void __attribute__((constructor)) init(void) { 24 gonamespaces(); 25 } 26 */ 27 import "C" 28 29 // NamespaceSwitchError reports unsuccessful namespace switching during 30 // startup. 31 type NamespaceSwitchError struct { 32 details string 33 } 34 35 // Error returns a description of the failure causing the initial namespace 36 // switching to abort. 37 func (e *NamespaceSwitchError) Error() string { 38 if e == nil { 39 return "<nil>" 40 } 41 return e.details 42 } 43 44 // Status returns nil if there were no problems switching namespaces during 45 // initial startup; otherwise, it returns a NamespaceSwitchError with a detail 46 // description. 47 func Status() error { 48 if C.gonsmsg == nil { 49 return nil 50 } 51 return &NamespaceSwitchError{ 52 details: C.GoString(C.gonsmsg), 53 } 54 }