Anyone else think this patch from NetBSD is worthwhile?
Should I also extend it to support bzip2'ed dumps now that that's in
the base system, or would that be overkill?
Kris
Index: Makefile
===================================================================
RCS file: /mnt/ncvs/src/sbin/savecore/Makefile,v
retrieving revision 1.5
diff -u -r1.5 Makefile
--- Makefile 2001/03/26 14:33:23 1.5
+++ Makefile 2001/09/01 08:15:14
@@ -5,8 +5,7 @@
SRCS= savecore.c zopen.c
MAN= savecore.8
-ZOPENPATH= ${.CURDIR}/../../usr.bin/compress
-.PATH: ${ZOPENPATH}
-CFLAGS+= -I${ZOPENPATH}
+DPADD+= ${LIBZ}
+LDADD+= -lz
.include <bsd.prog.mk>
Index: savecore.8
===================================================================
RCS file: /mnt/ncvs/src/sbin/savecore/savecore.8,v
retrieving revision 1.12
diff -u -r1.12 savecore.8
--- savecore.8 2001/07/10 11:02:27 1.12
+++ savecore.8 2001/09/01 08:11:50
@@ -72,7 +72,7 @@
Print out some additional debugging information.
.It Fl z
Compress the core dump and kernel (see
-.Xr compress 1 ) .
+.Xr gzip 1 ) .
.El
.Pp
.Nm Savecore
@@ -113,8 +113,8 @@
.Sh BUGS
The minfree code does not consider the effect of compression.
.Sh SEE ALSO
-.Xr compress 1 ,
.Xr getbootfile 3 ,
+.Xr gzip 1 ,
.Xr syslogd 8
.Sh HISTORY
The
Index: savecore.c
===================================================================
RCS file: /mnt/ncvs/src/sbin/savecore/savecore.c,v
retrieving revision 1.41
diff -u -r1.41 savecore.c
--- savecore.c 2001/06/09 01:41:03 1.41
+++ savecore.c 2001/09/01 08:06:48
@@ -63,8 +63,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "zopen.h"
+extern FILE *zopen(const char *fname, const char *mode);
+
#ifdef __alpha__
#define ok(number) ALPHA_K0SEG_TO_PHYS(number)
#endif
@@ -131,7 +132,7 @@
int get_crashtime __P((void));
void get_dumpsize __P((void));
void kmem_setup __P((void));
-void log __P((int, char *, ...));
+void log __P((int, char *, ...)) __printf0like(2, 3);
void Lseek __P((int, off_t, int));
int Open __P((const char *, int rw));
int Read __P((int, void *, int));
@@ -384,9 +385,9 @@
/* Create the core file. */
oumask = umask(S_IRWXG|S_IRWXO); /* Restrict access to the core file.*/
(void)snprintf(path, sizeof(path), "%s/vmcore.%d%s",
- savedir, bounds, compress ? ".Z" : "");
+ savedir, bounds, compress ? ".gz" : "");
if (compress)
- fp = zopen(path, "w", 0);
+ fp = zopen(path, "w");
else
fp = fopen(path, "w");
if (fp == NULL) {
@@ -463,9 +464,9 @@
/* Copy the kernel. */
ifd = Open(kernel ? kernel : getbootfile(), O_RDONLY);
(void)snprintf(path, sizeof(path), "%s/kernel.%d%s",
- savedir, bounds, compress ? ".Z" : "");
+ savedir, bounds, compress ? ".gz" : "");
if (compress)
- fp = zopen(path, "w", 0);
+ fp = zopen(path, "w");
else
fp = fopen(path, "w");
if (fp == NULL) {
--- /dev/null Sat Sep 1 01:13:34 2001
+++ zopen.c Sat Sep 1 01:10:14 2001
@@ -0,0 +1,39 @@
+/*
+ * Public domain stdio wrapper for libz, written by Johan Danielsson.
+ */
+
+#ifndef lint
+static const char rcsid[] =
+ "$FreeBSD$";
+#endif /* not lint */
+
+#include <stdio.h>
+#include <zlib.h>
+
+FILE *zopen(const char *fname, const char *mode);
+
+/* convert arguments */
+static int
+xgzread(void *cookie, char *data, int size)
+{
+ return gzread(cookie, data, size);
+}
+
+static int
+xgzwrite(void *cookie, const char *data, int size)
+{
+ return gzwrite(cookie, (void*)data, size);
+}
+
+FILE *
+zopen(const char *fname, const char *mode)
+{
+ gzFile gz = gzopen(fname, mode);
+ if(gz == NULL)
+ return NULL;
+
+ if(*mode == 'r')
+ return (funopen(gz, xgzread, NULL, NULL, gzclose));
+ else
+ return (funopen(gz, NULL, xgzwrite, NULL, gzclose));
+}
PGP signature