From 6ea788a0c0de72a387895c09d84e7a24061677eb Mon Sep 17 00:00:00 2001 From: lawl Date: Mon, 5 Apr 2021 15:08:20 +0200 Subject: [PATCH] Refactor: Remove old method of removing rlimit for pulseaudio Previously we had the capability to remove the rlimit on pulseaudio by calling ourselves via pkexec to elevate privileges. A while ago we switched to fully using capabilities. We now remove the old legacy codepath. --- main.go | 15 --------------- module.go | 10 +++------- rlimit.go | 16 ---------------- 3 files changed, 3 insertions(+), 38 deletions(-) diff --git a/main.go b/main.go index a7817ac..7aed3cf 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,6 @@ import ( "os" "path/filepath" "strings" - "syscall" "time" "github.com/BurntSushi/xgbutil" @@ -47,7 +46,6 @@ const appName = "NoiseTorch" func main() { - var pulsepid int var setcap bool var sinkName string var unload bool @@ -56,7 +54,6 @@ func main() { var threshold int var list bool - flag.IntVar(&pulsepid, "removerlimit", -1, "for internal use only") flag.BoolVar(&setcap, "setcap", false, "for internal use only") flag.StringVar(&sinkName, "s", "", "Use the specified source/sink device ID") flag.BoolVar(&loadInput, "i", false, "Load supressor for input. If no source device ID is specified the default pulse audio source is used.") @@ -74,18 +71,6 @@ func main() { os.Exit(0) } - //TODO:remove this after 0.10. Not required anymore after that. - //We don't remove it right now, since someone could have an old instance running that calls the updated binary - if pulsepid > 0 { - const MaxUint = ^uint64(0) - new := syscall.Rlimit{Cur: MaxUint, Max: MaxUint} - err := setRlimit(pulsepid, &new) - if err != nil { - os.Exit(1) - } - os.Exit(0) - } - date := time.Now().Format("2006_01_02_15_04_05") tmpdir := os.TempDir() f, err := os.OpenFile(filepath.Join(tmpdir, fmt.Sprintf("noisetorch-%s.log", date)), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) diff --git a/module.go b/module.go index 009b132..25bd45a 100644 --- a/module.go +++ b/module.go @@ -120,13 +120,9 @@ func loadSupressor(ctx *ntcontext, inp *device, out *device) error { return err } log.Printf("Rlimit: %+v. Trying to remove.\n", lim) - if hasCapSysResource(getCurrentCaps()) { - log.Printf("Have capabilities\n") - removeRlimit(pid) - } else { - log.Printf("Capabilities missing, removing via pkexec\n") - removeRlimitAsRoot(pid) - } + + removeRlimit(pid) + defer setRlimit(pid, &lim) // lowering RLIMIT doesn't require root newLim, err := getRlimit(pid) diff --git a/rlimit.go b/rlimit.go index 4f08750..75d09c6 100644 --- a/rlimit.go +++ b/rlimit.go @@ -3,8 +3,6 @@ package main import ( "io/ioutil" "log" - "os" - "os/exec" "strconv" "strings" "syscall" @@ -52,20 +50,6 @@ func removeRlimit(pid int) { } } -func removeRlimitAsRoot(pid int) { - self, err := os.Executable() - if err != nil { - log.Fatalf("Couldn't find path to own binary\n") - } - - cmd := exec.Command("pkexec", self, "-removerlimit", strconv.Itoa(pid)) - log.Printf("Calling: %s\n", cmd.String()) - err = cmd.Run() - if err != nil { - log.Printf("Couldn't remove rlimit as root: %v\n", err) - } -} - func pRlimit(pid int, limit uintptr, new *syscall.Rlimit, old *syscall.Rlimit) error { _, _, errno := syscall.RawSyscall6(syscall.SYS_PRLIMIT64, uintptr(pid),