1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-02 08:42:48 +00:00

Make the savecore command work like the man page says:

- make minfree work by getting the dump size before checking to see
  if the dump will fit on the filesystem
- also fail to dump if no minfree is specified but there are not enough
  free blocks.

Fix a typo in the man page.

Fixes PR bin/1322

Submitted by:	"Philippe C." <charnier@lirmm.fr>
This commit is contained in:
Bill Fenner 1996-10-13 18:12:20 +00:00
parent 4023b3033b
commit 4731e263af
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=18914
2 changed files with 21 additions and 10 deletions

View File

@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" From: @(#)savecore.8 8.1 (Berkeley) 6/5/93
.\" $Id$
.\" $Id: savecore.8,v 1.3 1994/09/24 00:08:21 wollman Exp $
.\"
.Dd September 23, 1994
.Dt SAVECORE 8
@ -65,7 +65,7 @@ is insufficient disk space.
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

View File

@ -119,6 +119,7 @@ int Create __P((char *, int));
int dump_exists __P((void));
char *find_dev __P((dev_t, int));
int get_crashtime __P((void));
int get_dumpsize __P((void));
void kmem_setup __P((void));
void log __P((int, char *, ...));
void Lseek __P((int, off_t, int));
@ -189,6 +190,8 @@ main(argc, argv)
else
syslog(LOG_ALERT, "reboot");
get_dumpsize();
if ((!get_crashtime() || !check_space()) && !force)
exit(1);
@ -370,15 +373,10 @@ err1: syslog(LOG_WARNING, "%s: %s", path, strerror(errno));
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) {
@ -528,12 +526,23 @@ get_crashtime()
return (1);
}
int
get_dumpsize()
{
/* 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);
}
int
check_space()
{
register FILE *fp;
const char *tkernel;
off_t minfree, spacefree, kernelsize, needed;
off_t minfree, spacefree, totfree, kernelsize, needed;
struct stat st;
struct statfs fsbuf;
char buf[100], path[MAXPATHLEN];
@ -544,11 +553,13 @@ check_space()
exit(1);
}
kernelsize = st.st_blocks * S_BLKSIZE;
if (statfs(dirname, &fsbuf) < 0) {
syslog(LOG_ERR, "%s: %m", dirname);
exit(1);
}
spacefree = ((off_t) fsbuf.f_bavail * fsbuf.f_bsize) / 1024;
totfree = ((off_t) fsbuf.f_bfree * fsbuf.f_bsize) / 1024;
(void)snprintf(path, sizeof(path), "%s/minfree", dirname);
if ((fp = fopen(path, "r")) == NULL)
@ -562,12 +573,12 @@ check_space()
}
needed = (dumpsize + kernelsize) / 1024;
if (minfree > 0 && spacefree - needed < minfree) {
if (((minfree > 0) ? spacefree : totfree) - needed < minfree) {
syslog(LOG_WARNING,
"no dump, not enough free space on device");
return (0);
}
if (spacefree - needed < minfree)
if (spacefree - needed < 0)
syslog(LOG_WARNING,
"dump performed, but free space threshold crossed");
return (1);