Anonymous avatar Anonymous committed b2ee531

cleaned up cwd

Comments (0)

Files changed (1)

+#include <stdlib.h>
 #include <unistd.h>
 #include <signal.h>
 #include <sys/inotify.h>
 char paths[MAX_WATCH][PATH_MAX] = {0};
 int wins[MAX_WATCH] = {0};
 
+char term[16] = "urxvt";
+
 void win(int wd)
 {
 	char path[PATH_MAX], out[PATH_MAX], in[PATH_MAX];
-	char *wincmd[] = {"urxvt", "-title", paths[wd], "-e", "srw", "cw", out, in, NULL};
+	char *wincmd[] = {term, "-title", paths[wd], "-e", "srw", "cw", out, in, NULL};
 
 	if (wins[wd])
 		return;
 	sprintf(out, "%s/out", paths[wd]);
 	sprintf(in,  "%s/in",  paths[wd]);
 
-	printf("about to exec\n");
-
 	if ((wins[wd] = fork()) == 0) {
 		execvp(wincmd[0], wincmd);
 		err(1, "failed on execlp cw");
-	} else {
-		printf("child has pid %d\n", wins[wd]);
 	}
 }
 
 
 	if (paths[wd][0] == '\0') {
 		strcpy(paths[wd], fpath);
-		printf("added %s\n", paths[wd]);
 		strcpy(out, fpath);
 		strcat(out, "/out");
 		if (!init && stat(out, &st) == 0)
 			win(wd);
-	} else {
-		printf("existed %s\n", paths[wd]);
 	}
 
 	return 0;
 	pid_t pid;
 	int wd;
 
-	if(signal(SIGCHLD, sigchld) == SIG_ERR)
-		err("failed installing SIGCHLD handler");
-
 	while((pid = waitpid(-1, NULL, WNOHANG)) > 0) {
-		printf("killed child with pid %d ", pid);
-		if ((wd = find(wins, pid, MAX_WATCH)) > -1) {
-			printf("wd %d path %s\n", wd, paths[wd]);
+		if ((wd = find(wins, pid, MAX_WATCH)) > -1)
 			wins[wd] = 0;
-		} else {
-			printf("no wd...\n");
-		}
 	}
 }
 
 	char buf[4096];
 	int i, len;
 	struct inotify_event *cur;
+	struct stat st;
 
-	sigchld(0);
+	if (argc != 2) {
+		printf("Usage: cwd dir\n");
+		exit(1);
+	}
+
+	if (stat(argv[1], &st) < 0 || !S_ISDIR(st.st_mode))
+		errx(1, "%s does not exist or is not a directory", argv[1]);
+
+	if (signal(SIGCHLD, sigchld) == SIG_ERR)
+		err("failed installing SIGCHLD handler");
 
 	if ((evq = inotify_init()) < 0)
 		err(1, "failed on inotify_init()");
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.