summaryrefslogtreecommitdiff
path: root/master.c
diff options
context:
space:
mode:
authorNed T. Crigler <crigler@gmail.com>2025-06-19 19:45:22 -0700
committerNed T. Crigler <crigler@gmail.com>2025-06-19 20:30:18 -0700
commitdc84bf8b0f70af92f894209d2cf68eaff55db9f0 (patch)
tree4805f9238336fa21f396beb14fd278a4feac9911 /master.c
parent6e04acf9ed089f065b19ff4e42be97bd17529ff2 (diff)
Always check the return value of the write() system call
dtach was assuming that writes with a small byte count could never fail, and was not handling partial writes for larger byte counts in a few places. This should also suppress unused result warnings from gcc on systems that define _FORTIFY_SOURCE by default.
Diffstat (limited to 'master.c')
-rw-r--r--master.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/master.c b/master.c
index 81aa6a9..75f4926 100644
--- a/master.c
+++ b/master.c
@@ -379,7 +379,7 @@ client_activity(struct client *p)
return;
/* Close the client on an error. */
- if (len <= 0)
+ if (len != sizeof(struct packet))
{
close(p->fd);
if (p->next)
@@ -393,7 +393,7 @@ client_activity(struct client *p)
if (pkt.type == MSG_PUSH)
{
if (pkt.len <= sizeof(pkt.u.buf))
- write(the_pty.fd, pkt.u.buf, pkt.len);
+ write_buf_or_fail(the_pty.fd, pkt.u.buf, pkt.len);
}
/* Attach or detach from the program. */
@@ -434,7 +434,7 @@ client_activity(struct client *p)
if (((the_pty.term.c_lflag & (ECHO|ICANON)) == 0) &&
(the_pty.term.c_cc[VMIN] == 1))
{
- write(the_pty.fd, &c, 1);
+ write_buf_or_fail(the_pty.fd, &c, 1);
}
}
/* Send a WINCH signal to the program. */
@@ -672,7 +672,7 @@ master_main(char **argv, int waitattach, int dontfork)
len = read(fd[0], buf, sizeof(buf));
if (len > 0)
{
- write(2, buf, len);
+ write_buf_or_fail(2, buf, len);
kill(pid, SIGTERM);
return 1;
}