From owner-svn-src-head@FreeBSD.ORG Mon Nov 22 11:24:11 2010 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 D91D010656A4; Mon, 22 Nov 2010 11:24:11 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AA17B8FC17; Mon, 22 Nov 2010 11:24:11 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oAMBOBCq090402; Mon, 22 Nov 2010 11:24:11 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oAMBOB9M090400; Mon, 22 Nov 2010 11:24:11 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201011221124.oAMBOB9M090400@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Mon, 22 Nov 2010 11:24:11 +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: r215672 - 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: Mon, 22 Nov 2010 11:24:12 -0000 Author: ae Date: Mon Nov 22 11:24:11 2010 New Revision: 215672 URL: http://svn.freebsd.org/changeset/base/215672 Log: Add SIGINT handler to `gpart restore` action. MFC after: 1 week 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 Mon Nov 22 10:08:33 2010 (r215671) +++ head/sbin/geom/class/part/geom_part.c Mon Nov 22 11:24:11 2010 (r215672) @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -61,6 +62,7 @@ uint32_t PUBSYM(version) = 0; static char sstart[32]; static char ssize[32]; +volatile sig_atomic_t undo_restore; #define GPART_AUTOFILL "*" #define GPART_FLAGS "C" @@ -757,12 +759,19 @@ skip_line(const char *p) } static void +gpart_sighndl(int sig __unused) +{ + undo_restore = 1; +} + +static void gpart_restore(struct gctl_req *req, unsigned int fl __unused) { struct gmesh mesh; struct gclass *classp; struct gctl_req *r; struct ggeom *gp; + struct sigaction si_sa; const char *s, *flags, *errstr, *label; char **ap, *argv[6], line[BUFSIZ], *pline; int error, forced, i, l, nargs, created, rl; @@ -786,6 +795,13 @@ gpart_restore(struct gctl_req *req, unsi geom_deletetree(&mesh); errx(EXIT_FAILURE, "Class %s not found.", s); } + + sigemptyset(&si_sa.sa_mask); + si_sa.sa_flags = 0; + si_sa.sa_handler = gpart_sighndl; + if (sigaction(SIGINT, &si_sa, 0) == -1) + err(EXIT_FAILURE, "sigaction SIGINT"); + if (forced) { /* destroy existent partition table before restore */ for (i = 0; i < nargs; i++) { @@ -811,7 +827,8 @@ gpart_restore(struct gctl_req *req, unsi } } created = 0; - while (fgets(line, sizeof(line) - 1, stdin)) { + while (undo_restore == 0 && + fgets(line, sizeof(line) - 1, stdin) != NULL) { /* Format of backup entries: * * [label] ['['attrib[,attrib]']'] @@ -920,6 +937,8 @@ gpart_restore(struct gctl_req *req, unsi } } } + if (undo_restore) + goto backout; /* commit changes if needed */ if (strchr(flags, 'C') != NULL) { for (i = 0; i < nargs; i++) {