aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-07-31 15:15:51 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-07-31 15:15:51 +0000
commita7d21c5c7f02241732818d747d4ee27f54a65c5f (patch)
tree553745eba0e8fa879daf2e552338eab9ff25c8cd
parentslave: user-notifications: emit errors first, then warnings and last deprecations (diff)
slave: user-notifications: don't block in write(3)
The main process is blocking and waiting for us to close the error pipe (in exec(3), via O_CLOEXEC). Thus, pts data will *not* be processed until we've exec:d the shell. Because of this we must not write too much and block in write(3). Do this by setting O_NONBLOCK on the pts fd (*after* dup:ing it to stdin/stderr/sdout) and watch for EAGAIN EWOULDBLOCK.
-rw-r--r--slave.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/slave.c b/slave.c
index 8019f20c..e8f9ccc7 100644
--- a/slave.c
+++ b/slave.c
@@ -93,6 +93,16 @@ emit_one_notification(int fd, const struct user_notification *notif)
write(fd, notif->text, strlen(notif->text)) < 0 ||
write(fd, postfix, strlen(postfix)) < 0)
{
+ if (errno == EWOULDBLOCK || errno == EAGAIN) {
+ /*
+ * The main process is blocking and waiting for us to
+ * close the error pipe. Thus, pts data will *not* be
+ * processed until we've exec:d. This means we cannot
+ * write anymore once the kernel buffer is full. Don't
+ * treat this as a fatal error.
+ */
+ return true;
+ }
return false;
}
@@ -186,6 +196,14 @@ slave_exec(int ptmx, char *argv[], int err_fd, bool login_shell,
goto err;
}
+ {
+ int flags = fcntl(pts, F_GETFL);
+ if (flags < 0)
+ goto err;
+ if (fcntl(pts, F_SETFL, flags | O_NONBLOCK) < 0)
+ goto err;
+ }
+
if (!emit_notifications(pts, notifications))
goto err;