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