Robert Lowry avatar Robert Lowry committed 69dd4ca

finished up refactoring from win[wd] to watch_t linked list, somehow it works.

Comments (0)

Files changed (1)

 void spawn_win(watch_t *w)
 {
 	char out[PATH_MAX], in[PATH_MAX], path[PATH_MAX], channel[32];
-	//char *cmd[] = CMD;
+	char *cmd[] = CMD;
 
 	strcpy(path,w->path);
-	snprintf(channel,sizeof(channel),basename(path));
+	snprintf(channel,sizeof(channel),"%s> ",basename(path));
 	snprintf(out,sizeof(out),"%s/out",w->path);
 	snprintf(in,sizeof(in),"%s/in",w->path);
+
+	if ((w->pid = fork()) == 0) {
+		execvp(cmd[0],cmd);
+		err(1, "failed on execvp %s", cmd[0]);
+	}
 }
 
 #ifdef HAVE_INOTIFY
 int add_dir_inotify(const char *fpath, const struct stat *sb, int typeflag)
 {
-/*	int wd;
-	Char out[PATH_MAX];
-	struct stat st;
-
-	if (!(typeflag & FTW_D))
-		return 0;
-
-	if ((wd = inotify_add_watch(evq, fpath, IN_CREATE | IN_MODIFY)) < 0) {
-		warn("failed on inotify_add_watch on %s", fpath);
-		return 0;
-	}
-
-	if (paths[wd][0] == '\0') {
-		strcpy(paths[wd], fpath);
-		sprintf(out, "%s/out", fpath);
-		if (!init && stat(out, &st) == 0)
-			spawn_win(wd);
-	}*/
-
 	char out[PATH_MAX];
 	struct stat st;
 	watch_t *w;
 
 	if ((wd = inotify_add_watch(evq, fpath, IN_CREATE | IN_MODIFY)) < 0) {
 		warn("failed on inotify_add_watch on %s", fpath);
+		return 0;
 	}
+	printf("test");
 
 	for(w = watch; w; w = w->next) {
 		if (w->wd == wd) {
 			if(!w->path) {
 				w->path = strdup(fpath);
 				snprintf(out,sizeof(out),"%s/out",fpath);
+				printf("adding %s\n",out);
 				if(!init && stat(out, &st) == 0)
 					spawn_win(w);
 			}
 }
 #endif
 
-/*
-int find(int *haystack, int needle, int len)
-{
-	int i;
-
-	for (i = 0; i < len; i++)
-		if (haystack[i] == needle)
-			return i;
-
-	return -1;
-}
-*/
-
 void sigchld(int unused) {
 	pid_t pid;
-	//int wd;
 	watch_t *w;
 
 	while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) {
-		//if ((wd = find(wins, pid, MAX_WATCH)) > -1)
-		//	wins[wd] = 0;
 		for (w = watch; w; w = watch->next) {
 			if (w->pid == pid) {
 				w->pid = 0;
 
 			if (cur->mask & (IN_CREATE | IN_ISDIR))
 				ftw(dir, add_dir_inotify, MAX_OPENFD);
-			if (cur->mask & (IN_CREATE | IN_MODIFY) && !strcmp(cur->name, "out"))
-				spawn_win(cur->wd);
+			if (cur->mask & (IN_CREATE | IN_MODIFY) && !strcmp(cur->name, "out")) {
+				for (w = watch; w; w = w->next)
+					if(w->wd == cur->wd)
+						break;
+				if (w)
+					spawn_win(w);
+			}
 		}
 	}
 }
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.