Commits

Robert Lowry committed 9d2925a

started kqueue code

  • Participants
  • Parent commits cdab912

Comments (0)

Files changed (1)

 #include <string.h>
 #include <unistd.h>
 #include <sys/param.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <sys/resource.h>
+#include <libgen.h>
 
 #ifdef __linux__
 #define HAVE_INOTIFY
 #include <sys/wait.h>
 #else
 #define HAVE_KQUEUE
+#include <sys/event.h>
 #endif
 
 #include "config.h"
 char *nick = DEFAULT_NICK;
 int color = DEFAULT_COLOR_SETTING;
 
+#ifdef HAVE_INOTIFY
 int evq, init;
+#endif
+
+#ifdef HAVE_KQUEUE
+int kq;
+#endif
 
 void usage()
 {
 	exit(1);
 }
 
+void sigchld(int unused) {
+	pid_t pid;
+	watch_t *w;
+
+	while ((pid = waitpid(-1, NULL, WNOHANG)) > 0)
+		for (w = watch; w; w = watch->next)
+			if (w->pid == pid)
+				w->pid = 0;
+}
+
 watch_t *new_watch()
 {
 	watch_t *w = malloc(sizeof(watch_t));
 
 	if(w->pid) return;
 
-	strcpy(path,w->path);
+	strncpy(path,w->path,sizeof(path));
 	snprintf(channel,sizeof(channel),"%s> ",basename(path));
 	snprintf(out,sizeof(out),"%s/out",w->path);
 	snprintf(in,sizeof(in),"%s/in",w->path);
 		return 0;
 	}
 
+	/* TODO: oops, this can be simplified greatly */
 	if (!watch) {
 		watch = new_watch();
 		watch->wd = wd;
 	}
 	return 0;
 }
-#endif
 
-void sigchld(int unused) {
-	pid_t pid;
-	watch_t *w;
-
-	while ((pid = waitpid(-1, NULL, WNOHANG)) > 0)
-		for (w = watch; w; w = watch->next)
-			if (w->pid == pid)
-				w->pid = 0;
-}
-
-#ifdef HAVE_INOTIFY
 void run_inotify(char *dir)
 {
 	char buf[4096];
 #endif
 
 #ifdef HAVE_KQUEUE
-void run_kqueue()
+int add_dir_kqueue(const char *fpath, const struct stat *sb, int typeflag)
 {
+	char out[PATH_MAX];
+	struct stat st;
+	watch_t *w;
+
+	if(!(typeflag & FTW_D))
+		return 0;
+
+	// add watch here
+
+	if (!watch)
+		watch = new_watch();
+
+	return 0;
+}
+
+void run_kqueue(char *dir)
+{
+	struct kevent change;
+	struct kevent event;
+	int i;
+
+	if ((kq == kqueue()) == -1)
+		perror("kqueue failed");
 }
 #endif
 
 	if (signal(SIGCHLD, sigchld) == SIG_ERR)
 		err(1, "failed installing SIGCHLD handler");
 
+#ifdef HAVE_INOTIFY
 	run_inotify(dir);
+#else
+	run_kqueue(dir);
+#endif
 
 	return 0;
 }