On Wed, Apr 23, 2025 at 05:42:36PM +0000, Listeria monocytogenes wrote:
> I just tried it on linux and the connection is closed even if we don't
> request it
I don't know if this is documented or not but Xlib uses xcb internally
and xcb opens the connection with CLOEXEC:
https://lists.freedesktop.org/archives/xcb/2013-March/008207.html
> I think it makes more sense to use posix_spawn_file_actions_* if we're
> using posix_spawn
It really doesn't. As you can already see, posix_spawn interface is
absolutely garbagely designed for anything non-trivial. The whole
posix_spawn_file_actions_t thing should've been an array where the user
puts his "commands" in, instead of some opaque struct that needs to be
error checked for every single call.
In any case, explicitly closing the xfd would be consistent with the
previous state so I agree with doing it. But you should use CLOEXEC like
your first patch instead of posix_spawn_file_actions_*.
Suggestion (untested):
pid_t pid;
extern char **environ;
int err = 0;
int xfd = ConnectionNumber(dpy);
int flags = fcntl(xfd, F_GETFD);
if (flags < 0 || fcntl(xfd, F_SETFD, flags | FD_CLOEXEC) < 0)
err = errno;
if (!err)
err = posix_spawnp(&pid, argv[0], NULL, NULL, argv, environ);
if (err) {
die("slock: failed to execute post-lock command: %s: %s\n",
- NRK
Received on Wed Apr 23 2025 - 20:50:22 CEST