logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: b59a513ae6363a380f46fcab7360cbe29be71b9e
parent 4b7bdfacd40b81b7844b22851ee0d7f8f56f40c2
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 25 Jul 2025 04:35:37 +0200

cmd/timeout: add support for long options

Diffstat:

Mcmd/timeout.c19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/cmd/timeout.c b/cmd/timeout.c @@ -4,6 +4,7 @@ #define _POSIX_C_SOURCE 200809L #define _DEFAULT_SOURCE // For NSIG in sys_signame.h, thanks glibc +#include "../config.h" #include "../lib/sys_signame.h" #include "../libutils/getopt_nolong.h" #include "../libutils/strtodur.h" @@ -19,6 +20,9 @@ #include <sys/wait.h> #include <time.h> // nanosleep #include <unistd.h> // getopt +#ifdef HAS_GETOPT_LONG +#include <getopt.h> +#endif #define CMD_EXIT_TIMEOUT 124 #define CMD_EXIT_FAILURE 125 @@ -61,7 +65,22 @@ main(int argc, char *argv[]) char *arg = NULL; +#ifdef HAS_GETOPT_LONG + // Strictly for GNUisms compatibility so no long-only options + // clang-format off + static struct option opts[] = { + {"kill-after", required_argument, NULL, 'k'}, + {"preserve-status", required_argument, NULL, 'p'}, + {"signal", required_argument, NULL, 's'}, + {0, 0, 0, 0}, + }; + // clang-format on + + // Need + as first character to get POSIX-style option parsing + for(int c = -1; (c = getopt_long(argc, argv, "+:fk:ps:", opts, NULL)) != -1;) +#else for(int c = -1; (c = getopt_nolong(argc, argv, ":fk:ps:")) != -1;) +#endif { switch(c) {