svn commit: r185454 - head/sbin/geom/class/part
Marcel Moolenaar
marcel at FreeBSD.org
Sat Nov 29 13:20:08 PST 2008
Author: marcel
Date: Sat Nov 29 21:20:07 2008
New Revision: 185454
URL: http://svn.freebsd.org/changeset/base/185454
Log:
Parse the error string returned by the kernel. The format is:
<errno> [<parameter> <value>]
So, rather than printing the error:
gpart: 22 scheme 'gpt'
gpart(8) now prints:
gpart: scheme 'gpt': invalid argument
Modified:
head/sbin/geom/class/part/geom_part.c
Modified: head/sbin/geom/class/part/geom_part.c
==============================================================================
--- head/sbin/geom/class/part/geom_part.c Sat Nov 29 20:55:11 2008 (r185453)
+++ head/sbin/geom/class/part/geom_part.c Sat Nov 29 21:20:07 2008 (r185454)
@@ -63,10 +63,11 @@ static char index_param[] = "index";
static char partcode_param[] = "partcode";
static void gpart_bootcode(struct gctl_req *, unsigned int);
+static void gpart_issue(struct gctl_req *, unsigned int);
static void gpart_show(struct gctl_req *, unsigned int);
struct g_command PUBSYM(class_commands)[] = {
- { "add", 0, NULL, {
+ { "add", 0, gpart_issue, {
{ 'b', "start", NULL, G_TYPE_STRING },
{ 's', "size", NULL, G_TYPE_STRING },
{ 't', "type", NULL, G_TYPE_STRING },
@@ -84,25 +85,25 @@ struct g_command PUBSYM(class_commands)[
G_OPT_SENTINEL },
"geom", NULL
},
- { "commit", 0, NULL, G_NULL_OPTS, "geom", NULL },
- { "create", 0, NULL, {
+ { "commit", 0, gpart_issue, G_NULL_OPTS, "geom", NULL },
+ { "create", 0, gpart_issue, {
{ 's', "scheme", NULL, G_TYPE_STRING },
{ 'n', "entries", optional, G_TYPE_STRING },
{ 'f', "flags", flags, G_TYPE_STRING },
G_OPT_SENTINEL },
"provider", NULL
},
- { "delete", 0, NULL, {
+ { "delete", 0, gpart_issue, {
{ 'i', index_param, NULL, G_TYPE_STRING },
{ 'f', "flags", flags, G_TYPE_STRING },
G_OPT_SENTINEL },
"geom", NULL
},
- { "destroy", 0, NULL, {
+ { "destroy", 0, gpart_issue, {
{ 'f', "flags", flags, G_TYPE_STRING },
G_OPT_SENTINEL },
"geom", NULL },
- { "modify", 0, NULL, {
+ { "modify", 0, gpart_issue, {
{ 'i', index_param, NULL, G_TYPE_STRING },
{ 'l', "label", optional, G_TYPE_STRING },
{ 't', "type", optional, G_TYPE_STRING },
@@ -110,7 +111,7 @@ struct g_command PUBSYM(class_commands)[
G_OPT_SENTINEL },
"geom", NULL
},
- { "set", 0, NULL, {
+ { "set", 0, gpart_issue, {
{ 'a', "attrib", NULL, G_TYPE_STRING },
{ 'i', index_param, NULL, G_TYPE_STRING },
{ 'f', "flags", flags, G_TYPE_STRING },
@@ -123,8 +124,8 @@ struct g_command PUBSYM(class_commands)[
G_OPT_SENTINEL },
NULL, "[-lr] [geom ...]"
},
- { "undo", 0, NULL, G_NULL_OPTS, "geom", NULL },
- { "unset", 0, NULL, {
+ { "undo", 0, gpart_issue, G_NULL_OPTS, "geom", NULL },
+ { "unset", 0, gpart_issue, {
{ 'a', "attrib", NULL, G_TYPE_STRING },
{ 'i', index_param, NULL, G_TYPE_STRING },
{ 'f', "flags", flags, G_TYPE_STRING },
@@ -446,7 +447,7 @@ gpart_write_partcode(struct gctl_req *re
}
static void
-gpart_bootcode(struct gctl_req *req, unsigned int fl __unused)
+gpart_bootcode(struct gctl_req *req, unsigned int fl)
{
const char *s;
char *sp;
@@ -501,9 +502,33 @@ gpart_bootcode(struct gctl_req *req, uns
errx(EXIT_FAILURE, "no -b nor -p");
}
- if (bootcode != NULL) {
- s = gctl_issue(req);
- if (s != NULL)
- errx(EXIT_FAILURE, "%s", s);
- }
+ if (bootcode != NULL)
+ gpart_issue(req, fl);
+}
+
+static void
+gpart_issue(struct gctl_req *req, unsigned int fl __unused)
+{
+ char buf[4096];
+ char *errmsg;
+ const char *errstr;
+ int error;
+
+ bzero(buf, sizeof(buf));
+ gctl_rw_param(req, "output", sizeof(buf), buf);
+ errstr = gctl_issue(req);
+ gctl_free(req);
+ if (errstr == NULL || errstr[0] == '\0') {
+ if (buf[0] != '\0')
+ printf("%s", buf);
+ exit(EXIT_SUCCESS);
+ }
+
+ error = strtol(errstr, &errmsg, 0);
+ while (errmsg[0] == ' ')
+ errmsg++;
+ if (errmsg[0] != '\0')
+ errc(EXIT_FAILURE, error, "%s", errmsg);
+ else
+ errc(EXIT_FAILURE, error, NULL);
}
More information about the svn-src-all
mailing list