summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2007-04-06 03:24:09 +0000
committerRay Lai <ray@cvs.openbsd.org>2007-04-06 03:24:09 +0000
commit2607abcfe8567e68f900f459d9dfc0e7c3cef828 (patch)
tree0f9273227487861f7015116cc6a4c50d639d7332 /usr.bin
parent3e95bca9bd2d90eca79687336880591b7f7b9151 (diff)
Only include newest dmesg.
``Come on, take some risks'' deraadt@.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sendbug/sendbug.c72
1 files changed, 47 insertions, 25 deletions
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 <ray@cyth.net>.
@@ -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"
- "<dmesg is attached.>\n"
- "<Feel free to delete or use the -D"
- " flag if it contains sensitive "
- "information.>\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"
+ "<dmesg is attached.>\n"
+ "<Feel free to delete or use the -D flag if it contains "
+ "sensitive information.>\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)
{