[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: PATCH: inotifyd.c: Implement a builtin 'echo' command
From: Flemming Madsen <busybox () themadsens ! dk>
Date: 2011-09-26 18:55:11
Message-ID: CACWu54X4oUBmK-HUy7JsKOWozTT_tSzUV8E5fO-dHf=+a63hOA () mail ! gmail ! com
[Download RAW message or body]
inotifyd.c: Implement a builtin 'echo' command for simply outputting
events on stdout.
Signed-off-by: Flemming Madsen <busybox@themadsens.dk>
---
This will allow programs&scripts to popen() 'inotifyd echo ...'
for easy inotify functionality without excessive fork/exec overhead.
["01-inotifyd-echo.patch" (text/x-patch)]
inotifyd.c: Implement a builtin 'echo' command for simply outputting events on stdout.
Signed-off-by: Flemming Madsen <busybox@themadsens.dk>
---
This will allow programs&scripts to popen() 'inotifyd echo ...'
for easy inotify functionality without excessive fork/exec overhead.
Index: busybox/busybox-1.19.2/miscutils/inotifyd.c
===================================================================
--- busybox.orig/busybox-1.19.2/miscutils/inotifyd.c 2011-08-22 04:57:49.000000000 +0200
+++ busybox/busybox-1.19.2/miscutils/inotifyd.c 2011-09-26 09:23:52.000000000 +0200
@@ -88,6 +88,7 @@
struct pollfd pfd;
char **watches; // names of files being watched
const char *args[5];
+ int echo;
// sanity check: agent and at least one watch must be given
if (!argv[1] || !argv[2])
@@ -101,6 +102,7 @@
args[0] = *argv;
args[4] = NULL;
argc -= 2; // number of files we watch
+ echo = strcmp(*argv, "echo") == 0;
// open inotify
pfd.fd = inotify_init();
@@ -177,12 +179,20 @@
*s++ = mask_names[i];
}
*s = '\0';
-// bb_error_msg("exec %s %08X\t%s\t%s\t%s", args[0],
-// ie->mask, events, watches[ie->wd], ie->len ? ie->name : "");
- args[1] = events;
- args[2] = watches[ie->wd];
- args[3] = ie->len ? ie->name : NULL;
- spawn_and_wait((char **)args);
+ if (echo) {
+ printf("%s\t%s%s%s\n", events, \
+ watches[ie->wd], \
+ ie->len ? "\t" : "", ie->len ? ie->name : "");
+ fflush(stdout);
+ }
+ else {
+// bb_error_msg("exec %s %08X\t%s\t%s\t%s", args[0],
+// ie->mask, events, watches[ie->wd], ie->len ? ie->name : "");
+ args[1] = events;
+ args[2] = watches[ie->wd];
+ args[3] = ie->len ? ie->name : NULL;
+ spawn_and_wait((char **)args);
+ }
// we are done if all files got final x event
if (ie->mask & 0x8000) {
if (--argc <= 0)
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic