this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Don't set O_NONBLOCK on shellspawn's stdin

O_NONBLOCK is a "file status flag", which means it is set on the underlying file, not individual file descriptors. This means that, when we pass our stdin to the child directly, they will see it as O_NONBLOCK (but that's not supposed to happen).

The workaround is to leave it as a blocking file but instead use FIONREAD to determine exactly how many bytes we can read without blocking.

+13 -4
+13 -4
src/startup/darling.c
··· 375 375 376 376 if (master != -1) 377 377 fcntl(master, F_SETFL, O_NONBLOCK); 378 - fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); 378 + //fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); 379 379 fcntl(sockfd, F_SETFL, O_NONBLOCK); 380 380 381 381 while (1) ··· 405 405 406 406 if (pfds[1].revents & POLLIN) 407 407 { 408 - int rd; 408 + int rd = 0; 409 409 do 410 410 { 411 - rd = read(STDIN_FILENO, buf, sizeof(buf)); 411 + if (ioctl(STDIN_FILENO, FIONREAD, &rd) < 0) { 412 + perror("ioctl"); 413 + exit(1); 414 + } 415 + if (rd > sizeof(buf)) { 416 + rd = sizeof(buf); 417 + } 418 + rd = read(STDIN_FILENO, buf, rd); 412 419 if (rd > 0) 413 420 write(master, buf, rd); 414 - else 421 + else { 422 + perror("read"); 415 423 exit(1); 424 + } 416 425 } 417 426 while (rd == sizeof(buf)); 418 427 }