Skip to content

Commit

Permalink
add doas support #37
Browse files Browse the repository at this point in the history
elesiuta committed Dec 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent a6186af commit 301c821
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions picosnitch.py
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@
import queue
import resource
import shlex
import shutil
import signal
import site
import socket
@@ -72,6 +73,8 @@
home_user = pwd.getpwuid(int(os.getenv("SUDO_UID"))).pw_name
elif os.getenv("SUDO_USER"):
home_user = os.getenv("SUDO_USER")
elif os.getenv("DOAS_USER"):
home_user = os.getenv("DOAS_USER")
else:
for home_user in os.listdir("/home"):
try:
@@ -2240,8 +2243,12 @@ def start_picosnitch():
return 0
elif sys.argv[1] in ["start", "stop", "restart", "start-no-daemon", "systemd"]:
if os.getuid() != 0:
args = ["sudo", "-E", sys.executable, os.path.abspath(__file__), sys.argv[1]]
os.execvp("sudo", args)
if shutil.which("doas") and os.path.exists("/etc/doas.conf"):
args = ["doas", sys.executable, os.path.abspath(__file__), sys.argv[1]]
os.execvp("doas", args)
else:
args = ["sudo", "-E", sys.executable, os.path.abspath(__file__), sys.argv[1]]
os.execvp("sudo", args)
with open("/proc/self/status", "r") as f:
proc_status = f.read()
capeff = int(proc_status[proc_status.find("CapEff:")+8:].splitlines()[0].strip(), base=16)

0 comments on commit 301c821

Please sign in to comment.