Robert Lowry avatar Robert Lowry committed 59ab0d3

started kqueue code. it's promising, but broken.

Comments (0)

Files changed (1)

 #include <sys/wait.h>
 #include <sys/resource.h>
 #include <libgen.h>
+#include <fcntl.h>
 
 #ifdef __linux__
 #define HAVE_INOTIFY
 	int pid;
 	char *path;
 	watch_t *next;
-#ifdef HAVE_INOTIFY
 	int wd;
-#endif
 };
 
 watch_t *watch = NULL;
 {
 	char out[PATH_MAX];
 	struct stat st;
+	struct kevent kadd;
 	watch_t *w;
+	int fd;
+
+	printf("adding %s\n",fpath);
 
 	if(!(typeflag & FTW_D))
 		return 0;
 
-	// add watch here
+	for (w = watch; w; w = w->next)
+		if (!strcmp(w->path, fpath))
+			return 0;
+
+	if((fd = open(fpath, O_RDONLY)) == -1)
+		err(1,"directory open");
+
+	EV_SET(&kadd, fd, EVFILT_VNODE, EV_ADD | EV_CLEAR, NOTE_WRITE, 0, 0);
+	if(kevent(kq, &kadd, 1, NULL, 0, NULL) == -1)
+		err(1,"kevent set EVFILT_VNODE");
 
 	if (!watch)
 		watch = new_watch();
+	for(w = watch; w; w = w->next)
+		if(w->next == NULL)
+			break;
+	w->next = new_watch();
+	w = w->next;
+	w->wd = fd;
+	w->path = strdup(fpath);
+	snprintf(out,sizeof(out),"%s/out",fpath);
+	if(!init && stat(out, &st) == 0)
+		spawn_win(w); 
 
 	return 0;
 }
 
 void run_kqueue(char *dir)
 {
-	struct kevent change;
 	struct kevent event;
 	int i;
 
-	if ((kq == kqueue()) == -1)
-		perror("kqueue failed");
+	if ((kq = kqueue()) == -1)
+		err(1,"kqueue failed");
+	
+	init = 1;
+	ftw(dir, add_dir_kqueue, MAX_OPENFD);
+	init = 0;
+
 }
 #endif
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.