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 16:26:36 +0000

This no longer closes the connection to the X server before executing
the post-lock cmd. This patch should fix that, but doesn't die if
fcntl() fails, I'm not sure if that's desired.

---
 slock.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/slock.c b/slock.c
index b5a9b04..856c3e6 100644
--- a/slock.c
+++ b/slock.c
_AT_@ -6,6 +6,7 @@
 
 #include <ctype.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <grp.h>
 #include <pwd.h>
 #include <stdarg.h>
_AT_@ -59,7 +60,6 @@ die(const char *errstr, ...)
 }
 
 #ifdef __linux__
-#include <fcntl.h>
 #include <linux/oom.h>
 
 static void
_AT_@ -379,6 +379,10 @@ main(int argc, char **argv) {
 	if (argc > 0) {
 		pid_t pid;
 		extern char **environ;
+		int xfd = ConnectionNumber(dpy);
+		int flags = fcntl(xfd, F_GETFD);
+		if (flags >= 0)
+			fcntl(xfd, F_SETFD, flags | FD_CLOEXEC);
 		int err = posix_spawnp(&pid, argv[0], NULL, NULL, argv, environ);
 		if (err) {
 			die("slock: failed to execute post-lock command: %s: %s\n",
-- 
2.49.0
Received on Wed Apr 23 2025 - 18:26:36 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 23 2025 - 18:36:40 CEST