Skip to content

Commit

Permalink
Merge pull request #540 from mrostecki/err-check
Browse files Browse the repository at this point in the history
Check for returned errors
  • Loading branch information
Lomanic authored Jun 21, 2018
2 parents b488b27 + 9d003ad commit ebfe800
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cpu/cpu_solaris_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func TestParseProcessorInfo(t *testing.T) {
}

cpus, err := parseProcessorInfo(string(content))
if err != nil {
t.Errorf("cannot parse processor info: %s", err)
}

if !reflect.DeepEqual(tc.expected, cpus) {
t.Fatalf("Bad Processor Info\nExpected: %v\n Actual: %v", tc.expected, cpus)
Expand Down
4 changes: 3 additions & 1 deletion disk/disk_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
return ret, err
}
fs := make([]Statfs, count)
_, err = Getfsstat(fs, MntWait)
if _, err = Getfsstat(fs, MntWait); err != nil {
return ret, err
}
for _, stat := range fs {
opts := "rw"
if stat.Flags&MntReadOnly != 0 {
Expand Down
4 changes: 3 additions & 1 deletion disk/disk_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
}

fs := make([]Statfs, count)
_, err = Getfsstat(fs, MNT_WAIT)
if _, err = Getfsstat(fs, MNT_WAIT); err != nil {
return ret, err
}

for _, stat := range fs {
opts := "rw"
Expand Down
4 changes: 3 additions & 1 deletion disk/disk_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
}

fs := make([]Statfs, count)
_, err = Getfsstat(fs, MNT_WAIT)
if _, err = Getfsstat(fs, MNT_WAIT); err != nil {
return ret, err
}

for _, stat := range fs {
opts := "rw"
Expand Down
3 changes: 3 additions & 0 deletions host/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func TestBoot_time(t *testing.T) {
t.Logf("first boot time: %d", v)

v2, err := BootTime()
if err != nil {
t.Errorf("error %v", err)
}
if v != v2 {
t.Errorf("cached boot time is different")
}
Expand Down
3 changes: 3 additions & 0 deletions net/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ func TestNetConnectionStatString(t *testing.T) {

func TestNetIOCountersAll(t *testing.T) {
v, err := IOCounters(false)
if err != nil {
t.Errorf("Could not get NetIOCounters: %v", err)
}
per, err := IOCounters(true)
if err != nil {
t.Errorf("Could not get NetIOCounters: %v", err)
Expand Down
3 changes: 3 additions & 0 deletions process/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,9 @@ func (p *Process) fillFromTIDStatWithContext(ctx context.Context, tid int32) (ui
createTime := int64(ctime * 1000)

rtpriority, err := strconv.ParseInt(fields[i+16], 10, 32)
if err != nil {
return 0, 0, nil, 0, 0, 0, err
}
if rtpriority < 0 {
rtpriority = rtpriority*-1 - 1
} else {
Expand Down
6 changes: 6 additions & 0 deletions process/process_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func getTerminalMap() (map[uint64]string, error) {
defer d.Close()

devnames, err := d.Readdirnames(-1)
if err != nil {
return nil, err
}
for _, devname := range devnames {
if strings.HasPrefix(devname, "/dev/tty") {
termfiles = append(termfiles, "/dev/tty/"+devname)
Expand All @@ -45,6 +48,9 @@ func getTerminalMap() (map[uint64]string, error) {
if ptsnames == nil {
defer ptsd.Close()
ptsnames, err = ptsd.Readdirnames(-1)
if err != nil {
return nil, err
}
for _, ptsname := range ptsnames {
termfiles = append(termfiles, "/dev/pts/"+ptsname)
}
Expand Down
3 changes: 3 additions & 0 deletions process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func Test_Process_memory_maps(t *testing.T) {
checkPid := os.Getpid()

ret, err := NewProcess(int32(checkPid))
if err != nil {
t.Errorf("error %v", err)
}

mmaps, err := ret.MemoryMaps(false)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions process/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ func (p *Process) UsernameWithContext(ctx context.Context) (string, error) {
}
defer token.Close()
tokenUser, err := token.GetTokenUser()
if err != nil {
return "", err
}

user, domain, _, err := tokenUser.User.Sid.LookupAccount("")
return domain + "\\" + user, err
Expand Down

0 comments on commit ebfe800

Please sign in to comment.