Anonymous avatar Anonymous committed 4de63ff

add sigwinch handler, error check on select

Comments (0)

Files changed (1)

 static void print_usr(void);
 static void quit(int sig);
 static void run(void);
-static void sigchld(int sig);
+static void sigchld(int unused);
+static void sigwinch(int unused);
 static int  start_pos(int start, int cur, int len, int cols);
 static void stop(int unused);
 static void term_set(int unused);
 static void usage(void);
 
 struct sig sig_table[] = {
-	{SIGINT,  "SIGINT" , quit    },
-	{SIGTERM, "SIGTERM", quit    },
-	{SIGTSTP, "SIGTSTP", stop    },
-	{SIGCONT, "SIGCONT", term_set},
-	{SIGCHLD, "SIGCHLD", sigchld },
+	{SIGINT,   "SIGINT",   quit    },
+	{SIGTERM,  "SIGTERM",  quit    },
+	{SIGTSTP,  "SIGTSTP",  stop    },
+	{SIGCONT,  "SIGCONT",  term_set},
+	{SIGCHLD,  "SIGCHLD",  sigchld },
+	{SIGWINCH, "SIGWINCH", sigwinch},
 	{0},
 };
 
 		FD_SET(STDIN, &rd);
 		FD_SET(mfd,   &rd);
 
-		select(mfd + 1, &rd, NULL, NULL, NULL);
+		if (select(mfd + 1, &rd, NULL, NULL, NULL) < 0) {
+			if (errno != EINTR)
+				warn("failed select");
+			continue;
+		}
 
 		if (FD_ISSET(STDIN, &rd)) {
 			if ((rdlen = read(STDIN, &c, 1)) < 0)
 					case CTRL('e') : cur = len;               break;
 					case CTRL('f') : cur = MIN(len, cur + 1); break;
 					case CTRL('k') : len = cur;               break;
-					case CTRL('l') :
-						cursor_org();
-						cursor_clr();
-						fflush(stdout);
-						if (ioctl(STDOUT, TIOCGWINSZ, &ws) < 0)
-							err(1, "failed ioctl");
-						if (ioctl(mfd, TIOCSWINSZ, &ws) < 0)
-							err(1, "failed ioctl");
-						kill(-child, SIGWINCH);
-						break;
+					case CTRL('l') : sigwinch(0);             break;
 					case CTRL('u') : start = cur = len = 0;   break;
 					case CTRL('w') :
 						for (i = cur - 1; i >= 0 && strchr(word_separators, usrbuf[i]); i--)
 	}
 }
 
-void sigchld(int sig)
+void sigchld(int unused)
 {
 	pid_t pid;
 	int status;
 	}
 }
 
+void sigwinch(int unused)
+{
+	if (ioctl(STDOUT, TIOCGWINSZ, &ws) < 0)
+		err(1, "failed ioctl");
+
+	if (ioctl(mfd, TIOCSWINSZ, &ws) < 0)
+		err(1, "failed ioctl");
+
+	kill(-child, SIGWINCH);
+}
+
 int start_pos(int start, int cur, int len, int cols)
 {
 	int ret;
 
 	return 0;
 }
+
+/* vim: set ts=4 sw=4 noexpandtab: */
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.