aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-06-19 17:14:18 +0200
committerPřemysl Eric Janouch <p@janouch.name>2023-06-19 19:06:16 +0200
commit4cc1baf429bd770937fb31f6aa4ab5b6b4d3d316 (patch)
tree69a5fa5620d2ff69514363ee8df2e037e073887f
parent957aed63a8caed3107d53fe818e1e1ee77247574 (diff)
downloaddesktop-tools-4cc1baf429bd770937fb31f6aa4ab5b6b4d3d316.tar.gz
desktop-tools-4cc1baf429bd770937fb31f6aa4ab5b6b4d3d316.tar.xz
desktop-tools-4cc1baf429bd770937fb31f6aa4ab5b6b4d3d316.zip
iexec: enable watching a different path
-rw-r--r--LICENSE2
-rw-r--r--iexec.c12
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 <p@janouch.name>
+Copyright (c) 2015 - 2023, Přemysl Eric Janouch <p@janouch.name>
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