Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Jun 1996 16:11:42 +0200
From:      "Philippe C." <philou@lirmm.fr>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/1322: savecore: incorrect use of minfree
Message-ID:  <199606141411.QAA01133@pcdif01.lirmm.fr>
Resent-Message-ID: <199606141430.HAA18175@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         1322
>Category:       bin
>Synopsis:       savecore does not take minfree into account
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun 14 07:30:05 PDT 1996
>Last-Modified:
>Originator:     Philippe Charnier.
>Organization:
>Release:        FreeBSD 2.2-current
>Environment:

	

>Description:

	

I finally find a way to send this patch that is on my tree since months using
send-pr. It will not be lost. I real life, my address is charnier@lirmm.fr,
my From: line should lie.

        - dumpsize was used (in check_space) before being computed (in
          save_core): dumpsize was always 0 in check_space. Compute 
          dumpsize before calling check_space which need it.
        - convert all quantities required for free space computation to a
          number of bytes (some of them were in Kbytes, others in bytes,
          making result a little bit silly). Minfree is really take into
          account now.
        - cosmetics changes.
        - only dump a core is minfree bytes are left on the disk after
          the dump.

>How-To-Repeat:

	add only syslog(LOG_INFO,..) part of the patch and crash your kernel 
with not enough space in  /var/crash

>Fix:
	
	

cvs diff: Diffing .
Index: savecore.8
===================================================================
RCS file: /home2h/FreeBSD.cvsroot/src/sbin/savecore/savecore.8,v
retrieving revision 1.3
diff -u -r1.3 savecore.8
--- savecore.8	1994/09/24 00:08:21	1.3
+++ savecore.8	1996/06/13 20:26:05
@@ -65,7 +65,7 @@
 Use
 .Ar system
 as the kernel instead of the running kernel (as determined from
-.Xr getbootfile 3 )
+.Xr getbootfile 3 ).
 .It Fl v
 Prints out some additional debugging information.
 .It Fl z
Index: savecore.c
===================================================================
RCS file: /home2h/FreeBSD.cvsroot/src/sbin/savecore/savecore.c,v
retrieving revision 1.12
diff -u -r1.12 savecore.c
--- savecore.c	1996/05/02 09:07:53	1.12
+++ savecore.c	1996/05/03 18:38:19
@@ -290,6 +290,11 @@
 			*cp = getc(fp);
 		while (*cp++ && cp < &panic_mesg[sizeof(panic_mesg)]);
 	}
+	/* Read the dump size, and convert it to a number of bytes. */
+	(void)fseek(fp,
+		(off_t)(dumplo + ok(dump_nl[X_DUMPSIZE].n_value)), L_SET);
+	(void)fread(&dumpsize, sizeof(dumpsize), 1, fp);
+	dumpsize *= getpagesize();
 	/* Don't fclose(fp), we use dumpfd later. */
 }
 
@@ -369,15 +374,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) {
@@ -547,28 +547,27 @@
 		syslog(LOG_ERR, "%s: %m", dirname);
 		exit(1);
 	}
- 	spacefree = (fsbuf.f_bavail * fsbuf.f_bsize) / 1024;
-
+ 	spacefree = fsbuf.f_bavail * fsbuf.f_bsize;
+	minfree   = 0;
 	(void)snprintf(path, sizeof(path), "%s/minfree", dirname);
-	if ((fp = fopen(path, "r")) == NULL)
-		minfree = 0;
-	else {
-		if (fgets(buf, sizeof(buf), fp) == NULL)
-			minfree = 0;
-		else
-			minfree = atoi(buf);
+	if ((fp = fopen(path, "r"))) {
+		if (fgets(buf, sizeof(buf), fp)) minfree = atoi(buf);
 		(void)fclose(fp);
 	}
-
-	needed = (dumpsize + kernelsize) / 1024;
- 	if (minfree > 0 && spacefree - needed < minfree) {
-		syslog(LOG_WARNING,
-		    "no dump, not enough free space on device");
+	/* dumpsize, kernelsize, minfree, and spacefree are in bytes */
+	needed = dumpsize + kernelsize; /* minfree? not yet */
+	if (verbose) {
+		syslog(LOG_INFO, "dumpsize:   %d", dumpsize);
+		syslog(LOG_INFO, "kernelsize: %d", kernelsize);
+		syslog(LOG_INFO, "minfree:    %d", minfree);
+		syslog(LOG_INFO, "spacefree:  %d", spacefree);
+		syslog(LOG_INFO, "needed:     %d", needed);
+	}
+	/* space left (after the dump) must be greater than minfree */
+	if (spacefree < needed + minfree) {
+		syslog(LOG_WARNING, "no dump, not enough free space on device");
 		return (0);
 	}
-	if (spacefree - needed < minfree)
-		syslog(LOG_WARNING,
-		    "dump performed, but free space threshold crossed");
 	return (1);
 }

>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199606141411.QAA01133>