summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sbin/savecore/savecore.84
-rw-r--r--sbin/savecore/savecore.c27
2 files changed, 21 insertions, 10 deletions
diff --git a/sbin/savecore/savecore.8 b/sbin/savecore/savecore.8
index 47e0a34..5a613c9 100644
--- a/sbin/savecore/savecore.8
+++ b/sbin/savecore/savecore.8
@@ -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
diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c
index 2fc2c60..b86b05b 100644
--- a/sbin/savecore/savecore.c
+++ b/sbin/savecore/savecore.c
@@ -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) {
@@ -529,11 +527,22 @@ get_crashtime()
}
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);
OpenPOWER on IntegriCloud