diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 48a6030..8b133c3 100755 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -61,7 +61,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.22' + go-version: '1.23' check-latest: true - name: Get project dependencies diff --git a/go.mod b/go.mod index 33d89e4..7f80f5c 100755 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module XrayHelper -go 1.22 +go 1.23 require ( github.com/coreos/go-iptables v0.7.0 diff --git a/go.sum b/go.sum old mode 100755 new mode 100644 diff --git a/main/builds/version.go b/main/builds/version.go index fafb932..176202a 100755 --- a/main/builds/version.go +++ b/main/builds/version.go @@ -10,7 +10,7 @@ const ( VersionX byte = 1 VersionY byte = 4 VersionZ byte = 5 - Build = "-release" + Build = "-fix1" Intro = "A unified helper for Android to control system proxy.\n\nTelegram channel: https://t.me/Asterisk4Magisk\nTelegram chat: https://t.me/AsteriskFactory\n\nReport issues at https://github.com/Asterisk4Magisk/XrayHelper/issues\n" ) diff --git a/main/cgroup/cgroup.go b/main/cgroup/cgroup.go index c6d838c..d120607 100644 --- a/main/cgroup/cgroup.go +++ b/main/cgroup/cgroup.go @@ -59,59 +59,58 @@ func LimitProcess(pid int) error { return err } mountPoint = mp - // create cpu limit - if cpuLimit != 100.0 { - if err := os.MkdirAll(filepath.Join(mountPoint, "cpuctl", name), 0o755); err != nil { - return e.New("cannot create cpuctl cgroup, ", err).WithPrefix(tagCgroup) - } - if err := os.WriteFile( - filepath.Join(mountPoint, "cpuctl", name, "cpu.uclamp.max"), - []byte(strconv.FormatFloat(cpuLimit, 'f', 2, 64)), - os.FileMode(0), - ); err != nil { - log.HandleDebug("kernel not support uclamp, skip cpu.uclamp.max") - } - if err := os.WriteFile( - filepath.Join(mountPoint, "cpuctl", name, "cpu.shares"), - []byte(strconv.FormatInt(int64(cpuLimit*0.01*1024), 10)), - os.FileMode(0), - ); err != nil { - return e.New("cannot apply cpuctl cgroup, ", err).WithPrefix(tagCgroup) - } + } + // create cpu limit + if cpuLimit != 100.0 { + if err := os.MkdirAll(filepath.Join(mountPoint, "cpuctl", name), 0o755); err != nil { + return e.New("cannot create cpuctl cgroup, ", err).WithPrefix(tagCgroup) } - // create memory limit - if memLimit > 0 { - if err := os.MkdirAll(filepath.Join(mountPoint, "memcg", name), 0o755); err != nil { - return e.New("cannot create memcg cgroup, ", err).WithPrefix(tagCgroup) - } - if err := os.WriteFile( - filepath.Join(mountPoint, "memcg", name, "memory.limit_in_bytes"), - // convert limit to bytes - []byte(strconv.FormatInt(int64(memLimit*1024*1024), 10)), - os.FileMode(0), - ); err != nil { - return e.New("cannot apply memcg cgroup, ", err).WithPrefix(tagCgroup) - } + if err := os.WriteFile( + filepath.Join(mountPoint, "cpuctl", name, "cpu.uclamp.max"), + []byte(strconv.FormatFloat(cpuLimit, 'f', 2, 64)), + os.FileMode(0), + ); err != nil { + log.HandleDebug("kernel not support uclamp, skip cpu.uclamp.max") + } + if err := os.WriteFile( + filepath.Join(mountPoint, "cpuctl", name, "cpu.shares"), + []byte(strconv.FormatInt(int64(cpuLimit*0.01*1024), 10)), + os.FileMode(0), + ); err != nil { + return e.New("cannot apply cpuctl cgroup, ", err).WithPrefix(tagCgroup) + } + // apply cpu limit + f, err := os.OpenFile(filepath.Join(mountPoint, "cpuctl", name, "cgroup.procs"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.FileMode(0)) + if err != nil { + return e.New("cannot open cpuctl cgroup procs, ", err).WithPrefix(tagCgroup) + } + defer f.Close() + if _, err := f.WriteString(strconv.FormatInt(int64(pid), 10) + "\n"); err != nil { + return e.New("cannot add process to cpuctl cgroup, ", err).WithPrefix(tagCgroup) } - - } - // apply cpu limit - f, err := os.OpenFile(filepath.Join(mountPoint, "cpuctl", name, "cgroup.procs"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.FileMode(0)) - if err != nil { - return e.New("cannot open cpuctl cgroup procs, ", err).WithPrefix(tagCgroup) - } - defer f.Close() - if _, err := f.WriteString(strconv.FormatInt(int64(pid), 10) + "\n"); err != nil { - return e.New("cannot add process to cpuctl cgroup, ", err).WithPrefix(tagCgroup) - } - // apply memory limit - f2, err := os.OpenFile(filepath.Join(mountPoint, "memcg", name, "cgroup.procs"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.FileMode(0)) - if err != nil { - return e.New("cannot open memcg cgroup procs, ", err).WithPrefix(tagCgroup) } - defer f2.Close() - if _, err := f2.WriteString(strconv.FormatInt(int64(pid), 10) + "\n"); err != nil { - return e.New("cannot add process to memcg cgroup, ", err).WithPrefix(tagCgroup) + // create memory limit + if memLimit > 0 { + if err := os.MkdirAll(filepath.Join(mountPoint, "memcg", name), 0o755); err != nil { + return e.New("cannot create memcg cgroup, ", err).WithPrefix(tagCgroup) + } + if err := os.WriteFile( + filepath.Join(mountPoint, "memcg", name, "memory.limit_in_bytes"), + // convert limit to bytes + []byte(strconv.FormatInt(int64(memLimit*1024*1024), 10)), + os.FileMode(0), + ); err != nil { + return e.New("cannot apply memcg cgroup, ", err).WithPrefix(tagCgroup) + } + // apply memory limit + f2, err := os.OpenFile(filepath.Join(mountPoint, "memcg", name, "cgroup.procs"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.FileMode(0)) + if err != nil { + return e.New("cannot open memcg cgroup procs, ", err).WithPrefix(tagCgroup) + } + defer f2.Close() + if _, err := f2.WriteString(strconv.FormatInt(int64(pid), 10) + "\n"); err != nil { + return e.New("cannot add process to memcg cgroup, ", err).WithPrefix(tagCgroup) + } } return nil }