mirror of
https://github.com/google/gops.git
synced 2024-11-24 08:22:25 +02:00
add magic number to avoid unexpected collison
This commit is contained in:
parent
aed64a20c4
commit
2973de6fe1
@ -207,6 +207,14 @@ func formatBytes(val uint64) string {
|
||||
}
|
||||
|
||||
func handle(conn io.ReadWriter, msg []byte) error {
|
||||
reader := bufio.NewReader(conn)
|
||||
magic, err := binary.ReadVarint(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if magic != internal.MAGIC {
|
||||
return fmt.Errorf("gops: invalid magic number: %v", magic)
|
||||
}
|
||||
switch msg[0] {
|
||||
case signal.StackTrace:
|
||||
return pprof.Lookup("goroutine").WriteTo(conn, 2)
|
||||
@ -286,7 +294,7 @@ func handle(conn io.ReadWriter, msg []byte) error {
|
||||
time.Sleep(5 * time.Second)
|
||||
trace.Stop()
|
||||
case signal.SetGCPercent:
|
||||
perc, err := binary.ReadVarint(bufio.NewReader(conn))
|
||||
perc, err := binary.ReadVarint(reader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -306,6 +306,9 @@ func cmdLazy(addr net.TCPAddr, c byte, params ...byte) (io.Reader, error) {
|
||||
return nil, err
|
||||
}
|
||||
buf := []byte{c}
|
||||
magic := make([]byte, binary.MaxVarintLen64)
|
||||
binary.PutVarint(magic, internal.MAGIC)
|
||||
buf = append(buf, magic...)
|
||||
buf = append(buf, params...)
|
||||
if _, err := conn.Write(buf); err != nil {
|
||||
return nil, err
|
||||
|
@ -13,7 +13,10 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const gopsConfigDirEnvKey = "GOPS_CONFIG_DIR"
|
||||
const (
|
||||
goipsConfigDirEnvKey = "GOPS_CONFIG_DIR"
|
||||
MAGIC = 0xabcdefedcba
|
||||
)
|
||||
|
||||
func ConfigDir() (string, error) {
|
||||
if configDir := os.Getenv(gopsConfigDirEnvKey); configDir != "" {
|
||||
|
Loading…
Reference in New Issue
Block a user