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.
pull/110/head
lawl 3 years ago
parent 245455d508
commit 6ea788a0c0

@ -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)

@ -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)

@ -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),

Loading…
Cancel
Save