Mark stdin as nonblocking if we get EWOULDBLOCK, and before handing it off to child processes when either starting them or moving them to the foreground.

https://github.com/fish-shell/fish-shell/issues/176
This commit is contained in:
ridiculousfish
2013-04-07 12:40:08 -07:00
parent 3a7ab3f030
commit 437b4397b9
10 changed files with 77 additions and 54 deletions

View File

@@ -264,12 +264,10 @@ int wstat(const wcstring &file_name, struct stat *buf)
int lwstat(const wcstring &file_name, struct stat *buf)
{
// fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
cstring tmp = wcs2string(file_name);
return lstat(tmp.c_str(), buf);
}
int waccess(const wcstring &file_name, int mode)
{
cstring tmp = wcs2string(file_name);
@@ -292,6 +290,28 @@ void wperror(const wcstring &s)
fwprintf(stderr, L"%s\n", strerror(e));
}
int make_fd_nonblocking(int fd)
{
int flags = fcntl(fd, F_GETFL, 0);
int err = 0;
if (! (flags & O_NONBLOCK))
{
err = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
return err == -1 ? errno : 0;
}
int make_fd_blocking(int fd)
{
int flags = fcntl(fd, F_GETFL, 0);
int err = 0;
if (flags & O_NONBLOCK)
{
err = fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
}
return err == -1 ? errno : 0;
}
static inline void safe_append(char *buffer, const char *s, size_t buffsize)
{
strncat(buffer, s, buffsize - strlen(buffer) - 1);