From d52ebfd8e572596739b84b5138ef7c090a3dc442 Mon Sep 17 00:00:00 2001 From: kn Date: Thu, 1 Sep 2022 01:52:08 +0000 Subject: [PATCH] Don't print device name on failure Noticed by mistake (wanted `-l'): # vnconfig l vnd0 vnconfig: VNDIOCSET: No such file or directory Same happens if you try to load a bogus file: # vnconfig ./empty vnd0 vnconfig: VNDIOCSET: Input/output error In both cases, the info on stdout is useless as vnd0 is not used. Defer printing the device until after the file is set up: # ./obj/vnconfig l vnconfig: VNDIOCSET: No such file or directory # ./obj/vnconfig ./empty vnconfig: VNDIOCSET: Input/output error OK deraadt --- sbin/vnconfig/vnconfig.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sbin/vnconfig/vnconfig.c b/sbin/vnconfig/vnconfig.c index be80f2866b5..9ed7f8f04dc 100644 --- a/sbin/vnconfig/vnconfig.c +++ b/sbin/vnconfig/vnconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vnconfig.c,v 1.10 2022/08/20 06:39:24 kn Exp $ */ +/* $OpenBSD: vnconfig.c,v 1.11 2022/09/01 01:52:08 kn Exp $ */ /* * Copyright (c) 1993 University of Utah. * Copyright (c) 1990, 1993 @@ -289,7 +289,6 @@ config(char *file, char *dev, struct disklabel *dp, char *key, size_t keylen) if (dev == NULL) { if (getinfo(NULL, &unit) == -1) err(1, "no devices available"); - printf("vnd%d\n", unit); asprintf(&dev, "vnd%d", unit); } @@ -312,9 +311,12 @@ config(char *file, char *dev, struct disklabel *dp, char *key, size_t keylen) rv = ioctl(fd, VNDIOCSET, &vndio); if (rv) warn("VNDIOCSET"); - else if (verbose) - fprintf(stderr, "%s: %llu bytes on %s\n", dev, vndio.vnd_size, - file); + else { + printf("%s\n", dev); + if (verbose) + fprintf(stderr, "%s: %llu bytes on %s\n", dev, + vndio.vnd_size, file); + } close(fd); fflush(stdout); -- 2.20.1