Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/cgdconfig Check whether the cgd device selected is avai...
details: https://anonhg.NetBSD.org/src/rev/e43f16849194
branches: trunk
changeset: 322521:e43f16849194
user: kre <kre%NetBSD.org@localhost>
date: Sat May 05 11:28:44 2018 +0000
description:
Check whether the cgd device selected is available to be
configured,that is, not already in use, before requesting
passwords from the user (or elsewhere).
diffstat:
sbin/cgdconfig/cgdconfig.c | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
diffs (39 lines):
diff -r 9e06c83b3123 -r e43f16849194 sbin/cgdconfig/cgdconfig.c
--- a/sbin/cgdconfig/cgdconfig.c Sat May 05 11:16:30 2018 +0000
+++ b/sbin/cgdconfig/cgdconfig.c Sat May 05 11:28:44 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cgdconfig.c,v 1.41 2017/01/10 20:45:19 christos Exp $ */
+/* $NetBSD: cgdconfig.c,v 1.42 2018/05/05 11:28:44 kre Exp $ */
/*-
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 2002, 2003\
The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: cgdconfig.c,v 1.41 2017/01/10 20:45:19 christos Exp $");
+__RCSID("$NetBSD: cgdconfig.c,v 1.42 2018/05/05 11:28:44 kre Exp $");
#endif
#include <err.h>
@@ -515,6 +515,20 @@
char devicename[PATH_MAX];
const char *dev = NULL; /* XXX: gcc */
+ if ((
+ fd = opendisk1(*argv, O_RDWR, cgdname, sizeof(cgdname), 1, prog_open)
+ ) != -1) {
+ struct cgd_user cgu;
+
+ cgu.cgu_unit = -1;
+ if (prog_ioctl(fd, CGDIOCGET, &cgu) != -1 && cgu.cgu_dev != 0) {
+ warnx("device %s already in use", *argv);
+ close(fd);
+ return -1;
+ }
+ close(fd);
+ }
+
if (argc == 2 || argc == 3) {
dev = getfsspecname(devicename, sizeof(devicename), argv[1]);
if (dev == NULL) {
Home |
Main Index |
Thread Index |
Old Index