From d9e994bec8652904d6756a1ccfe737a1a0ecb56d Mon Sep 17 00:00:00 2001 From: WAKAYAMA shirou Date: Sat, 23 Apr 2016 23:10:23 +0900 Subject: [PATCH 1/4] [host]freebsd: update freebsd_amd64 --- host/host_freebsd.go | 6 ++---- host/host_freebsd_amd64.go | 9 ++++++--- host/types_freebsd.go | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/host/host_freebsd.go b/host/host_freebsd.go index 06142e1..aeb1b45 100644 --- a/host/host_freebsd.go +++ b/host/host_freebsd.go @@ -101,13 +101,11 @@ func Users() ([]UserStat, error) { return ret, err } - u := Utmpx{} - entrySize := int(unsafe.Sizeof(u)) - 3 - entrySize = 197 // TODO: why should 197 + entrySize := sizeOfUtmpx count := len(buf) / entrySize for i := 0; i < count; i++ { - b := buf[i*entrySize : i*entrySize+entrySize] + b := buf[i*sizeOfUtmpx : (i+1)*sizeOfUtmpx] var u Utmpx br := bytes.NewReader(b) err := binary.Read(br, binary.LittleEndian, &u) diff --git a/host/host_freebsd_amd64.go b/host/host_freebsd_amd64.go index 9a4c0a4..3f015f0 100644 --- a/host/host_freebsd_amd64.go +++ b/host/host_freebsd_amd64.go @@ -9,6 +9,7 @@ const ( sizeofInt = 0x4 sizeofLong = 0x8 sizeofLongLong = 0x8 + sizeOfUtmpx = 197 // TODO: why should 197, not 0x118 ) type ( @@ -24,17 +25,19 @@ type Utmp struct { Host [16]int8 Time int32 } + type Utmpx struct { Type int16 Tv Timeval - ID [8]int8 + Id [8]int8 Pid int32 User [32]int8 Line [16]int8 Host [125]int8 - // Host [128]int8 - // X__ut_spare [64]int8 + // Host [128]int8 + // X__ut_spare [64]int8 } + type Timeval struct { Sec [4]byte Usec [3]byte diff --git a/host/types_freebsd.go b/host/types_freebsd.go index 113b22e..e70677f 100644 --- a/host/types_freebsd.go +++ b/host/types_freebsd.go @@ -27,6 +27,7 @@ const ( sizeofInt = C.sizeof_int sizeofLong = C.sizeof_long sizeofLongLong = C.sizeof_longlong + sizeOfUtmpx = C.sizeof_struct_utmpx ) // Basic types From 01832c6a58c54193d3312ae70533e0d2b1523248 Mon Sep 17 00:00:00 2001 From: WAKAYAMA shirou Date: Sat, 23 Apr 2016 23:18:18 +0900 Subject: [PATCH 2/4] [host]freebsd: add freebsd_386. --- host/host_freebsd_386.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 host/host_freebsd_386.go diff --git a/host/host_freebsd_386.go b/host/host_freebsd_386.go new file mode 100644 index 0000000..7f06d8f --- /dev/null +++ b/host/host_freebsd_386.go @@ -0,0 +1,43 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_freebsd.go + +package host + +const ( + sizeofPtr = 0x4 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x4 + sizeofLongLong = 0x8 + sizeOfUtmpx = 197 // TODO why should 197 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 +) + +type Utmp struct { + Line [8]int8 + Name [16]int8 + Host [16]int8 + Time int32 +} + +type Utmpx struct { + Type int16 + Tv Timeval + Id [8]int8 + Pid int32 + User [32]int8 + Line [16]int8 + Host [125]int8 + // X__ut_spare [64]int8 +} + +type Timeval struct { + Sec [4]byte + Usec [3]byte +} From e864f2a037bf2e2e62d20e2f132ab08e261b6e71 Mon Sep 17 00:00:00 2001 From: WAKAYAMA shirou Date: Sat, 23 Apr 2016 23:43:00 +0900 Subject: [PATCH 3/4] [disk]freebsd: update 386. --- disk/disk_freebsd_386.go | 6 +++++- disk/disk_test.go | 5 ++++- host/host_test.go | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/disk/disk_freebsd_386.go b/disk/disk_freebsd_386.go index 6d4b597..0b3f536 100644 --- a/disk/disk_freebsd_386.go +++ b/disk/disk_freebsd_386.go @@ -39,6 +39,10 @@ const ( MNT_SUSPEND = 4 ) +const ( + sizeOfDevstat = 0xf0 +) + type ( _C_short int16 _C_int int32 @@ -95,7 +99,7 @@ type Devstat struct { Flags uint32 Device_type uint32 Priority uint32 - ID *byte + Id *byte Sequence1 uint32 } type Bintime struct { diff --git a/disk/disk_test.go b/disk/disk_test.go index c475c26..8023c03 100644 --- a/disk/disk_test.go +++ b/disk/disk_test.go @@ -26,6 +26,9 @@ func TestDisk_partitions(t *testing.T) { t.Errorf("error %v", err) } empty := PartitionStat{} + if len(ret) == 0 { + t.Errorf("ret is empty") + } for _, disk := range ret { if disk == empty { t.Errorf("Could not get device info %v", disk) @@ -39,7 +42,7 @@ func TestDisk_io_counters(t *testing.T) { t.Errorf("error %v", err) } if len(ret) == 0 { - t.Errorf("ret is empty, %v", ret) + t.Errorf("ret is empty") } empty := IOCountersStat{} for part, io := range ret { diff --git a/host/host_test.go b/host/host_test.go index c4c5afa..2bf395c 100644 --- a/host/host_test.go +++ b/host/host_test.go @@ -32,6 +32,9 @@ func TestUsers(t *testing.T) { t.Errorf("error %v", err) } empty := UserStat{} + if len(v) == 0 { + t.Errorf("Users is empty") + } for _, u := range v { if u == empty { t.Errorf("Could not Users %v", v) From a9040e612c9156d9ad6d13fbdd88e153c568b054 Mon Sep 17 00:00:00 2001 From: WAKAYAMA shirou Date: Sat, 23 Apr 2016 23:47:50 +0900 Subject: [PATCH 4/4] [process]freebsd: update 386. --- process/process_freebsd_386.go | 287 ++++++++++++++++++++++++----------------- 1 file changed, 169 insertions(+), 118 deletions(-) diff --git a/process/process_freebsd_386.go b/process/process_freebsd_386.go index 201f714..05e96d0 100644 --- a/process/process_freebsd_386.go +++ b/process/process_freebsd_386.go @@ -1,141 +1,192 @@ -// +build freebsd -// +build 386 +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_freebsd.go package process -// copied from sys/sysctl.h const ( - CTLKern = 1 // "high kernel": proc, limits - KernProc = 14 // struct: process entries - KernProcPID = 1 // by process id - KernProcProc = 8 // only return procs - KernProcPathname = 12 // path to executable - KernProcArgs = 7 // get/set arguments/proctitle + CTLKern = 1 + KernProc = 14 + KernProcPID = 1 + KernProcProc = 8 + KernProcPathname = 12 + KernProcArgs = 7 ) const ( - SIDL = 1 - SRUN = 2 - SSLEEP = 3 - SSTOP = 4 - SZOMB = 5 - SWAIT = 6 - SLOCK = 7 + sizeofPtr = 0x4 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x4 + sizeofLongLong = 0x8 ) const ( - sizeOfKinfoVmentry = 0x244 // TODO: really? - sizeOfKinfoProc = 0x220 + sizeOfKinfoVmentry = 0x488 + sizeOfKinfoProc = 0x300 +) + +const ( + SIDL = 1 + SRUN = 2 + SSLEEP = 3 + SSTOP = 4 + SZOMB = 5 + SWAIT = 6 + SLOCK = 7 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 ) type Timespec struct { - Sec int32 - Nsec int32 + Sec int32 + Nsec int32 } type Timeval struct { - Sec int32 - Usec int32 + Sec int32 + Usec int32 } type Rusage struct { - Utime Timeval - Stime Timeval - Maxrss int32 - Ixrss int32 - Idrss int32 - Isrss int32 - Minflt int32 - Majflt int32 - Nswap int32 - Inblock int32 - Oublock int32 - Msgsnd int32 - Msgrcv int32 - Nsignals int32 - Nvcsw int32 - Nivcsw int32 + Utime Timeval + Stime Timeval + Maxrss int32 + Ixrss int32 + Idrss int32 + Isrss int32 + Minflt int32 + Majflt int32 + Nswap int32 + Inblock int32 + Oublock int32 + Msgsnd int32 + Msgrcv int32 + Nsignals int32 + Nvcsw int32 + Nivcsw int32 +} + +type Rlimit struct { + Cur int64 + Max int64 } -// copied from sys/user.h type KinfoProc struct { - Structsize int32 - Layout int32 - Args int32 - Paddr int32 - Addr int32 - Tracep int32 - Textvp int32 - Fd int32 - Vmspace int32 - Wchan int32 - Pid int32 - Ppid int32 - Pgid int32 - Tpgid int32 - Sid int32 - Tsid int32 - Jobc [2]byte - SpareShort1 [2]byte - Tdev int32 - Siglist [16]byte - Sigmask [16]byte - Sigignore [16]byte - Sigcatch [16]byte - Uid int32 - Ruid int32 - Svuid int32 - Rgid int32 - Svgid int32 - Ngroups int16 - SpareShort2 [2]byte - Groups [64]byte - Size int32 - Rssize int32 - Swrss int32 - Tsize int32 - Dsize int32 - Ssize int32 - Xstat [2]byte - Acflag [2]byte - Pctcpu int32 - Estcpu int32 - Slptime int32 - Swtime int32 - Cow int32 - Runtime int64 - Start [8]byte - Childtime [8]byte - Flag int32 - Kflag int32 - Traceflag int32 - Stat int8 - Nice [1]byte - Lock [1]byte - Rqindex [1]byte - Oncpu [1]byte - Lastcpu [1]byte - Ocomm [17]byte - Wmesg [9]byte - Login [18]byte - Lockname [9]byte - Comm [20]int8 - Emul [17]byte - Sparestrings [68]byte - Spareints [36]byte - CrFlags int32 - Jid int32 - Numthreads int32 - Tid int32 - Pri int32 - Rusage Rusage - RusageCh [72]byte - Pcb int32 - Kstack int32 - Udata int32 - Tdaddr int32 - Spareptrs [24]byte - Spareint64s [48]byte - Sflag int32 - Tdflags int32 + Structsize int32 + Layout int32 + Args int32 /* pargs */ + Paddr int32 /* proc */ + Addr int32 /* user */ + Tracep int32 /* vnode */ + Textvp int32 /* vnode */ + Fd int32 /* filedesc */ + Vmspace int32 /* vmspace */ + Wchan int32 + Pid int32 + Ppid int32 + Pgid int32 + Tpgid int32 + Sid int32 + Tsid int32 + Jobc int16 + Spare_short1 int16 + Tdev uint32 + Siglist [16]byte /* sigset */ + Sigmask [16]byte /* sigset */ + Sigignore [16]byte /* sigset */ + Sigcatch [16]byte /* sigset */ + Uid uint32 + Ruid uint32 + Svuid uint32 + Rgid uint32 + Svgid uint32 + Ngroups int16 + Spare_short2 int16 + Groups [16]uint32 + Size uint32 + Rssize int32 + Swrss int32 + Tsize int32 + Dsize int32 + Ssize int32 + Xstat uint16 + Acflag uint16 + Pctcpu uint32 + Estcpu uint32 + Slptime uint32 + Swtime uint32 + Cow uint32 + Runtime uint64 + Start Timeval + Childtime Timeval + Flag int32 + Kiflag int32 + Traceflag int32 + Stat int8 + Nice int8 + Lock int8 + Rqindex int8 + Oncpu uint8 + Lastcpu uint8 + Tdname [17]int8 + Wmesg [9]int8 + Login [18]int8 + Lockname [9]int8 + Comm [20]int8 + Emul [17]int8 + Loginclass [18]int8 + Sparestrings [50]int8 + Spareints [7]int32 + Flag2 int32 + Fibnum int32 + Cr_flags uint32 + Jid int32 + Numthreads int32 + Tid int32 + Pri Priority + Rusage Rusage + Rusage_ch Rusage + Pcb int32 /* pcb */ + Kstack int32 + Udata int32 + Tdaddr int32 /* thread */ + Spareptrs [6]int32 + Sparelongs [12]int32 + Sflag int32 + Tdflags int32 +} + +type Priority struct { + Class uint8 + Level uint8 + Native uint8 + User uint8 +} + +type KinfoVmentry struct { + Structsize int32 + Type int32 + Start uint64 + End uint64 + Offset uint64 + Vn_fileid uint64 + Vn_fsid uint32 + Flags int32 + Resident int32 + Private_resident int32 + Protection int32 + Ref_count int32 + Shadow_count int32 + Vn_type int32 + Vn_size uint64 + Vn_rdev uint32 + Vn_mode uint16 + Status uint16 + X_kve_ispare [12]int32 + Path [1024]int8 }