mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 10:01:30 +00:00
platform: Add service error wrapper for macOS system extension
This commit is contained in:
parent
94f76d6671
commit
a8ee41715a
|
@ -93,13 +93,11 @@ func (s *CommandServer) listenUNIX() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return E.Cause(err, "listen ", sockPath)
|
return E.Cause(err, "listen ", sockPath)
|
||||||
}
|
}
|
||||||
if sUserID > 0 {
|
err = os.Chown(sockPath, sUserID, sGroupID)
|
||||||
err = os.Chown(sockPath, sUserID, sGroupID)
|
if err != nil {
|
||||||
if err != nil {
|
listener.Close()
|
||||||
listener.Close()
|
os.Remove(sockPath)
|
||||||
os.Remove(sockPath)
|
return E.Cause(err, "chown")
|
||||||
return E.Cause(err, "chown")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
s.listener = listener
|
s.listener = listener
|
||||||
go s.loopConnection(listener)
|
go s.loopConnection(listener)
|
||||||
|
|
|
@ -20,13 +20,11 @@ func RedirectStderr(path string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if runtime.GOOS != "android" {
|
if runtime.GOOS != "android" {
|
||||||
if sUserID > 0 {
|
err = outputFile.Chown(sUserID, sGroupID)
|
||||||
err = outputFile.Chown(sUserID, sGroupID)
|
if err != nil {
|
||||||
if err != nil {
|
outputFile.Close()
|
||||||
outputFile.Close()
|
os.Remove(outputFile.Name())
|
||||||
os.Remove(outputFile.Name())
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = unix.Dup2(int(outputFile.Fd()), int(os.Stderr.Fd()))
|
err = unix.Dup2(int(outputFile.Fd()), int(os.Stderr.Fd()))
|
||||||
|
|
32
experimental/libbox/service_error.go
Normal file
32
experimental/libbox/service_error.go
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package libbox
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func serviceErrorPath() string {
|
||||||
|
return filepath.Join(sWorkingPath, "network_extension_error")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ClearServiceError() {
|
||||||
|
os.Remove(serviceErrorPath())
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadServiceError() (string, error) {
|
||||||
|
data, err := os.ReadFile(serviceErrorPath())
|
||||||
|
if err == nil {
|
||||||
|
os.Remove(serviceErrorPath())
|
||||||
|
}
|
||||||
|
return string(data), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func WriteServiceError(message string) error {
|
||||||
|
errorFile, err := os.Create(serviceErrorPath())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
errorFile.WriteString(message)
|
||||||
|
errorFile.Chown(sUserID, sGroupID)
|
||||||
|
return errorFile.Close()
|
||||||
|
}
|
|
@ -25,6 +25,8 @@ func Setup(basePath string, workingPath string, tempPath string, isTVOS bool) {
|
||||||
sUserID = os.Getuid()
|
sUserID = os.Getuid()
|
||||||
sGroupID = os.Getgid()
|
sGroupID = os.Getgid()
|
||||||
sTVOS = isTVOS
|
sTVOS = isTVOS
|
||||||
|
os.MkdirAll(sWorkingPath, 0o777)
|
||||||
|
os.MkdirAll(sTempPath, 0o777)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupWithUsername(basePath string, workingPath string, tempPath string, username string) error {
|
func SetupWithUsername(basePath string, workingPath string, tempPath string, username string) error {
|
||||||
|
@ -37,6 +39,10 @@ func SetupWithUsername(basePath string, workingPath string, tempPath string, use
|
||||||
}
|
}
|
||||||
sUserID, _ = strconv.Atoi(sUser.Uid)
|
sUserID, _ = strconv.Atoi(sUser.Uid)
|
||||||
sGroupID, _ = strconv.Atoi(sUser.Gid)
|
sGroupID, _ = strconv.Atoi(sUser.Gid)
|
||||||
|
os.MkdirAll(sWorkingPath, 0o777)
|
||||||
|
os.MkdirAll(sTempPath, 0o777)
|
||||||
|
os.Chown(sWorkingPath, sUserID, sGroupID)
|
||||||
|
os.Chown(sTempPath, sUserID, sGroupID)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue