Commits

Anonymous committed 18cc4f5

bugfix for exec

Comments (0)

Files changed (1)

 #include <sys/inotify.h>
 #include <sys/wait.h>
 
+// fairly arbitray values...feel free to change
 #define PATH_MAX    1024
 #define CMD_MAX     1024
 #define MAX_ARGS    64
 #define MAX_WATCH   512
 
 int evq, init;
+int wins[MAX_WATCH] = {0};
 char paths[MAX_WATCH][PATH_MAX] = {{0}};
-int wins[MAX_WATCH] = {0};
-
 char cmd[CMD_MAX] = "urxvt -title %p -e srw -p %c cw %o %i";
-char *cmd_argv[MAX_ARGS] = {NULL};
 
 void usage(void)
 {
 
 void win(int wd)
 {
-	char out[PATH_MAX], in[PATH_MAX], path[PATH_MAX], channel[32];
+	char out[PATH_MAX], in[PATH_MAX], path[PATH_MAX], cmd_str[CMD_MAX], channel[32];
+	char *t, *cmd_argv[MAX_ARGS] = {NULL};
 	int i;
 
 	if (wins[wd])
 		return;
 
+	strcpy(cmd_str, cmd); // stupid strtok messing with my strings
+	for (i = 0, t = strtok(cmd_str, " "); i < MAX_ARGS - 1 && t; i++, t = strtok(NULL, " "))
+		cmd_argv[i] = t;
+
 	for (i = 0; cmd_argv[i]; i++) {
 		if (cmd_argv[i][0] == '%' && cmd_argv[i][1] && cmd_argv[i][2] == '\0') {
 			switch (cmd_argv[i][1]) {
-				case 'c' : cmd_argv[i] = channel; break;
-				case 'i' : cmd_argv[i] = in;      break;
-				case 'o' : cmd_argv[i] = out;     break;
-				case 'p' : cmd_argv[i] = path;    break;
+				case 'c' : cmd_argv[i] = channel;   break;
+				case 'i' : cmd_argv[i] = in;        break;
+				case 'o' : cmd_argv[i] = out;       break;
+				case 'p' : cmd_argv[i] = paths[wd]; break;
 			}
 		}
 	}
 
-	strcpy(path, paths[wd]);
+	strcpy(path, paths[wd]); // stupid basename messing with my strings
 	sprintf(channel, "%s> ", basename(path));
 	sprintf(out, "%s/out", paths[wd]);
 	sprintf(in,  "%s/in",  paths[wd]);
 
-	for (i = 0; cmd_argv[i]; i++)
-		printf("%s ", cmd_argv[i]);
-	printf("\n");
-
 	if ((wins[wd] = fork()) == 0) {
 		execvp(cmd_argv[0], cmd_argv);
 		err(1, "failed on execvp %s", cmd);
 
 int main(int argc, char **argv)
 {
-	char *root, buf[4096], *t;
+	char *root, buf[4096];
 	int i, len;
 	struct inotify_event *cur;
 	struct stat st;
 
 	root = argv[i];
 
-	for (i = 0, t = strtok(cmd, " "); i < MAX_ARGS - 1 && t; i++, t = strtok(NULL, " "))
-		cmd_argv[i] = t;
-
 	if (stat(root, &st) < 0 || !S_ISDIR(st.st_mode))
 		errx(1, "%s does not exist or is not a directory", root);