| 1 |
//go:build solaris && cgo |
| 2 |
|
| 3 |
package operatingsystem |
| 4 |
|
| 5 |
/* |
| 6 |
#include <zone.h> |
| 7 |
*/ |
| 8 |
import "C" |
| 9 |
|
| 10 |
import ( |
| 11 |
"bytes" |
| 12 |
"errors" |
| 13 |
"os" |
| 14 |
) |
| 15 |
|
| 16 |
var etcOsRelease = "/etc/release" |
| 17 |
|
| 18 |
// GetOperatingSystem gets the name of the current operating system. |
| 19 |
func GetOperatingSystem() (string, error) { |
| 20 |
b, err := os.ReadFile(etcOsRelease) |
| 21 |
if err != nil { |
| 22 |
return "", err |
| 23 |
} |
| 24 |
if i := bytes.Index(b, []byte("\n")); i >= 0 { |
| 25 |
b = bytes.Trim(b[:i], " ") |
| 26 |
return string(b), nil |
| 27 |
} |
| 28 |
return "", errors.New("release not found") |
| 29 |
} |
| 30 |
|
| 31 |
// IsContainerized returns true if we are running inside a container. |
| 32 |
func IsContainerized() (bool, error) { |
| 33 |
if C.getzoneid() != 0 { |
| 34 |
return true, nil |
| 35 |
} |
| 36 |
return false, nil |
| 37 |
} |