summaryrefslogtreecommitdiffstats
path: root/sbin/geom
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2008-11-29 21:20:07 +0000
committermarcel <marcel@FreeBSD.org>2008-11-29 21:20:07 +0000
commit3e94b73b94aaf0d6f7e3baf4830e4185f90142fa (patch)
tree94569cdaf4bfb7dc04cc311ee058ad59a7dde47b /sbin/geom
parentbb05e1a003ef80629f9ca38084317dc934119ef3 (diff)
downloadFreeBSD-src-3e94b73b94aaf0d6f7e3baf4830e4185f90142fa.zip
FreeBSD-src-3e94b73b94aaf0d6f7e3baf4830e4185f90142fa.tar.gz
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
Diffstat (limited to 'sbin/geom')
-rw-r--r--sbin/geom/class/part/geom_part.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/sbin/geom/class/part/geom_part.c b/sbin/geom/class/part/geom_part.c
index c5f8ebb..74cc829 100644
--- a/sbin/geom/class/part/geom_part.c
+++ b/sbin/geom/class/part/geom_part.c
@@ -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 *req, int idx, void *code, ssize_t size)
}
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, unsigned int fl __unused)
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);
}
OpenPOWER on IntegriCloud