Skip to content

Commit

Permalink
command/agent/host: uname returns an error string, windows
Browse files Browse the repository at this point in the history
  • Loading branch information
langmartin committed Jul 1, 2020
1 parent 4e88fad commit 81d430a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
7 changes: 1 addition & 6 deletions command/agent/host/host.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package host

import (
"fmt"
"os"
"strings"
)
Expand All @@ -21,10 +20,6 @@ type DiskUsage struct {
}

func MakeHostData() (*HostData, error) {
uname, err := uname()
if err != nil {
return nil, fmt.Errorf("error uname: %s", err.Error())
}
du := make(map[string]DiskUsage)
for _, path := range mountedPaths() {
u, err := diskUsage(path)
Expand All @@ -35,7 +30,7 @@ func MakeHostData() (*HostData, error) {
}

return &HostData{
OS: uname,
OS: uname(),
Network: network(),
ResolvConf: resolvConf(),
Hosts: etcHosts(),
Expand Down
5 changes: 2 additions & 3 deletions command/agent/host/unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
package host

import (
"fmt"
"strings"
"syscall"

"golang.org/x/sys/unix"
)

// uname returns the syscall like `uname -a`
func uname() (string, error) {
func uname() string {
u := &unix.Utsname{}
err := unix.Uname(u)
if err != nil {
return "", fmt.Errorf("error uname: %s", err.Error())
return err.Error()
}

uname := strings.Join([]string{
Expand Down
10 changes: 5 additions & 5 deletions command/agent/host/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func etcHosts() string {

func mountedPaths() (disks []string) {
for _, c := range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" {
_, err := os.Stat(string(c) + ":\\")
d := string(c) + ":\\"
_, err := os.Stat(d)
if err == nil {

disks = append(disks, c)
disks = append(disks, d)
}
}
}
Expand All @@ -39,7 +39,7 @@ type df struct {
avail int64
}

func makeDf(path string) *df {
func makeDf(path string) (*df, error) {
h := syscall.MustLoadDLL("kernel32.dll")
c := h.MustFindProc("GetDiskFreeSpaceExW")

Expand All @@ -49,7 +49,7 @@ func makeDf(path string) *df {
uintptr(unsafe.Pointer(&df.total)),
uintptr(unsafe.Pointer(&df.avail)))

return df
return df, nil
}

func (d *df) total() uint64 {
Expand Down

0 comments on commit 81d430a

Please sign in to comment.