aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/filemon.c
diff options
context:
space:
mode:
authorepochqwert <epoch@hacking.allowed.org>2015-06-28 00:15:29 -0500
committerepochqwert <epoch@hacking.allowed.org>2015-06-28 00:15:29 -0500
commit976c801cbe9ae8d03cae529b57a10cbb588fd92a (patch)
tree8c8a64ed504ec8abde678ddd10ab07d9536f3c50 /src/bin/filemon.c
parent5581f63df9034370cff54aeda44b365439b141fb (diff)
downloadmisc-976c801cbe9ae8d03cae529b57a10cbb588fd92a.tar.gz
misc-976c801cbe9ae8d03cae529b57a10cbb588fd92a.zip
fixed up a lot of warnings. added watch.
Diffstat (limited to 'src/bin/filemon.c')
-rw-r--r--src/bin/filemon.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/bin/filemon.c b/src/bin/filemon.c
index 2f0af24..ef7582b 100644
--- a/src/bin/filemon.c
+++ b/src/bin/filemon.c
@@ -10,27 +10,21 @@
#include <fcntl.h>
#include <err.h>
-int main(int argc, char *argv[]) {
- if(argc < 2) {
- printf("usage: filemon file [prog]");
- return 1;
- }
- monitor(argv[1],argv[2]);
-}
-
int monitor(char *file,char *handler) {
int fd, kq, nev;
struct kevent ev;
struct stat sb;
- char buffer[
+// char buffer[
static const struct timespec tout = { 1, 0 };
- if ((fd = open(file, O_RDONLY)) == -1) err(1, "Cannot open `%s'", argv[1]);
+ if ((fd = open(file, O_RDONLY)) == -1) err(1, "Cannot open `%s'", file);
fstat(fd,&sb);
if(S_ISDIR(sb.st_mode)) {
//read list of files from dir?
//rerun self on all files in that dir.
//system("filemon file/*"); //XD
- getdents(fd,,);
+ //getdents(fd,,); //I have code to do this in the MUD
+ printf("warning: this doesn't show changes of file in the dir.");
+ printf("warning: it just shows changes of the dir itself.");
}
if ((kq = kqueue()) == -1) err(1, "Cannot create kqueue");
EV_SET(&ev,
@@ -45,16 +39,16 @@ int monitor(char *file,char *handler) {
nev = kevent(kq, NULL, 0, &ev, 1, &tout);
if (nev == -1) err(1, "kevent");
if (nev == 0) continue;
- printf("nev:%x\n",nev);//probably fd that triggered event?
- printf("ev.ident:%x\n",ev.ident);
- printf("ev.filter:%x\n",ev.filter);
- printf("ev.flags:%x\n",ev.flags);
- printf("ev.fflags:%x\n",ev.fflags);
- printf("ev.data:%x\n",ev.data);
- printf("ev.udata:%x\n",ev.udata);
+ //printf("nev:%x\n",nev);//probably fd that triggered event?
+ //printf("ev.ident:%x\n",ev.ident);
+ //printf("ev.filter:%x\n",ev.filter);
+ //printf("ev.flags:%x\n",ev.flags);
+ //printf("ev.fflags:%x\n",ev.fflags);
+ //printf("ev.data:%x\n",ev.data);
+ //printf("ev.udata:%x\n",ev.udata);
if (ev.fflags & (NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK|NOTE_RENAME|NOTE_REVOKE)) {
printf("%s: ",file);
- if(argv[2]) system(handler);
+ if(handler) system(handler);
}
if (ev.fflags & NOTE_DELETE) {
printf("deleted ");
@@ -91,3 +85,11 @@ int monitor(char *file,char *handler) {
}
return 0;
}
+
+int main(int argc, char *argv[]) {
+ if(argc < 2) {
+ printf("usage: filemon file [prog]");
+ return 1;
+ }
+ return monitor(argv[1],argv[2]);
+}