diff --git a/.gitignore b/.gitignore index 96a1fad..f549d46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ test main +launchergo *.so retroarch-core-options.cfg *.lpl diff --git a/build.sh b/build.sh index b866eb3..feda8bc 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ #!/bin/bash set -x -go build main.go mainscreen.go +go build -o launchergo main.go mainscreen.go #go build -ldflags="-s -w" -o main main.go mainscreen.go diff --git a/deploy.sh b/deploy.sh index 96c90d5..ea72aa6 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,5 +1,5 @@ #!/bin/bash set -x DST=/home/cpi/launchergo -cp -f main $DST +cp -f launcher $DST diff --git a/launchergo b/launchergo new file mode 100755 index 0000000..a8d8db1 Binary files /dev/null and b/launchergo differ diff --git a/main.go b/main.go index a6d901d..c48e0ac 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "runtime" "path/filepath" "os/exec" + "syscall" //"encoding/json" gotime "time" "github.com/veandco/go-sdl2/sdl" @@ -263,6 +264,37 @@ func PreparationInAdv(){ } +func release_self_fds() { + fds_flags := []string{"pipe","socket:",".ttf"} + file_paths,err := filepath.Glob("/proc/self/fd/*") + if err != nil { + fmt.Println("release_self_fds error",err) + return + } + + ret := make(map[string]string) + path := "" + for _,v := range file_paths { + path,err = os.Readlink(v) + if err == nil { + ret[v] = path + } + } + + for k,v := range ret { + for _,f := range fds_flags { + if strings.Contains(v,f) { + id,_ := strconv.Atoi(filepath.Base(k)) + //fmt.Println("closing ",id) + err = syscall.Close(id) + if err != nil { + fmt.Println("syscall.CLose err ",err) + } + } + } + } +} + func run() int { display.Init() font.Init() @@ -335,6 +367,7 @@ func run() int { exec_app_cmd += ev.Data["Msg"] exec_app_cmd +="; sync & cd "+UI.GetExePath()+"; "+os.Args[0]+";" fmt.Println(exec_app_cmd) + release_self_fds() cmd := exec.Command("/bin/sh","-c",exec_app_cmd) err := cmd.Start() if err != nil { @@ -349,6 +382,7 @@ func run() int { case UI.RUNSYS: main_screen.OnExitCb() gogame.Quit() + release_self_fds() exec_app_cmd := ev.Data["Msg"] cmd := exec.Command("/bin/sh","-c",exec_app_cmd) err := cmd.Start() @@ -368,6 +402,7 @@ func run() int { fmt.Println("RUNSH") exec_app_cmd := ev.Data["Msg"]+";" fmt.Println(exec_app_cmd) + release_self_fds() cmd := exec.Command("/bin/sh","-c",exec_app_cmd) err := cmd.Start() if err != nil { @@ -384,6 +419,7 @@ func run() int { gogame.Quit() exec_app_cmd :=" sync & cd "+UI.GetExePath()+"; "+os.Args[0]+";" fmt.Println(exec_app_cmd) + release_self_fds() cmd := exec.Command("/bin/sh","-c",exec_app_cmd) err := cmd.Start() if err != nil {