Fix sxmo_power.sh polkit multi-session auth and dmenu PATH
This commit is contained in:
@@ -14,39 +14,62 @@ usage() {
|
||||
run_polkit_login1() {
|
||||
method="$1"
|
||||
python3 - "$method" <<'PYEOF' >/dev/null 2>&1
|
||||
import os, pty, select, sys
|
||||
import os, pty, select, sys, time
|
||||
method = sys.argv[1]
|
||||
ppid = os.getpid()
|
||||
if method == "Reboot":
|
||||
acts = "org.freedesktop.login1.reboot org.freedesktop.login1.reboot-multiple-sessions org.freedesktop.login1.reboot-ignore-inhibit"
|
||||
acts = [
|
||||
"org.freedesktop.login1.reboot",
|
||||
"org.freedesktop.login1.reboot-multiple-sessions",
|
||||
"org.freedesktop.login1.reboot-ignore-inhibit",
|
||||
]
|
||||
else:
|
||||
acts = "org.freedesktop.login1.power-off org.freedesktop.login1.power-off-multiple-sessions org.freedesktop.login1.power-off-ignore-inhibit"
|
||||
cmd = (
|
||||
"pkttyagent --process $$ & AG=$!; sleep 0.15; "
|
||||
"for act in " + acts + "; do "
|
||||
"pkcheck --action-id $act --process $$ -u >/dev/null 2>&1 || true; "
|
||||
"done; "
|
||||
"kill $AG 2>/dev/null || true; "
|
||||
"exec busctl call --allow-interactive-authorization=true "
|
||||
"org.freedesktop.login1 /org/freedesktop/login1 "
|
||||
"org.freedesktop.login1.Manager " + method + " b true"
|
||||
)
|
||||
pid, fd = pty.fork()
|
||||
if pid == 0:
|
||||
os.execlp("sh", "sh", "-c", cmd)
|
||||
while True:
|
||||
r, _, _ = select.select([fd], [], [], 3.0)
|
||||
if not r:
|
||||
break
|
||||
acts = [
|
||||
"org.freedesktop.login1.power-off",
|
||||
"org.freedesktop.login1.power-off-multiple-sessions",
|
||||
"org.freedesktop.login1.power-off-ignore-inhibit",
|
||||
]
|
||||
for act in acts:
|
||||
cmd = (
|
||||
f"pkttyagent --process {ppid} & AG=$!; sleep 0.25; "
|
||||
f"pkcheck --action-id {act} --process {ppid} -u >/dev/null 2>&1; "
|
||||
f"RC=$?; kill $AG 2>/dev/null || true; exit $RC"
|
||||
)
|
||||
pid, fd = pty.fork()
|
||||
if pid == 0:
|
||||
os.execlp("sh", "sh", "-c", cmd)
|
||||
t0 = time.time()
|
||||
buf = b""
|
||||
while time.time() - t0 < 5.0:
|
||||
r, _, _ = select.select([fd], [], [], 0.2)
|
||||
if r:
|
||||
try:
|
||||
d = os.read(fd, 1024)
|
||||
if not d:
|
||||
break
|
||||
buf += d
|
||||
if b"assword:" in buf or b"password:" in buf.lower():
|
||||
buf = b""
|
||||
os.write(fd, b"147147\n")
|
||||
except OSError:
|
||||
break
|
||||
try:
|
||||
d = os.read(fd, 1024)
|
||||
if not d:
|
||||
break
|
||||
if b"assword:" in d or b"password" in d.lower():
|
||||
os.write(fd, b"147147\n")
|
||||
os.close(fd)
|
||||
except OSError:
|
||||
break
|
||||
_, st = os.waitpid(pid, 0)
|
||||
sys.exit(os.WEXITSTATUS(st))
|
||||
pass
|
||||
os.waitpid(pid, 0)
|
||||
os.execlp(
|
||||
"busctl",
|
||||
"busctl",
|
||||
"call",
|
||||
"--allow-interactive-authorization=true",
|
||||
"org.freedesktop.login1",
|
||||
"/org/freedesktop/login1",
|
||||
"org.freedesktop.login1.Manager",
|
||||
method,
|
||||
"b",
|
||||
"true",
|
||||
)
|
||||
PYEOF
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+11
-4
@@ -2290,8 +2290,7 @@ process_x11_events(void)
|
||||
return;
|
||||
}
|
||||
if (ev.type == KeyRelease) {
|
||||
if (query_trigger_keys_down() == 0)
|
||||
initial_released = 1;
|
||||
initial_released = 1;
|
||||
continue;
|
||||
}
|
||||
if (!initial_released || now < start_ignore)
|
||||
@@ -2308,8 +2307,7 @@ process_x11_events(void)
|
||||
}
|
||||
if (is_enter) {
|
||||
if (ev.type == KeyRelease) {
|
||||
if (query_trigger_keys_down() == 0)
|
||||
initial_released = 1;
|
||||
initial_released = 1;
|
||||
continue;
|
||||
}
|
||||
if (!initial_released || dmenu_now_ms() < start_ignore)
|
||||
@@ -2713,6 +2711,15 @@ dmenu_run_main(int argc, char *argv[])
|
||||
if (getenv("DMENU_WRAP_AROUND"))
|
||||
wrap_around = 1;
|
||||
|
||||
const char *cur_path = getenv("PATH");
|
||||
if (!cur_path || !strstr(cur_path, "/home/user/.local/bin")) {
|
||||
char new_path[1024];
|
||||
snprintf(new_path, sizeof(new_path),
|
||||
"/home/user/.config/sxmo/hooks:/home/user/.local/bin:/usr/share/sxmo/default_hooks:%s",
|
||||
(cur_path && cur_path[0]) ? cur_path : "/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin");
|
||||
setenv("PATH", new_path, 1);
|
||||
}
|
||||
|
||||
int lock_fd = -1;
|
||||
int fifo_fd = -1;
|
||||
int sock_fd = -1;
|
||||
|
||||
Reference in New Issue
Block a user