From owner-svn-src-head@FreeBSD.ORG Sat Nov 29 21:20:08 2008 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 12F6B1065676; Sat, 29 Nov 2008 21:20:08 +0000 (UTC) (envelope-from marcel@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 075DE8FC13; Sat, 29 Nov 2008 21:20:08 +0000 (UTC) (envelope-from marcel@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mATLK7so062711; Sat, 29 Nov 2008 21:20:07 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mATLK7iR062710; Sat, 29 Nov 2008 21:20:07 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <200811292120.mATLK7iR062710@svn.freebsd.org> From: Marcel Moolenaar Date: Sat, 29 Nov 2008 21:20:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185454 - head/sbin/geom/class/part X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Nov 2008 21:20:08 -0000 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: [ ] 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); }