mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 04:41:14 -03:00
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:
24
wutil.cpp
24
wutil.cpp
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user