@@ -10,7 +10,12 @@ import (
1010 "time"
1111)
1212
13- const wrapperIDComment = "# Pin Wrapper generated by Go tool funkoverage"
13+ const (
14+ wrapperIDComment = "# Pin Wrapper generated by Go tool funkoverage"
15+ defaultPinToolSearchDir = "/usr/lib64/coverage-tools"
16+ defaultLogDir = "/var/coverage/data"
17+ defaultSafeBinDir = "/var/coverage/bin"
18+ )
1419
1520// --- Wrapper Management ---
1621
@@ -73,15 +78,15 @@ func wrap(targetBinary string) error {
7378 }
7479 PIN_TOOL_SEARCH_DIR := os .Getenv ("PIN_TOOL_SEARCH_DIR" )
7580 if PIN_TOOL_SEARCH_DIR == "" {
76- PIN_TOOL_SEARCH_DIR = "/usr/lib64/coverage-tools"
81+ PIN_TOOL_SEARCH_DIR = defaultPinToolSearchDir
7782 }
7883 LOG_DIR := os .Getenv ("LOG_DIR" )
7984 if LOG_DIR == "" {
80- LOG_DIR = "/var/coverage/data"
85+ LOG_DIR = defaultLogDir
8186 }
8287 SAFE_BIN_DIR := os .Getenv ("SAFE_BIN_DIR" )
8388 if SAFE_BIN_DIR == "" {
84- SAFE_BIN_DIR = "/var/coverage/bin"
89+ SAFE_BIN_DIR = defaultSafeBinDir
8590 }
8691 pinTool , err := findPinTool (PIN_TOOL_SEARCH_DIR )
8792 if err != nil {
@@ -110,7 +115,7 @@ func wrap(targetBinary string) error {
110115 if err != nil {
111116 return err
112117 }
113- // change tmpdir permissions to allow execution from all users
118+ // change tmpdir permissions to allow execution from all users
114119 if err := os .Chmod (tmpDir , 0755 ); err != nil {
115120 return fmt .Errorf ("could not set permissions on temp dir: %w" , err )
116121 }
@@ -184,7 +189,35 @@ func findPinTool(searchDir string) (string, error) {
184189 return nil
185190 })
186191 if found == "" {
187- return "" , errors .New ("FuncTracer.so not found" )
192+ return "" , errors .New ("FuncTracer.so not found. Look for it in the $PIN_TOOL_SEARCH_DIR env variable or " + defaultPinToolSearchDir + " directory " )
188193 }
189194 return found , nil
190195}
196+
197+ func wrapMany (binaries []string ) error {
198+ var failed []string
199+ for _ , bin := range binaries {
200+ if err := wrap (bin ); err != nil {
201+ fmt .Fprintf (os .Stderr , "wrap error for %s: %v\n " , bin , err )
202+ failed = append (failed , bin )
203+ }
204+ }
205+ if len (failed ) > 0 {
206+ return fmt .Errorf ("failed to wrap: %v" , failed )
207+ }
208+ return nil
209+ }
210+
211+ func unwrapMany (binaries []string ) error {
212+ var failed []string
213+ for _ , bin := range binaries {
214+ if err := unwrap (bin ); err != nil {
215+ fmt .Fprintf (os .Stderr , "unwrap error for %s: %v\n " , bin , err )
216+ failed = append (failed , bin )
217+ }
218+ }
219+ if len (failed ) > 0 {
220+ return fmt .Errorf ("failed to unwrap: %v" , failed )
221+ }
222+ return nil
223+ }
0 commit comments