Commit afe5f711 authored by Mike Hibler's avatar Mike Hibler

SIGINFO handler for BSD

parent 79faa27f
...@@ -59,6 +59,7 @@ static int hashlen = 20; ...@@ -59,6 +59,7 @@ static int hashlen = 20;
static long hashblksize = HASHBLK_SIZE; static long hashblksize = HASHBLK_SIZE;
static unsigned long long ndatabytes; static unsigned long long ndatabytes;
static unsigned long nchunks, nregions, nhregions; static unsigned long nchunks, nregions, nhregions;
static char *imagename;
static char *fileid = NULL; static char *fileid = NULL;
static char *sigfile = NULL; static char *sigfile = NULL;
...@@ -88,6 +89,7 @@ static void readblock(readbuf_t *rbuf); ...@@ -88,6 +89,7 @@ static void readblock(readbuf_t *rbuf);
static readbuf_t *alloc_readbuf(uint32_t start, uint32_t size, int dowait); static readbuf_t *alloc_readbuf(uint32_t start, uint32_t size, int dowait);
static void free_readbuf(readbuf_t *rbuf); static void free_readbuf(readbuf_t *rbuf);
static void dump_readbufs(void); static void dump_readbufs(void);
static void dump_stats(int sig);
#define sectobytes(s) ((off_t)(s) * SECSIZE) #define sectobytes(s) ((off_t)(s) * SECSIZE)
#define bytestosec(b) (uint32_t)((b) / SECSIZE) #define bytestosec(b) (uint32_t)((b) / SECSIZE)
...@@ -166,6 +168,7 @@ main(int argc, char **argv) ...@@ -166,6 +168,7 @@ main(int argc, char **argv)
if ((create && argc < 1) || (!create && argc < 2)) if ((create && argc < 1) || (!create && argc < 2))
usage(); usage();
imagename = argv[0];
/* /*
* Ensure we can open both files before we do the expensive stuff. * Ensure we can open both files before we do the expensive stuff.
...@@ -179,6 +182,10 @@ main(int argc, char **argv) ...@@ -179,6 +182,10 @@ main(int argc, char **argv)
exit(1); exit(1);
} }
#ifdef SIGINFO
signal(SIGINFO, dump_stats);
#endif
/* /*
* Raw image comparison * Raw image comparison
*/ */
...@@ -330,6 +337,7 @@ readhashinfo(char *name, struct hashinfo **hinfop) ...@@ -330,6 +337,7 @@ readhashinfo(char *name, struct hashinfo **hinfop)
hashlen = 20; hashlen = 20;
break; break;
} }
nhregions = hinfo->nregions;
return 0; return 0;
} }
...@@ -376,6 +384,7 @@ addhash(struct hashinfo **hinfop, int chunkno, uint32_t start, uint32_t size, ...@@ -376,6 +384,7 @@ addhash(struct hashinfo **hinfop, int chunkno, uint32_t start, uint32_t size,
hinfo->regions[nreg].region.size = size; hinfo->regions[nreg].region.size = size;
memcpy(hinfo->regions[nreg].hash, hash, HASH_MAXSIZE); memcpy(hinfo->regions[nreg].hash, hash, HASH_MAXSIZE);
hinfo->nregions++; hinfo->nregions++;
nhregions = hinfo->nregions;
} }
static void static void
...@@ -483,9 +492,7 @@ createhash(char *name, struct hashinfo **hinfop) ...@@ -483,9 +492,7 @@ createhash(char *name, struct hashinfo **hinfop)
fprintf(stderr, "%s: WARNING: could not set mtime (%s)\n", fprintf(stderr, "%s: WARNING: could not set mtime (%s)\n",
hfile, strerror(errno)); hfile, strerror(errno));
nhregions = hinfo->nregions; dump_stats(0);
printf("%s: %lu chunks, %lu regions, %lu hashregions, %llu data bytes\n",
name, nchunks, nregions, nhregions, ndatabytes);
#ifdef TIMEIT #ifdef TIMEIT
printf("%qu bytes: inflate cycles: %llu\n", ndatabytes, dcycles); printf("%qu bytes: inflate cycles: %llu\n", ndatabytes, dcycles);
#endif #endif
...@@ -612,9 +619,7 @@ checkhash(char *name, struct hashinfo *hinfo) ...@@ -612,9 +619,7 @@ checkhash(char *name, struct hashinfo *hinfo)
stopreader(); stopreader();
nhregions = hinfo->nregions; dump_stats(0);
printf("%s: %lu chunks, %lu hashregions, %llu data bytes\n",
name, nchunks, nhregions, ndatabytes);
if (badhashes) if (badhashes)
printf("%s: %u regions (%d chunks) had bad hashes, " printf("%s: %u regions (%d chunks) had bad hashes, "
"%llu bytes affected\n", "%llu bytes affected\n",
...@@ -823,11 +828,12 @@ hashimage(char *name, struct hashinfo **hinfop) ...@@ -823,11 +828,12 @@ hashimage(char *name, struct hashinfo **hinfop)
bp += cc; bp += cc;
} }
errors += hashchunk(chunkno, chunkbuf, hinfop); errors += hashchunk(chunkno, chunkbuf, hinfop);
nchunks++;
} }
done: done:
if (!isstdin) if (!isstdin)
close(ifd); close(ifd);
nchunks = chunkno + 1; nchunks++;
return errors; return errors;
} }
...@@ -1436,3 +1442,10 @@ fsleep(unsigned int usecs) ...@@ -1436,3 +1442,10 @@ fsleep(unsigned int usecs)
} }
#endif #endif
#endif #endif
static void
dump_stats(int sig)
{
printf("%s: %lu chunks, %lu regions, %lu hashregions, %llu data bytes\n",
imagename, nchunks, nregions, nhregions, ndatabytes);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment