From 1d976324765399d96b1aeabf04b2bf7ac358b3db Mon Sep 17 00:00:00 2001 From: millert Date: Wed, 24 Aug 2016 16:09:40 +0000 Subject: [PATCH] Use writev(2) to write history records using a single syscall. OK deraadt@ --- bin/ksh/history.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/ksh/history.c b/bin/ksh/history.c index be9874f0107..8d75212d106 100644 --- a/bin/ksh/history.c +++ b/bin/ksh/history.c @@ -1,4 +1,4 @@ -/* $OpenBSD: history.c,v 1.57 2016/08/24 13:32:17 millert Exp $ */ +/* $OpenBSD: history.c,v 1.58 2016/08/24 16:09:40 millert Exp $ */ /* * command history @@ -14,6 +14,7 @@ */ #include +#include #include #include @@ -901,6 +902,7 @@ writehistfile(int lno, char *cmd) unsigned char *new; int bytes; unsigned char hdr[5]; + struct iovec iov[2]; (void) flock(histfd, LOCK_EX); sizenow = lseek(histfd, 0L, SEEK_END); @@ -941,8 +943,11 @@ writehistfile(int lno, char *cmd) hdr[2] = (lno>>16)&0xff; hdr[3] = (lno>>8)&0xff; hdr[4] = lno&0xff; - (void) write(histfd, hdr, 5); - (void) write(histfd, cmd, strlen(cmd)+1); + iov[0].iov_base = hdr; + iov[0].iov_len = 5; + iov[1].iov_base = cmd; + iov[1].iov_len = strlen(cmd) + 1; + (void) writev(histfd, iov, 2); hsize = lseek(histfd, 0L, SEEK_END); (void) flock(histfd, LOCK_UN); return; -- 2.20.1