diff --git a/README.rst b/README.rst index e16d591..cd851c8 100644 --- a/README.rst +++ b/README.rst @@ -17,10 +17,6 @@ psutil functions on some architectures... Package (a.k.a. directory) structure has been changed!! see `issue 24 `_ -.. highlights:: golang 1.4 will become REQUIRED! - - Since syscall package becomes frozen, we should use golang/x/sys of golang 1.4 as soon as possible. - Available Architectures ------------------------------------ @@ -63,6 +59,7 @@ The output is below. You can set an alternative location to /proc by setting the HOST_PROC environment variable. You can set an alternative location to /sys by setting the HOST_SYS environment variable. +You can set an alternative location to /etc by setting the HOST_ETC environment variable. Documentation ------------------------ diff --git a/disk/disk_linux.go b/disk/disk_linux.go index caa1e17..5d0b5a5 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -214,8 +214,7 @@ var fsTypeMap = map[int64]string{ // Get disk partitions. // should use setmntent(3) but this implement use /etc/mtab file func DiskPartitions(all bool) ([]DiskPartitionStat, error) { - - filename := "/etc/mtab" + filename := common.HostEtc("mtab") lines, err := common.ReadLines(filename) if err != nil { return nil, err diff --git a/host/host_linux.go b/host/host_linux.go index 11c8a4e..d24c172 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -141,8 +141,8 @@ func Users() ([]UserStat, error) { func getLSB() (*LSB, error) { ret := &LSB{} - if common.PathExists("/etc/lsb-release") { - contents, err := common.ReadLines("/etc/lsb-release") + if common.PathExists(common.HostEtc("lsb-release")) { + contents, err := common.ReadLines(common.HostEtc("lsb-release")) if err != nil { return ret, err // return empty } @@ -196,19 +196,20 @@ func GetPlatformInformation() (platform string, family string, version string, e lsb = &LSB{} } - if common.PathExists("/etc/oracle-release") { + if common.PathExists(common.HostEtc("oracle-release")) { platform = "oracle" - contents, err := common.ReadLines("/etc/oracle-release") + contents, err := common.ReadLines(common.HostEtc("oracle-release")) if err == nil { version = getRedhatishVersion(contents) } - } else if common.PathExists("/etc/enterprise-release") { + + } else if common.PathExists(common.HostEtc("enterprise-release")) { platform = "oracle" - contents, err := common.ReadLines("/etc/enterprise-release") + contents, err := common.ReadLines(common.HostEtc("enterprise-release")) if err == nil { version = getRedhatishVersion(contents) } - } else if common.PathExists("/etc/debian_version") { + } else if common.PathExists(common.HostEtc("debian_version")) { if lsb.ID == "Ubuntu" { platform = "ubuntu" version = lsb.Release @@ -221,37 +222,37 @@ func GetPlatformInformation() (platform string, family string, version string, e } else { platform = "debian" } - contents, err := common.ReadLines("/etc/debian_version") + contents, err := common.ReadLines(common.HostEtc("debian_version")) if err == nil { version = contents[0] } } - } else if common.PathExists("/etc/redhat-release") { - contents, err := common.ReadLines("/etc/redhat-release") + } else if common.PathExists(common.HostEtc("redhat-release")) { + contents, err := common.ReadLines(common.HostEtc("redhat-release")) if err == nil { version = getRedhatishVersion(contents) platform = getRedhatishPlatform(contents) } - } else if common.PathExists("/etc/system-release") { - contents, err := common.ReadLines("/etc/system-release") + } else if common.PathExists(common.HostEtc("system-release")) { + contents, err := common.ReadLines(common.HostEtc("system-release")) if err == nil { version = getRedhatishVersion(contents) platform = getRedhatishPlatform(contents) } - } else if common.PathExists("/etc/gentoo-release") { + } else if common.PathExists(common.HostEtc("gentoo-release")) { platform = "gentoo" - contents, err := common.ReadLines("/etc/gentoo-release") + contents, err := common.ReadLines(common.HostEtc("gentoo-release")) if err == nil { version = getRedhatishVersion(contents) } - } else if common.PathExists("/etc/SuSE-release") { - contents, err := common.ReadLines("/etc/SuSE-release") + } else if common.PathExists(common.HostEtc("SuSE-release")) { + contents, err := common.ReadLines(common.HostEtc("SuSE-release")) if err == nil { version = getSuseVersion(contents) platform = getSusePlatform(contents) } // TODO: slackware detecion - } else if common.PathExists("/etc/arch-release") { + } else if common.PathExists(common.HostEtc("arch-release")) { platform = "arch" version = lsb.Release } else if lsb.ID == "RedHat" { diff --git a/internal/common/common.go b/internal/common/common.go index 53e0667..9cff834 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -274,3 +274,7 @@ func HostProc(combineWith ...string) string { func HostSys(combineWith ...string) string { return GetEnv("HOST_SYS", "/sys", combineWith...) } + +func HostEtc(combineWith ...string) string { + return GetEnv("HOST_ETC", "/etc", combineWith...) +} diff --git a/internal/common/common_test.go b/internal/common/common_test.go index b2660b2..b7bda8b 100644 --- a/internal/common/common_test.go +++ b/internal/common/common_test.go @@ -88,3 +88,10 @@ func TestPathExists(t *testing.T) { t.Error("not exists but return exists") } } + +func TestHostEtc(t *testing.T) { + p := HostEtc("mtab") + if p != "/etc/mtab" { + t.Errorf("invalid HostEtc, %s", p) + } +}