From 4cc1baf429bd770937fb31f6aa4ab5b6b4d3d316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Mon, 19 Jun 2023 17:14:18 +0200 Subject: [PATCH] iexec: enable watching a different path --- LICENSE | 2 +- iexec.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index 7eda545..a146b5d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2015 - 2021, Přemysl Eric Janouch +Copyright (c) 2015 - 2023, Přemysl Eric Janouch Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. diff --git a/iexec.c b/iexec.c index 9853eb1..5e4c403 100644 --- a/iexec.c +++ b/iexec.c @@ -98,8 +98,10 @@ sigchld_handler (int signum) int main (int argc, char *argv[]) { + const char *target = NULL; static const struct opt opts[] = { + { 'f', "file", "PATH", 0, "watch this path rather than the program" }, { 'd', "debug", NULL, 0, "run in debug mode" }, { 'h', "help", NULL, 0, "display this help and exit" }, { 'V', "version", NULL, 0, "output version information and exit" }, @@ -116,6 +118,9 @@ main (int argc, char *argv[]) while ((c = opt_handler_get (&oh)) != -1) switch (c) { + case 'f': + target = optarg; + break; case 'd': g_debug_mode = true; break; @@ -141,6 +146,9 @@ main (int argc, char *argv[]) argc -= optind; argv += optind; + if (!target) + target = argv[0]; + (void) signal (SIGPIPE, SIG_IGN); struct sigaction sa = { .sa_handler = sigchld_handler }; sigemptyset (&sa.sa_mask); @@ -154,7 +162,7 @@ main (int argc, char *argv[]) exit_fatal ("sigprocmask: %s", strerror (errno)); char *path = NULL; - char *dir = dirname ((path = xstrdup (argv[0]))); + char *dir = dirname ((path = xstrdup (target))); if ((g_inotify_fd = inotify_init1 (IN_NONBLOCK)) < 0) exit_fatal ("inotify_init1: %s", strerror (errno)); @@ -163,7 +171,7 @@ main (int argc, char *argv[]) exit_fatal ("inotify_add_watch: %s", strerror (errno)); free (path); - char *base = basename ((path = xstrdup (argv[0]))); + char *base = basename ((path = xstrdup (target))); spawn (argv); do