Commits

Evan Gates  committed 18a44b3

usage() if we don't have a command and die if the command dies (kill ourselves so the terminal goes back to normal)

  • Participants
  • Parent commits dc5ba6b

Comments (0)

Files changed (1)

+#include <signal.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/select.h>
 void usage(void)
 {
 	printf("Usage: srw [-p prompt] [-P scroll_prompt] cmd [args]...\n");
+	exit(1);
+}
+
+void sigchld(int unused)
+{
+	printf("\n");
+	warnx("subprocess died");
+	kill(getpid(), SIGINT);
 }
 
 void my_write(int fd, const void *buf, size_t count)
 			case 'P' : scrl_prompt = argv[++i]; break;
 			default  : usage();
 		}
-		if (i >= argc)
-			usage();
 	}
 
+	if (i >= argc)
+		usage();
+
 	tcgetattr(0, &set);
 	set.c_lflag &= ~ECHO;
 
+	if (signal(SIGCHLD, sigchld) == SIG_ERR)
+		err("failed to install SIGCHLD handler");
+
 	if (forkpty(&mfd, NULL, &set, NULL) == 0) { //child
 		execvp(argv[i], &argv[i]);
 		err("failed execvp %s", argv[i]);