This commit is contained in:
WAKAYAMA shirou 2014-04-22 17:39:51 +09:00
parent ac570a47a1
commit 4bf256a08a
4 changed files with 12 additions and 16 deletions

View File

@ -10,7 +10,6 @@ import (
"bufio"
"os"
"strings"
)
// Read contents from file and split by new line.
@ -33,8 +32,7 @@ func ReadLines(filename string) ([]string, error) {
return ret, err
}
func byteToString(orig []byte) string{
func byteToString(orig []byte) string {
n := -1
for i, b := range orig {
if b == 0 {
@ -42,9 +40,9 @@ func byteToString(orig []byte) string{
}
n = i + 1
}
if n == -1{
if n == -1 {
return string(orig)
}else{
} else {
return string(orig[:n])
}

View File

@ -9,6 +9,5 @@ import (
func Cpu_times() ([]CPU_TimesStat, error) {
ret := make([]CPU_TimesStat, 0)
fmt.Println("FreeBSD")
return ret, nil
}

View File

@ -3,8 +3,8 @@
package gopsutil
import (
"encoding/binary"
"bytes"
"encoding/binary"
"io/ioutil"
"os"
"syscall"
@ -75,17 +75,17 @@ func Users() ([]UserStat, error) {
for i := 0; i < count; i++ {
b := buf[i*entrySize : i*entrySize+entrySize]
var u utmp
br := bytes.NewReader(b)
err := binary.Read(br, binary.LittleEndian, &u)
var u utmp
br := bytes.NewReader(b)
err := binary.Read(br, binary.LittleEndian, &u)
if err != nil {
continue
}
user := UserStat{
User: byteToString(u.Ut_user[:]),
User: byteToString(u.Ut_user[:]),
Terminal: byteToString(u.Ut_line[:]),
Host: byteToString(u.Ut_host[:]),
Started: int(u.Ut_tv.Tv_sec),
Host: byteToString(u.Ut_host[:]),
Started: int(u.Ut_tv.Tv_sec),
}
ret = append(ret, user)
}

View File

@ -24,14 +24,13 @@ func TestBoot_time(t *testing.T) {
}
}
func TestUsers(t *testing.T) {
v, err := Users()
if err != nil {
t.Errorf("error %v", err)
}
for _, u := range v {
if u.User == ""{
for _, u := range v {
if u.User == "" {
t.Errorf("Could not Users %v", v)
}
}