Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/mknod Don't exit on error from pack_dev.c, but return a...
details: https://anonhg.NetBSD.org/src/rev/a930c6f9b86c
branches: trunk
changeset: 558195:a930c6f9b86c
user: ross <ross%NetBSD.org@localhost>
date: Fri Jan 30 19:06:55 2004 +0000
description:
Don't exit on error from pack_dev.c, but return an error string and
have the caller do cleanup and (potentially) report errors in context.
This is needed because mknod(8) is not the only user of pack_dev.[ch]
diffstat:
sbin/mknod/mknod.c | 19 ++++++++-
sbin/mknod/pack_dev.c | 98 ++++++++++++++++++++++++++------------------------
sbin/mknod/pack_dev.h | 4 +-
3 files changed, 68 insertions(+), 53 deletions(-)
diffs (truncated from 302 to 300 lines):
diff -r 3f62b431e7f6 -r a930c6f9b86c sbin/mknod/mknod.c
--- a/sbin/mknod/mknod.c Fri Jan 30 19:06:36 2004 +0000
+++ b/sbin/mknod/mknod.c Fri Jan 30 19:06:55 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mknod.c,v 1.29 2004/01/05 23:23:33 jmmv Exp $ */
+/* $NetBSD: mknod.c,v 1.30 2004/01/30 19:06:55 ross Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.\n");
-__RCSID("$NetBSD: mknod.c,v 1.29 2004/01/05 23:23:33 jmmv Exp $");
+__RCSID("$NetBSD: mknod.c,v 1.30 2004/01/30 19:06:55 ross Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -64,6 +64,7 @@
#include "pack_dev.h"
static int gid_name(const char *, gid_t *);
+static portdev_t callPack(pack_t *, int, u_long *);
int main(int, char *[]);
static void usage(void);
@@ -208,7 +209,7 @@
break;
default:
- dev = (*pack)(argc, numbers);
+ dev = callPack(pack, argc, numbers);
break;
}
@@ -275,3 +276,15 @@
*gid = g->gr_gid;
return 0;
}
+
+static portdev_t
+callPack(pack_t *f, int n, u_long *numbers)
+{
+ portdev_t d;
+ char *error = NULL;
+
+ d = (*f)(n, numbers, &error);
+ if (error != NULL)
+ errx(1, "%s", error);
+ return d;
+}
diff -r 3f62b431e7f6 -r a930c6f9b86c sbin/mknod/pack_dev.c
--- a/sbin/mknod/pack_dev.c Fri Jan 30 19:06:36 2004 +0000
+++ b/sbin/mknod/pack_dev.c Fri Jan 30 19:06:55 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pack_dev.c,v 1.6 2003/10/27 00:12:42 lukem Exp $ */
+/* $NetBSD: pack_dev.c,v 1.7 2004/01/30 19:06:55 ross Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -42,13 +42,12 @@
#include <sys/cdefs.h>
#if !defined(lint)
-__RCSID("$NetBSD: pack_dev.c,v 1.6 2003/10/27 00:12:42 lukem Exp $");
+__RCSID("$NetBSD: pack_dev.c,v 1.7 2004/01/30 19:06:55 ross Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
-#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@@ -66,38 +65,41 @@
static pack_t pack_bsdos;
static int compare_format(const void *, const void *);
+static char iMajorError[] = "invalid major number";
+static char iMinorError[] = "invalid minor number";
+static char tooManyFields[] = "too many fields for format";
/* exported */
portdev_t
-pack_native(int n, u_long numbers[])
+pack_native(int n, u_long numbers[], char **error)
{
- portdev_t dev;
+ portdev_t dev = 0;
if (n == 2) {
dev = makedev(numbers[0], numbers[1]);
if (major(dev) != numbers[0])
- errx(1, "invalid major number");
- if (minor(dev) != numbers[1])
- errx(1, "invalid minor number");
+ *error = iMajorError;
+ else if (minor(dev) != numbers[1])
+ *error = iMinorError;
} else
- errx(1, "too many fields for format");
+ *error = tooManyFields;
return (dev);
}
static portdev_t
-pack_netbsd(int n, u_long numbers[])
+pack_netbsd(int n, u_long numbers[], char **error)
{
- portdev_t dev;
+ portdev_t dev = 0;
if (n == 2) {
dev = makedev_netbsd(numbers[0], numbers[1]);
if (major_netbsd(dev) != numbers[0])
- errx(1, "invalid major number");
- if (minor_netbsd(dev) != numbers[1])
- errx(1, "invalid minor number");
+ *error = iMajorError;
+ else if (minor_netbsd(dev) != numbers[1])
+ *error = iMinorError;
} else
- errx(1, "too many fields for format");
+ *error = tooManyFields;
return (dev);
}
@@ -108,18 +110,18 @@
(((y) << 0) & 0xffff00ff)))
static portdev_t
-pack_freebsd(int n, u_long numbers[])
+pack_freebsd(int n, u_long numbers[], char **error)
{
- portdev_t dev;
+ portdev_t dev = 0;
if (n == 2) {
dev = makedev_freebsd(numbers[0], numbers[1]);
if (major_freebsd(dev) != numbers[0])
- errx(1, "invalid major number");
+ *error = iMajorError;
if (minor_freebsd(dev) != numbers[1])
- errx(1, "invalid minor number");
+ *error = iMinorError;
} else
- errx(1, "too many fields for format");
+ *error = tooManyFields;
return (dev);
}
@@ -130,18 +132,18 @@
(((y) << 0) & 0x000000ff)))
static portdev_t
-pack_8_8(int n, u_long numbers[])
+pack_8_8(int n, u_long numbers[], char **error)
{
- portdev_t dev;
+ portdev_t dev = 0;
if (n == 2) {
dev = makedev_8_8(numbers[0], numbers[1]);
if (major_8_8(dev) != numbers[0])
- errx(1, "invalid major number");
+ *error = iMajorError;
if (minor_8_8(dev) != numbers[1])
- errx(1, "invalid minor number");
+ *error = iMinorError;
} else
- errx(1, "too many fields for format");
+ *error = tooManyFields;
return (dev);
}
@@ -152,18 +154,18 @@
(((y) << 0) & 0x000fffff)))
static portdev_t
-pack_12_20(int n, u_long numbers[])
+pack_12_20(int n, u_long numbers[], char **error)
{
- portdev_t dev;
+ portdev_t dev = 0;
if (n == 2) {
dev = makedev_12_20(numbers[0], numbers[1]);
if (major_12_20(dev) != numbers[0])
- errx(1, "invalid major number");
+ *error = iMajorError;
if (minor_12_20(dev) != numbers[1])
- errx(1, "invalid minor number");
+ *error = iMinorError;
} else
- errx(1, "too many fields for format");
+ *error = tooManyFields;
return (dev);
}
@@ -174,18 +176,18 @@
(((y) << 0) & 0x0003ffff)))
static portdev_t
-pack_14_18(int n, u_long numbers[])
+pack_14_18(int n, u_long numbers[], char **error)
{
- portdev_t dev;
+ portdev_t dev = 0;
if (n == 2) {
dev = makedev_14_18(numbers[0], numbers[1]);
if (major_14_18(dev) != numbers[0])
- errx(1, "invalid major number");
+ *error = iMajorError;
if (minor_14_18(dev) != numbers[1])
- errx(1, "invalid minor number");
+ *error = iMinorError;
} else
- errx(1, "too many fields for format");
+ *error = tooManyFields;
return (dev);
}
@@ -196,18 +198,18 @@
(((y) << 0) & 0x00ffffff)))
static portdev_t
-pack_8_24(int n, u_long numbers[])
+pack_8_24(int n, u_long numbers[], char **error)
{
- portdev_t dev;
+ portdev_t dev = 0;
if (n == 2) {
dev = makedev_8_24(numbers[0], numbers[1]);
if (major_8_24(dev) != numbers[0])
- errx(1, "invalid major number");
+ *error = iMajorError;
if (minor_8_24(dev) != numbers[1])
- errx(1, "invalid minor number");
+ *error = iMinorError;
} else
- errx(1, "too many fields for format");
+ *error = tooManyFields;
return (dev);
}
@@ -220,26 +222,26 @@
(((z) << 0) & 0x000000ff)))
static portdev_t
-pack_bsdos(int n, u_long numbers[])
+pack_bsdos(int n, u_long numbers[], char **error)
{
- portdev_t dev;
+ portdev_t dev = 0;
if (n == 2) {
dev = makedev_12_20(numbers[0], numbers[1]);
if (major_12_20(dev) != numbers[0])
- errx(1, "invalid major number");
+ *error = iMajorError;
if (minor_12_20(dev) != numbers[1])
- errx(1, "invalid minor number");
+ *error = iMinorError;
} else if (n == 3) {
dev = makedev_12_12_8(numbers[0], numbers[1], numbers[2]);
if (major_12_12_8(dev) != numbers[0])
- errx(1, "invalid major number");
+ *error = iMajorError;
if (unit_12_12_8(dev) != numbers[1])
- errx(1, "invalid unit number");
+ *error = "invalid unit number";
if (subunit_12_12_8(dev) != numbers[2])
- errx(1, "invalid subunit number");
+ *error = "invalid subunit number";
} else
- errx(1, "too many fields for format");
+ *error = tooManyFields;
return (dev);
}
diff -r 3f62b431e7f6 -r a930c6f9b86c sbin/mknod/pack_dev.h
--- a/sbin/mknod/pack_dev.h Fri Jan 30 19:06:36 2004 +0000
+++ b/sbin/mknod/pack_dev.h Fri Jan 30 19:06:55 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pack_dev.h,v 1.4 2003/05/08 14:47:19 christos Exp $ */
+/* $NetBSD: pack_dev.h,v 1.5 2004/01/30 19:06:55 ross Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
#else
typedef dev_t portdev_t;
#endif
-typedef portdev_t pack_t(int, u_long []);
+typedef portdev_t pack_t(int, u_long [], char **);
Home |
Main Index |
Thread Index |
Old Index