mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-11-23 20:36:21 +01:00
Check caller's euid and egid when accessing /dev/mem on FreeBSD.
This commit is contained in:
parent
6ef3b7a4e8
commit
a10ab2c102
@ -4,6 +4,7 @@ package collector
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
@ -49,6 +50,10 @@ func NewStatCollector(config Config) (Collector, error) {
|
|||||||
|
|
||||||
// Expose cpu stats using kvm
|
// Expose cpu stats using kvm
|
||||||
func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
|
if os.Geteuid() != 0 && os.Getegid() != 2 {
|
||||||
|
return errors.New("Caller should be either root user or kmem group to access /dev/mem")
|
||||||
|
}
|
||||||
|
|
||||||
var errbuf *C.char
|
var errbuf *C.char
|
||||||
kd := C.kvm_open(nil, nil, nil, C.O_RDONLY, errbuf)
|
kd := C.kvm_open(nil, nil, nil, C.O_RDONLY, errbuf)
|
||||||
if errbuf != nil {
|
if errbuf != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user