summaryrefslogtreecommitdiff
path: root/usr.sbin/hostctl
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/hostctl')
-rw-r--r--usr.sbin/hostctl/hostctl.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/usr.sbin/hostctl/hostctl.c b/usr.sbin/hostctl/hostctl.c
index f0639dd55f3..a6b6c72ea67 100644
--- a/usr.sbin/hostctl/hostctl.c
+++ b/usr.sbin/hostctl/hostctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hostctl.c,v 1.5 2019/06/28 13:32:47 deraadt Exp $ */
+/* $OpenBSD: hostctl.c,v 1.6 2023/01/07 06:40:21 asou Exp $ */
/*
* Copyright (c) 2016 Reyk Floeter <reyk@openbsd.org>
@@ -178,15 +178,29 @@ main(int argc, char *argv[])
usage();
/* Re-open read-writable */
- if (cmd == PVBUSIOC_KVWRITE) {
+ if (cmd != PVBUSIOC_KVREAD) {
close(fd);
if ((fd = open(path_pvbus, O_RDWR)) == -1)
err(1, "open: %s", path_pvbus);
+ if ((ret = ioctl(fd, cmd, &pvr, sizeof(pvr))) == -1)
+ err(1, "ioctl");
+ } else {
+ while (1) {
+ if ((ret = ioctl(fd, cmd, &pvr, sizeof(pvr))) == 0)
+ break;
+ if (errno == ERANGE &&
+ pvr.pvr_valuelen < PVBUS_KVOP_MAXSIZE) {
+ /* the buffer is not enough, expand it */
+ pvr.pvr_valuelen *= 2;
+ if ((pvr.pvr_value = realloc(pvr.pvr_value,
+ pvr.pvr_valuelen)) == NULL)
+ err(1, "realloc");
+ continue;
+ }
+ err(1, "ioctl");
+ }
}
- if ((ret = ioctl(fd, cmd, &pvr, sizeof(pvr))) == -1)
- err(1, "ioctl");
-
if (!qflag && strlen(pvr.pvr_value)) {
/*
* The value can contain newlines and basically anything;