--- NOTE: if we want to assume the former (i.e not die if post-lock cmd fails) then `die()` can be replaced with `fprintf(stderr, ...)`. slock.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/slock.c b/slock.c index 5ae738c..8afb7da 100644 --- a/slock.c +++ b/slock.c _AT_@ -13,6 +13,7 @@ #include <stdio.h> #include <string.h> #include <unistd.h> +#include <spawn.h> #include <sys/types.h> #include <X11/extensions/Xrandr.h> #include <X11/keysym.h> _AT_@ -376,15 +377,12 @@ main(int argc, char **argv) { /* run post-lock command */ if (argc > 0) { - switch (fork()) { - case -1: - die("slock: fork failed: %s\n", strerror(errno)); - case 0: - if (close(ConnectionNumber(dpy)) < 0) - die("slock: close: %s\n", strerror(errno)); - execvp(argv[0], argv); - fprintf(stderr, "slock: execvp %s: %s\n", argv[0], strerror(errno)); - _exit(1); + pid_t pid; + extern char **environ; + int err = posix_spawnp(&pid, argv[0], NULL, NULL, argv, environ); + if (err) { + die("slock: failed to execute post-lock command: %s: %s\n", + argv[0], strerror(err)); } } -- 2.35.1Received on Fri Sep 09 2022 - 10:50:12 CEST
This archive was generated by hypermail 2.3.0 : Fri Sep 09 2022 - 11:00:38 CEST