From e4cee3c190b6efad64ea874579b0b7943b4114b3 Mon Sep 17 00:00:00 2001 From: WAKAYAMA shirou Date: Wed, 30 Apr 2014 16:19:39 +0900 Subject: [PATCH 1/2] golint on freebsd. --- cpu_freebsd.go | 2 +- disk_freebsd.go | 36 ++++++++++++++++++------------------ host_freebsd.go | 8 ++++---- mem_freebsd.go | 4 ++-- process_freebsd.go | 8 ++++---- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/cpu_freebsd.go b/cpu_freebsd.go index 19095e4..86a3102 100644 --- a/cpu_freebsd.go +++ b/cpu_freebsd.go @@ -23,7 +23,7 @@ const ( // TODO: get per cpus func CPUTimes(percpu bool) ([]CPUTimesStat, error) { - var ret []CPU_TimesStat + var ret []CPUTimesStat cpuTime, err := doSysctrl("kern.cp_time") if err != nil { diff --git a/disk_freebsd.go b/disk_freebsd.go index 92e23a8..e05e36d 100644 --- a/disk_freebsd.go +++ b/disk_freebsd.go @@ -9,7 +9,7 @@ import ( ) func DiskPartitions(all bool) ([]DiskPartitionStat, error) { - var ret []Disk_partitionStat + var ret []DiskPartitionStat // get length count, err := syscall.Getfsstat(nil, MNT_WAIT) @@ -22,56 +22,56 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) { for _, stat := range fs { opts := "rw" - if stat.F_flags&MNT_RDONLY != 0 { + if stat.FFlags&MNT_RDONLY != 0 { opts = "ro" } - if stat.F_flags&MNT_SYNCHRONOUS != 0 { + if stat.FFlags&MNT_SYNCHRONOUS != 0 { opts += ",sync" } - if stat.F_flags&MNT_NOEXEC != 0 { + if stat.FFlags&MNT_NOEXEC != 0 { opts += ",noexec" } - if stat.F_flags&MNT_NOSUID != 0 { + if stat.FFlags&MNT_NOSUID != 0 { opts += ",nosuid" } - if stat.F_flags&MNT_UNION != 0 { + if stat.FFlags&MNT_UNION != 0 { opts += ",union" } - if stat.F_flags&MNT_ASYNC != 0 { + if stat.FFlags&MNT_ASYNC != 0 { opts += ",async" } - if stat.F_flags&MNT_SUIDDIR != 0 { + if stat.FFlags&MNT_SUIDDIR != 0 { opts += ",suiddir" } - if stat.F_flags&MNT_SOFTDEP != 0 { + if stat.FFlags&MNT_SOFTDEP != 0 { opts += ",softdep" } - if stat.F_flags&MNT_NOSYMFOLLOW != 0 { + if stat.FFlags&MNT_NOSYMFOLLOW != 0 { opts += ",nosymfollow" } - if stat.F_flags&MNT_GJOURNAL != 0 { + if stat.FFlags&MNT_GJOURNAL != 0 { opts += ",gjounalc" } - if stat.F_flags&MNT_MULTILABEL != 0 { + if stat.FFlags&MNT_MULTILABEL != 0 { opts += ",multilabel" } - if stat.F_flags&MNT_ACLS != 0 { + if stat.FFlags&MNT_ACLS != 0 { opts += ",acls" } - if stat.F_flags&MNT_NOATIME != 0 { + if stat.FFlags&MNT_NOATIME != 0 { opts += ",noattime" } - if stat.F_flags&MNT_NOCLUSTERR != 0 { + if stat.FFlags&MNT_NOCLUSTERR != 0 { opts += ",nocluster" } - if stat.F_flags&MNT_NOCLUSTERW != 0 { + if stat.FFlags&MNT_NOCLUSTERW != 0 { opts += ",noclusterw" } - if stat.F_flags&MNT_NFS4ACLS != 0 { + if stat.FFlags&MNT_NFS4ACLS != 0 { opts += ",nfs4acls" } - d := Disk_partitionStat{ + d := DiskPartitionStat{ Mountpoint: byteToString(stat.FMntonname[:]), Fstype: byteToString(stat.FFstypename[:]), Opts: opts, diff --git a/host_freebsd.go b/host_freebsd.go index 7952187..c999473 100644 --- a/host_freebsd.go +++ b/host_freebsd.go @@ -68,10 +68,10 @@ func Users() ([]UserStat, error) { continue } user := UserStat{ - User: byteToString(u.Ut_name[:]), - Terminal: byteToString(u.Ut_line[:]), - Host: byteToString(u.Ut_host[:]), - Started: int(u.Ut_time), + User: byteToString(u.UtName[:]), + Terminal: byteToString(u.UtLine[:]), + Host: byteToString(u.UtHost[:]), + Started: int(u.UtTime), } ret = append(ret, user) } diff --git a/mem_freebsd.go b/mem_freebsd.go index 9cd56e0..7535118 100644 --- a/mem_freebsd.go +++ b/mem_freebsd.go @@ -3,13 +3,13 @@ package gopsutil func VirtualMemory() (VirtualMemoryStat, error) { - ret := Virtual_memoryStat{} + ret := VirtualMemoryStat{} return ret, nil } func SwapMemory() (SwapMemoryStat, error) { - ret := Swap_memoryStat{} + ret := SwapMemoryStat{} return ret, nil } diff --git a/process_freebsd.go b/process_freebsd.go index 7bc6d99..e91368c 100644 --- a/process_freebsd.go +++ b/process_freebsd.go @@ -132,7 +132,7 @@ func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) { return &ret, errors.New("not implemented yet") } -func copyParams(k *Kinfo_proc, p *Process) error { +func copyParams(k *KinfoProc, p *Process) error { return nil } @@ -147,7 +147,7 @@ func processes() ([]Process, error) { } // get kinfo_proc size - k := Kinfo_proc{} + k := KinfoProc{} procinfoLen := int(unsafe.Sizeof(k)) count := int(length / uint64(procinfoLen)) @@ -158,7 +158,7 @@ func processes() ([]Process, error) { if err != nil { continue } - p, err := NewProcess(int32(k.Ki_pid)) + p, err := NewProcess(int32(k.KiPid)) if err != nil { continue } @@ -223,7 +223,7 @@ func NewProcess(pid int32) (*Process, error) { p := &Process{Pid: pid} mib := []int32{CTL_KERN, KERN_PROC, KERN_PROC_PID, p.Pid} - buf, length, err := call_syscall(mib) + buf, length, err := callSyscall(mib) if err != nil { return nil, err } From 6c201fdc5de2eaa0d276f911874092ab78f50f22 Mon Sep 17 00:00:00 2001 From: WAKAYAMA shirou Date: Wed, 30 Apr 2014 16:22:54 +0900 Subject: [PATCH 2/2] fix func exporting. --- common.go | 4 ++-- cpu_linux.go | 2 +- disk_linux.go | 6 +++--- net_linux.go | 2 +- process_posix_test.go | 19 +++++++++++++++++++ process_test_posix.go | 19 ------------------- 6 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 process_posix_test.go delete mode 100644 process_test_posix.go diff --git a/common.go b/common.go index 0b4f9c1..9130303 100644 --- a/common.go +++ b/common.go @@ -13,8 +13,8 @@ import ( "strings" ) -// ReadLines read contents from file and split by new line. -func ReadLines(filename string) ([]string, error) { +// readLines read contents from file and split by new line. +func readLines(filename string) ([]string, error) { f, err := os.Open(filename) if err != nil { return []string{""}, err diff --git a/cpu_linux.go b/cpu_linux.go index 9938635..b7b2073 100644 --- a/cpu_linux.go +++ b/cpu_linux.go @@ -12,7 +12,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) { var ret []CPUTimesStat filename := "/proc/stat" - lines, _ := ReadLines(filename) + lines, _ := readLines(filename) for _, line := range lines { ct, err := parseStatLine(line) if err != nil { diff --git a/disk_linux.go b/disk_linux.go index 5fccbd2..c98ef7a 100644 --- a/disk_linux.go +++ b/disk_linux.go @@ -17,7 +17,7 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) { var ret []DiskPartitionStat filename := "/etc/mtab" - lines, err := ReadLines(filename) + lines, err := readLines(filename) if err != nil { return ret, err } @@ -40,7 +40,7 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) { // determine partitions we want to look for filename := "/proc/partitions" - lines, err := ReadLines(filename) + lines, err := readLines(filename) if err != nil { return ret, err } @@ -62,7 +62,7 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) { } filename = "/proc/diskstats" - lines, err = ReadLines(filename) + lines, err = readLines(filename) if err != nil { return ret, err } diff --git a/net_linux.go b/net_linux.go index 06578a3..ad2b8a7 100644 --- a/net_linux.go +++ b/net_linux.go @@ -8,7 +8,7 @@ import ( func NetIOCounters() ([]NetIOCountersStat, error) { filename := "/proc/net/dev" - lines, err := ReadLines(filename) + lines, err := readLines(filename) if err != nil { return make([]NetIOCountersStat, 0), err } diff --git a/process_posix_test.go b/process_posix_test.go new file mode 100644 index 0000000..b45418a --- /dev/null +++ b/process_posix_test.go @@ -0,0 +1,19 @@ +// +build linux freebsd + +package gopsutil + +import ( + "os" + "syscall" + "testing" +) + +func Test_SendSignal(t *testing.T) { + checkPid := os.Getpid() + + p, _ := NewProcess(int32(checkPid)) + err := p.SendSignal(syscall.SIGCONT) + if err != nil { + t.Errorf("send signal %v", err) + } +} diff --git a/process_test_posix.go b/process_test_posix.go deleted file mode 100644 index 103efce..0000000 --- a/process_test_posix.go +++ /dev/null @@ -1,19 +0,0 @@ -// +build linux freebsd - -package gopsutil - -import ( - "os" - "syscall" - "testing" -) - -func TestSendSignal(t *testing.T) { - checkPid := os.Getpid() - - p, _ := NewProcess(int32(checkPid)) - err := p.SendSignal(syscall.SIGCONT) - if err != nil { - t.Errorf("send signal %v", err) - } -}