From 83bfe521b1a554a02d0f33fb982cd740339ebd05 Mon Sep 17 00:00:00 2001 From: Kr328 Date: Sat, 5 Mar 2022 18:25:16 +0800 Subject: [PATCH 1/2] Fix: should split linux process name with space (#2008) --- component/process/process_linux.go | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/component/process/process_linux.go b/component/process/process_linux.go index be758a69..0ca42716 100644 --- a/component/process/process_linux.go +++ b/component/process/process_linux.go @@ -9,7 +9,9 @@ import ( "os" "path" "path/filepath" + "strings" "syscall" + "unicode" "unsafe" "github.com/Dreamacro/clash/common/pool" @@ -219,24 +221,15 @@ func resolveProcessNameByProcSearch(inode, uid int) (string, error) { } func splitCmdline(cmdline []byte) string { - indexOfEndOfString := len(cmdline) + idx := bytes.IndexFunc(cmdline, func(r rune) bool { + return unicode.IsControl(r) || unicode.IsSpace(r) + }) - for i, c := range cmdline { - if c == 0 { - indexOfEndOfString = i - break - } - } - - return filepath.Base(string(cmdline[:indexOfEndOfString])) + return filepath.Base(string(cmdline[:idx])) } func isPid(s string) bool { - for _, s := range s { - if s < '0' || s > '9' { - return false - } - } - - return true + return strings.IndexFunc(s, func(r rune) bool { + return !unicode.IsDigit(r) + }) == -1 } From f6c7281bb71d8e08547fad1395f26bf4549111a9 Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Sun, 6 Mar 2022 21:48:25 +0800 Subject: [PATCH 2/2] Chore: update github action workflow --- .github/workflows/codeql-analysis.yml | 8 ++++---- .github/workflows/docker.yml | 4 ++-- .github/workflows/linter.yml | 16 +++++++++++++--- .github/workflows/release.yml | 2 +- .github/workflows/stale.yml | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ae1a2793..8a36dc97 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -1,8 +1,8 @@ -name: "CodeQL" +name: CodeQL on: push: - branches: [ master, dev ] + branches: [master, dev] jobs: analyze: @@ -12,11 +12,11 @@ jobs: strategy: fail-fast: false matrix: - language: [ 'go' ] + language: ['go'] steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Initialize CodeQL uses: github/codeql-action/init@v1 diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f0ad1ea8..38860d5b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 @@ -52,7 +52,7 @@ jobs: - name: Get all docker tags if: startsWith(github.ref, 'refs/tags/') - uses: actions/github-script@v4 + uses: actions/github-script@v6 id: tags with: script: | diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 26d318c3..a81cfc1c 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -4,9 +4,19 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + + - name: Get latest go version + id: version + run: | + echo ::set-output name=go_version::$(curl -s https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json | grep -oE '"version": "[0-9]{1}.[0-9]{1,}(.[0-9]{1,})?"' | head -1 | cut -d':' -f2 | sed 's/ //g; s/"//g') + + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: ${{ steps.version.outputs.go_version }} + - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v3 with: version: latest - args: --disable-all -E govet -E gofumpt -E megacheck ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d4bad8a3..8226d875 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,7 @@ jobs: go-version: ${{ steps.version.outputs.go_version }} - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Cache go module uses: actions/cache@v2 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 68f986ff..34cd0d31 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/stale@v4 + - uses: actions/stale@v5 with: stale-issue-message: 'This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days' days-before-stale: 60