Skip to content

Commit

Permalink
runc: replace debug-trace.go debug-flag.go
Browse files Browse the repository at this point in the history
Signed-off-by: LEI WANG <[email protected]>
  • Loading branch information
ssst0n3 committed Mar 13, 2024
1 parent c8050a9 commit b866543
Showing 1 changed file with 12 additions and 38 deletions.
50 changes: 12 additions & 38 deletions runc/v1.1.11/patch/0002-Add-make-debug.patch
Original file line number Diff line number Diff line change
@@ -1,70 +1,44 @@
diff --git a/Makefile b/Makefile
index 7ce26c6..e424632 100644
index e3af9bc..059f3d1 100644
--- a/Makefile
+++ b/Makefile
@@ -136,6 +136,14 @@ shell:
@@ -136,6 +136,14 @@ shell: runcimage
-v $(CURDIR):/go/src/$(PROJECT) \
$(RUNC_IMAGE) bash

+debug:
+ mv debug-trace.go debug-trace.go.bak || echo ""
+ mv debug-flag.go debug-flag.go.bak || echo ""
+ make EXTRA_FLAGS='-gcflags="all=-N -l"' static
+ mv runc runc-v1.1.11-debug
+ mv debug-trace.go.bak debug-trace.go
+ mv debug-flag.go.bak debug-flag.go
+ make EXTRA_FLAGS='-gcflags="all=-N -l"' static
+ mv runc runc-v1.1.11-debug-auto-wait-tracing
+ mv runc runc-v1.1.11-debug-flag
+
install:
install -D -m0755 runc $(DESTDIR)$(BINDIR)/runc

diff --git a/debug-trace.go b/debug-trace.go
diff --git a/debug-flag.go b/debug-flag.go
new file mode 100644
index 0000000..ca6cccb
index 0000000..647ef4d
--- /dev/null
+++ b/debug-trace.go
@@ -0,0 +1,45 @@
+++ b/debug-flag.go
@@ -0,0 +1,18 @@
+package main
+
+import (
+ "bufio"
+ "os"
+ "strings"
+ "time"
+)
+
+func isBeingTraced() (tracing bool) {
+ file, err := os.Open("/proc/self/status")
+ if err != nil {
+ panic(err)
+ }
+ defer file.Close()
+
+ scanner := bufio.NewScanner(file)
+ for scanner.Scan() {
+ line := scanner.Text()
+ if strings.HasPrefix(line, "TracerPid:") {
+ tracerPidInfo := strings.Fields(line)
+ if len(tracerPidInfo) == 2 && tracerPidInfo[1] != "0" {
+ return true
+ }
+ break
+ }
+ }
+
+ if err := scanner.Err(); err != nil {
+ panic(err)
+ }
+
+ return
+}
+
+func init() {
+ if len(os.Args) > 1 && os.Args[1] == "init" {
+ var flag bool
+ for {
+ if isBeingTraced() {
+ if flag {
+ break
+ }
+ time.Sleep(time.Second)
+ }
+ }
+}
\ No newline at end of file

0 comments on commit b866543

Please sign in to comment.