Subject: bin/1257: savecore: setting /var/crash/minfree doesn't work
To: None <gnats-bugs@gnats.netbsd.org>
From: enami tsugutomo <enami@sys.ptg.sony.co.jp>
List: netbsd-bugs
Date: 07/22/1995 13:57:00
>Number:         1257
>Category:       bin
>Synopsis:       Inhibitting savecore by minfree file doesn't work
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul 22 19:20:04 1995
>Last-Modified:
>Originator:     enami tsugutomo
>Organization:
	Sony Corporation.
>Release:        arround jul 7
>Environment:
System: NetBSD king-show 1.0A NetBSD 1.0A (KINGSHOW) #9: Thu Jul 20 07:49:12 JST 1995 root@king-show:/usr/src/sys/arch/i386/compile/KINGSHOW i386

	24M bytes of main memory and 7M bytes of free space in /var/crash.

>Description:
	Inhibitting savecore by creating appropreate minfree file
	doesn't work in certain condition.  This is because the variable
	`dumpsize' is used (in check_space) before is set (in save_core).

>How-To-Repeat:
	First create minfree file, for example:
		echo 4096 > /var/crash/minfree
	Then make system panic in some way, and reboot.
	During the boot, savecore tries to save core to /var/crash
	even if 7M - 24M < 4096 kilobytes.
>Fix:
	The workaround is set dumpsize in the function `dump_exists'
	instead of in the `save_core'.

===================================================================
RCS file: RCS/savecore.c,v
retrieving revision 1.1
diff -u -r1.1 savecore.c
--- savecore.c	1995/07/05 11:51:54	1.1
+++ savecore.c	1995/07/05 12:23:33
@@ -321,6 +321,13 @@
 		syslog(LOG_WARNING, "no core dump");
 		return (0);
 	}
+
+	/* Read the dump size. */
+	Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPSIZE].n_value)), L_SET);
+	(void)Read(dumpfd, &dumpsize, sizeof(dumpsize));
+
+	dumpsize *= getpagesize();
+
 	return (1);
 }
 
@@ -374,15 +381,10 @@
 		ifd = dumpfd;
 	}
 
-	/* Read the dump size. */
-	Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPSIZE].n_value)), L_SET);
-	(void)Read(dumpfd, &dumpsize, sizeof(dumpsize));
-
 	/* Seek to the start of the core. */
 	Lseek(ifd, (off_t)dumplo, L_SET);
 
 	/* Copy the core file. */
-	dumpsize *= getpagesize();
 	syslog(LOG_NOTICE, "writing %score to %s",
 	    compress ? "compressed " : "", path);
 	for (; dumpsize > 0; dumpsize -= nr) {
>Audit-Trail:
>Unformatted: