diff options
author | ae <ae@FreeBSD.org> | 2011-07-12 09:03:38 +0000 |
---|---|---|
committer | ae <ae@FreeBSD.org> | 2011-07-12 09:03:38 +0000 |
commit | 35f380437f3aa1c78e2f694db55ac1e6d0eeb758 (patch) | |
tree | ffe693d6cda791f6089ca53b1488dd65ea99baa4 /sbin/newfs_msdos | |
parent | 33943872a7cc0deec277ad1f74cfbb315445520f (diff) | |
download | FreeBSD-src-35f380437f3aa1c78e2f694db55ac1e6d0eeb758.zip FreeBSD-src-35f380437f3aa1c78e2f694db55ac1e6d0eeb758.tar.gz |
Add SIGINFO handler.
Reviewed by: kib
Obtained from: NetBSD (partly)
MFC after: 2 weeks
Diffstat (limited to 'sbin/newfs_msdos')
-rw-r--r-- | sbin/newfs_msdos/newfs_msdos.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/sbin/newfs_msdos/newfs_msdos.c b/sbin/newfs_msdos/newfs_msdos.c index 955c3a5..a4deb23 100644 --- a/sbin/newfs_msdos/newfs_msdos.c +++ b/sbin/newfs_msdos/newfs_msdos.c @@ -44,6 +44,7 @@ static const char rcsid[] = #include <fcntl.h> #include <inttypes.h> #include <paths.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -216,6 +217,9 @@ static const u_int8_t bootcode[] = { 0 }; +static volatile sig_atomic_t got_siginfo; +static void infohandler(int); + static void check_mounted(const char *, mode_t); static void getstdfmt(const char *, struct bpb *); static void getdiskinfo(int, const char *, const char *, int, @@ -243,6 +247,7 @@ main(int argc, char *argv[]) int opt_N = 0; int Iflag = 0, mflag = 0, oflag = 0; char buf[MAXPATHLEN]; + struct sigaction si_sa; struct stat sb; struct timeval tv; struct bpb bpb; @@ -604,7 +609,19 @@ main(int argc, char *argv[]) if (!(img = malloc(bpb.bpbBytesPerSec))) err(1, NULL); dir = bpb.bpbResSectors + (bpb.bpbFATsecs ? bpb.bpbFATsecs : bpb.bpbBigFATsecs) * bpb.bpbFATs; + memset(&si_sa, 0, sizeof(si_sa)); + si_sa.sa_handler = infohandler; + if (sigaction(SIGINFO, &si_sa, 0) == -1) + err(1, "sigaction SIGINFO"); for (lsn = 0; lsn < dir + (fat == 32 ? bpb.bpbSecPerClust : rds); lsn++) { + if (got_siginfo) { + fprintf(stderr,"%s: writing sector %u of %u (%u%%)\n", + fname, lsn, + (dir + (fat == 32 ? bpb.bpbSecPerClust: rds)), + (lsn * 100) / (dir + + (fat == 32 ? bpb.bpbSecPerClust: rds))); + got_siginfo = 0; + } x = lsn; if (opt_B && fat == 32 && bpb.bpbBackup != MAXU16 && @@ -1017,3 +1034,10 @@ usage(void) "\t-u sectors/track\n"); exit(1); } + +static void +infohandler(int sig __unused) +{ + + got_siginfo = 1; +} |