setcap 부활

This commit is contained in:
2023-11-24 16:02:31 +09:00
parent 84543f9a31
commit d4cd792950
5 changed files with 33 additions and 95 deletions

View File

@ -153,16 +153,15 @@ func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) *
if err == nil && fi.IsDir() {
exefile := "./" + path.Clean(strings.TrimPrefix(req.Args[0], "/"))
os.Chmod(path.Join(verpath, exefile), 0777)
err = set_permission(path.Join(verpath, exefile))
if err != nil {
logger.Println("set_permission failed :", err)
return nil
}
exef, _ := os.Executable()
cmd := exec.Command(path.Join(path.Dir(exef), verpath, exefile), req.Args[1:]...)
if err := run_prelaunch_script(cmd.Args[0]); err != nil {
logger.Println("run_prelaunch_script failed :", cmd.Args[0], err)
return nil
}
cmd.Dir = verpath
stdin, _ := cmd.StdinPipe()

View File

@ -1,47 +0,0 @@
//go:build client && linux
package client
import (
"errors"
"io/fs"
"os"
"os/exec"
"path"
"repositories.action2quare.com/ayo/gocommon/logger"
)
func run_prelaunch_script(exepath string) error {
scriptPath := path.Join(path.Dir(exepath), "prelaunch.sh")
fi, err := os.Stat(scriptPath)
if errors.Is(err, fs.ErrNotExist) {
logger.Println("prelaunch.sh not exists :", scriptPath, err)
return nil
}
if fi == nil {
logger.Println("prelaunch.sh fi is nil :", scriptPath)
return nil
}
os.Chmod(scriptPath, 0777)
logger.Println("run_prelaunch_script :", "/bin/bash", scriptPath, exepath)
return exec.Command("/bin/bash", scriptPath, exepath).Run()
}
func run_postlaunch_script(exepath string) error {
scriptPath := path.Join(path.Dir(exepath), "postlaunch.sh")
fi, err := os.Stat(scriptPath)
if errors.Is(err, fs.ErrNotExist) {
return nil
}
if fi == nil {
return nil
}
os.Chmod(scriptPath, 0777)
return exec.Command("/bin/bash", scriptPath, exepath).Run()
}

View File

@ -1,42 +0,0 @@
//go:build !(client && linux)
package client
import (
"errors"
"io/fs"
"os"
"os/exec"
"path"
)
func run_prelaunch_script(exepath string) error {
scriptPath := path.Join(path.Dir(exepath), "prelaunch.bat")
fi, err := os.Stat(scriptPath)
if errors.Is(err, fs.ErrNotExist) {
return nil
}
if fi == nil {
return nil
}
os.Chmod(scriptPath, 0777)
return exec.Command("cmd", scriptPath).Run()
}
func run_postlaunch_script(exepath string) error {
scriptPath := path.Join(path.Dir(exepath), "postlaunch.bat")
fi, err := os.Stat(scriptPath)
if errors.Is(err, fs.ErrNotExist) {
return nil
}
if fi == nil {
return nil
}
os.Chmod(scriptPath, 0777)
return exec.Command("cmd", scriptPath).Run()
}

View File

@ -0,0 +1,7 @@
//go:build client && windows
package client
func set_permission(path string) error {
return nil
}

View File

@ -0,0 +1,21 @@
//go:build client && linux
package client
import (
"os"
"os/exec"
)
func init() {
file, _ := os.OpenFile("setcap.sh", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0777)
file.Write([]byte("sudo setcap 'cap_net_bind_service=+ep' $1"))
file.Sync()
file.Close()
}
func set_permission(path string) error {
os.Chmod(path, 0777)
cmd := exec.Command("/bin/bash", "./setcap.sh", path)
return cmd.Run()
}