-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
58 lines (48 loc) · 1.1 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"os"
"unsafe"
"github.com/sirupsen/logrus"
)
// ByteOrder - host byte order
var ByteOrder binary.ByteOrder
func init() {
ByteOrder = getHostByteOrder()
}
// getHostByteOrder - Returns the host byte order
func getHostByteOrder() binary.ByteOrder {
var i int32 = 0x01020304
u := unsafe.Pointer(&i)
pb := (*byte)(u)
b := *pb
if b == 0x04 {
return binary.LittleEndian
}
return binary.BigEndian
}
// recoverAssets - Recover ebpf asset
func recoverAssets() io.ReaderAt {
buf, err := Asset("/probe.o")
if err != nil {
logrus.Fatal(errors.New(fmt.Sprintf("error:%v , couldn't find asset", err)))
}
return bytes.NewReader(buf)
}
// trigger - Creates and then removes a tmp folder to trigger the probes
func trigger() error {
logrus.Println("Generating events to trigger the probes ...")
// Creating a tmp directory to trigger the probes
tmpDir := "/tmp/test_folder"
logrus.Printf("creating %v", tmpDir)
err := os.MkdirAll(tmpDir, 0666)
if err != nil {
return err
}
// Removing the tmp directory
return os.RemoveAll(tmpDir)
}