Re: [hackers] [slock] simplify post-lock cmd and die if it fails || NRK

From: Listeria monocytogenes <listeria_AT_disroot.org>
Date: Wed, 23 Apr 2025 17:42:36 +0000

I just tried it on linux and the connection is closed even if we don't
request it, I'm not sure how it works on other systems. Regardless, I
think it makes more sense to use posix_spawn_file_actions_* if we're
using posix_spawn, which would look something like this:

---
 slock.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/slock.c b/slock.c
index b5a9b04..e77d65c 100644
--- a/slock.c
+++ b/slock.c
_AT_@ -379,11 +379,21 @@ main(int argc, char **argv) {
 	if (argc > 0) {
 		pid_t pid;
 		extern char **environ;
-		int err = posix_spawnp(&pid, argv[0], NULL, NULL, argv, environ);
+		posix_spawn_file_actions_t fa;
+		int err = posix_spawn_file_actions_init(&fa);
+		if (err)
+			goto posix_spawnp_failed;
+
+                err = posix_spawn_file_actions_addclose(&fa, ConnectionNumber(dpy));
+		if (err)
+			goto posix_spawnp_failed;
+		err = posix_spawnp(&pid, argv[0], &fa, NULL, argv, environ);
 		if (err) {
+posix_spawnp_failed:
 			die("slock: failed to execute post-lock command: %s: %s\n",
 			    argv[0], strerror(err));
 		}
+		posix_spawn_file_actions_destroy(&fa);
 	}
 
 	/* everything is now blank. Wait for the correct password */
-- 
2.49.0
Received on Wed Apr 23 2025 - 19:42:36 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 23 2025 - 19:48:40 CEST