Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/dd block siginfo during writes.



details:   https://anonhg.NetBSD.org/src/rev/465cfad3d508
branches:  trunk
changeset: 495651:465cfad3d508
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Aug 02 16:46:16 2000 +0000

description:
block siginfo during writes.

diffstat:

 bin/dd/dd.c       |  30 +++++++++++++++++++++++++++---
 bin/dd/extern.h   |   3 ++-
 bin/dd/position.c |   6 +++---
 3 files changed, 32 insertions(+), 7 deletions(-)

diffs (113 lines):

diff -r 226ac53cbf53 -r 465cfad3d508 bin/dd/dd.c
--- a/bin/dd/dd.c       Wed Aug 02 15:42:24 2000 +0000
+++ b/bin/dd/dd.c       Wed Aug 02 16:46:16 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dd.c,v 1.14 1999/11/09 15:06:31 drochner Exp $ */
+/*     $NetBSD: dd.c,v 1.15 2000/08/02 16:46:16 christos Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -47,7 +47,7 @@
 #if 0
 static char sccsid[] = "@(#)dd.c       8.5 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: dd.c,v 1.14 1999/11/09 15:06:31 drochner Exp $");
+__RCSID("$NetBSD: dd.c,v 1.15 2000/08/02 16:46:16 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -86,6 +86,7 @@
 u_int  files_cnt = 1;          /* # of files to copy */
 int    progress = 0;           /* display sign of life */
 const u_char   *ctab;          /* conversion table */
+sigset_t nset;                 /* a set blocking SIGINFO */
 
 int
 main(argc, argv)
@@ -97,6 +98,8 @@
 
        (void)signal(SIGINFO, summaryx);
        (void)signal(SIGINT, terminate);
+       (void)sigemptyset(&nset);
+       (void)sigaddset(&nset, SIGINFO);
 
        (void)atexit(summary);
 
@@ -374,7 +377,7 @@
        outp = out.db;
        for (n = force ? out.dbcnt : out.dbsz;; n = out.dbsz) {
                for (cnt = n;; cnt -= nw) {
-                       nw = write(out.fd, outp, cnt);
+                       nw = bwrite(out.fd, outp, cnt);
                        if (nw <= 0) {
                                if (nw == 0)
                                        errx(1, "%s: end of device", out.name);
@@ -414,3 +417,24 @@
        if (progress)
                (void)write(STDERR_FILENO, ".", 1);
 }
+
+/*
+ * A protected against SIGINFO write
+ */
+ssize_t
+bwrite(fd, buf, len)
+       int fd;
+       const void *buf;
+       size_t len;
+{
+       sigset_t oset;
+       ssize_t rv;
+       int oerrno;
+
+       (void)sigprocmask(SIG_BLOCK, &nset, &oset);
+       rv = write(fd, buf, len);
+       oerrno = errno;
+       (void)sigprocmask(SIG_SETMASK, &oset, NULL);
+       errno = oerrno;
+       return rv;
+}
diff -r 226ac53cbf53 -r 465cfad3d508 bin/dd/extern.h
--- a/bin/dd/extern.h   Wed Aug 02 15:42:24 2000 +0000
+++ b/bin/dd/extern.h   Wed Aug 02 16:46:16 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.9 1999/07/29 19:03:31 hubertf Exp $       */
+/*     $NetBSD: extern.h,v 1.10 2000/08/02 16:46:16 christos Exp $     */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -54,6 +54,7 @@
 void terminate __P((int));
 void unblock __P((void));
 void unblock_close __P((void));
+ssize_t bwrite __P((int, const void *, size_t));
 
 extern IO in, out;
 extern STAT st;
diff -r 226ac53cbf53 -r 465cfad3d508 bin/dd/position.c
--- a/bin/dd/position.c Wed Aug 02 15:42:24 2000 +0000
+++ b/bin/dd/position.c Wed Aug 02 16:46:16 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: position.c,v 1.8 1999/10/09 00:43:32 jtk Exp $ */
+/*     $NetBSD: position.c,v 1.9 2000/08/02 16:46:16 christos Exp $    */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)position.c 8.3 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: position.c,v 1.8 1999/10/09 00:43:32 jtk Exp $");
+__RCSID("$NetBSD: position.c,v 1.9 2000/08/02 16:46:16 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -167,7 +167,7 @@
                        err(1, "%s", out.name);
 
                while (cnt++ < out.offset)
-                       if ((n = write(out.fd, out.db, out.dbsz)) != out.dbsz)
+                       if ((n = bwrite(out.fd, out.db, out.dbsz)) != out.dbsz)
                                err(1, "%s", out.name);
                break;
        }



Home | Main Index | Thread Index | Old Index