github.com/sagernet/sing-box@v1.9.0-rc.20/experimental/libbox/service_error.go (about)

     1  package libbox
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  )
     7  
     8  func serviceErrorPath() string {
     9  	return filepath.Join(sWorkingPath, "network_extension_error")
    10  }
    11  
    12  func ClearServiceError() {
    13  	os.Remove(serviceErrorPath())
    14  }
    15  
    16  func ReadServiceError() (string, error) {
    17  	data, err := os.ReadFile(serviceErrorPath())
    18  	if err == nil {
    19  		os.Remove(serviceErrorPath())
    20  	}
    21  	return string(data), err
    22  }
    23  
    24  func WriteServiceError(message string) error {
    25  	errorFile, err := os.Create(serviceErrorPath())
    26  	if err != nil {
    27  		return err
    28  	}
    29  	errorFile.WriteString(message)
    30  	errorFile.Chown(sUserID, sGroupID)
    31  	return errorFile.Close()
    32  }