From 2607abcfe8567e68f900f459d9dfc0e7c3cef828 Mon Sep 17 00:00:00 2001 From: Ray Lai Date: Fri, 6 Apr 2007 03:24:09 +0000 Subject: Only include newest dmesg. ``Come on, take some risks'' deraadt@. --- usr.bin/sendbug/sendbug.c | 72 +++++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 25 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/sendbug/sendbug.c b/usr.bin/sendbug/sendbug.c index 13da73fad85..4f476fdcb9f 100644 --- a/usr.bin/sendbug/sendbug.c +++ b/usr.bin/sendbug/sendbug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sendbug.c,v 1.35 2007/04/06 01:32:39 ray Exp $ */ +/* $OpenBSD: sendbug.c,v 1.36 2007/04/06 03:24:08 ray Exp $ */ /* * Written by Ray Lai . @@ -29,6 +29,7 @@ #define _PATH_DMESG "/var/run/dmesg.boot" +void dmesg(FILE *); int editit(char *); void init(void); int prompt(void); @@ -133,30 +134,8 @@ main(int argc, char *argv[]) } } else { template(fp); - if (!Dflag) { - char buf[BUFSIZ]; - size_t len; - FILE *dfp; - - dfp = fopen(_PATH_DMESG, "r"); - if (dfp == NULL) { - warn("can't read dmesg"); - } else { - fputs("\n" - "\n" - "\n", fp); - while (!feof(dfp)) { - len = fread(buf, 1, sizeof buf, dfp); - if (len == 0) - break; - if (fwrite(buf, 1, len, fp) != len) - break; - } - fclose(dfp); - } - } + if (!Dflag) + dmesg(fp); } if (fflush(fp) == EOF || fstat(fd, &sb) == -1 || fclose(fp) == EOF) @@ -194,6 +173,49 @@ quit: return (ret); } +void +dmesg(FILE *fp) +{ + char buf[BUFSIZ]; + FILE *dfp; + off_t offset = -1; + + dfp = fopen(_PATH_DMESG, "r"); + if (dfp == NULL) { + warn("can't read dmesg"); + return; + } + + fputs("\n" + "\n" + "\n", fp); + /* Find last line starting with "OpenBSD". */ + for (;;) { + off_t o; + + o = ftello(dfp); + if (fgets(buf, sizeof(buf), dfp) == NULL) + break; + if (!strncmp("OpenBSD ", buf, sizeof("OpenBSD ") - 1)) + offset = o; + } + if (offset != -1) { + size_t len; + + clearerr(dfp); + fseeko(dfp, offset, SEEK_SET); + while (offset != -1 && !feof(dfp)) { + len = fread(buf, 1, sizeof buf, dfp); + if (len == 0) + break; + if (fwrite(buf, 1, len, fp) != len) + break; + } + } + fclose(dfp); +} + int editit(char *tmpfile) { -- cgit v1.2.3