Robert Lowry avatar Robert Lowry committed 2b310dd

close fds on rm_watch. changed empty fds to -1

Comments (0)

Files changed (1)

 
 	do {
 		if (ioctl(w->infd,FIONREAD,&num) == -1)
-			err(1,"ioctl() FIONREAD failed");
+			err(1,"ioctl() FIONREAD failed on %s/out",w->path);
 		if (num) {
 			read_line(w->infd,buf,sizeof(buf));
 			l = add_line(w->lastline,buf);
 {
 	Watch *w = malloc(sizeof(Watch));
 	memset(w,0x00,sizeof(Watch));
+	w->infd = -1;
+	w->outfd = -1;
 	return w;
 }
 
 
 	if (!w->path)
 		w->path = strdup(path);
-	if (!w->infd) {
+	if (w->infd == -1) {
 		snprintf(file,sizeof(file),"%s/out",path);
 		if(stat(file,&sb) == 0) {
 			if((fd = open(file,O_RDONLY)) < 0)
 				warn("error opening %s for reading",file);
 			else {
 				w->infd = fd;
-				read_watch_input(w);
+				//read_watch_input(w);
 			}
 		}
 	}
-	if (!w->outfd) {
+	if (w->outfd == -1) {
 		snprintf(file,sizeof(file),"%s/in",path);
 		if(stat(file,&sb) == 0) {
 			if((fd = open(file,O_WRONLY|O_NONBLOCK)) < 0 && errno != ENXIO)
 				warn("error opening %s for writing",file);
-			if(fd > 0)
+			if(fd > -1)
 				w->outfd = fd;
 		}
 	}
-	if (w->infd && w->outfd)
+	if ((w->infd > -1) && (w->outfd > -1)) {
 		w->active = 1;
+		read_watch_input(w);
+	}
 
 	return w;
 }
 {
 	Line *l;
 
-	if(curwatch == w)
+	if(curwatch == w) {
 		curwatch = next_active(curwatch);
+		updatescreen = 1;
+	}
 	if(w->prev) 
 		w->prev->next = w->next;
 	if(w->next)
 			break;
 		}
 	}
+	close(w->infd);
+	close(w->outfd);
 	free(w->path);
 	free(w);
 }
 					return;
 			}
 			if (event->mask & (IN_CREATE | IN_MODIFY | IN_DELETE)) {
-				if(!strcmp(event->name,"out"))
+				if(!strcmp(event->name,"out") && w->infd != -1)
 					read_watch_input(w);
-				else if(!strcmp(event->name,"in") && event->mask & IN_DELETE) {
+				else if(!strcmp(event->name,"in") && (event->mask & IN_DELETE)) {
 					rm_watch(w);
 				}
 			}
 			curwatch = prev_active(curwatch);
 			updatescreen = 1;
 			break;
+		case KEY_CONTROL_K:
+			curwatch = (curwatch->next? curwatch->next : watch);
+			updatescreen = 1;
+			break;
 		case '\n':
 			write_input();
 			break;
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.