Exit fsck_ffs with non-zero status when file system is not repaired.

When the fsck_ffs program cannot fully repair a file system, it will
output the message PLEASE RERUN FSCK. However, it does not exit with a
non-zero status in this case (contradicting the man page claim that it
"exits with 0 on success, and >0 if an error occurs."  The fsck
rc-script (when running "fsck -y") tests the status from fsck (which
passes along the exit status from fsck_ffs) and issues a "stop_boot"
if the status fails. However, this is not effective since fsck_ffs can
return zero even on (some) errors. Effectively, it is left to a later
step in the boot process when the file systems are mounted to detect
the still-unclean file system and stop the boot.

This change modifies fsck_ffs so that when it cannot fully repair the
file system and issues the PLEASE RERUN FSCK message it also exits
with a non-zero status.

While here, the fsck_ffs man page has also been updated to document
the failing exit status codes used by fsck_ffs. Previously, only exit
status 7 was documented. Some of these exit statuses are tested for in
the fsck rc-script, so they are clearly depended upon and deserve
documentation.

Reviewed by:	mckusick, vangyzen, jilles (manpages)
MFC after:	1 week
Sponsored by:	Dell EMC
Differential Revision:	https://reviews.freebsd.org/D13862
This commit is contained in:
dab 2018-01-15 19:25:11 +00:00
parent 03cbc447ee
commit 686a164856
3 changed files with 41 additions and 6 deletions

View File

@ -364,6 +364,7 @@ extern struct ufs2_dinode ufs2_zino;
#define FOUND 0x10
#define EEXIT 8 /* Standard error exit. */
#define ERERUN 16 /* fsck needs to be re-run. */
#define ERESTART -1
int flushentry(void);

View File

@ -29,7 +29,7 @@
.\" @(#)fsck.8 8.4 (Berkeley) 5/9/95
.\" $FreeBSD$
.\"
.Dd February 14, 2017
.Dd January 13, 2018
.Dt FSCK_FFS 8
.Os
.Sh NAME
@ -376,11 +376,43 @@ contains default list of file systems to check.
.Sh EXIT STATUS
.Ex -std
.Pp
If the option
Specific non-zero exit status values used are:
.Bl -tag -width indent
.It 1
Usage error (missing or invalid command arguments).
.It 2
The
.Fl p
option was used and a
.Dv SIGQUIT
was received, indicating that the system should be returned to single
user mode after the file system check.
.It 3
The file system superblock cannot be read.
This could indicate that the file system device does not exist or is not yet
ready.
.It 4
A mounted file system was modified; the system should be rebooted.
.It 5
The
.Fl B
option was used and soft updates are not enabled on the file system.
.It 6
The
.Fl B
option was used and the kernel lacks needed support.
.It 7
The
.Fl F
is used,
option was used and the file system is clean.
.It 8
General error exit.
.It 16
The file system could not be completely repaired.
The file system may be able to be repaired by running
.Nm
exits 7 if the file system is clean.
on the file system again.
.El
.Sh DIAGNOSTICS
The diagnostics produced by
.Nm

View File

@ -82,6 +82,7 @@ main(int argc, char *argv[])
int ch;
struct rlimit rlimit;
struct itimerval itimerval;
int fsret;
int ret = 0;
sync();
@ -196,8 +197,9 @@ main(int argc, char *argv[])
(void)setrlimit(RLIMIT_DATA, &rlimit);
}
while (argc > 0) {
if (checkfilesys(*argv) == ERESTART)
if ((fsret = checkfilesys(*argv)) == ERESTART)
continue;
ret |= fsret;
argc--;
argv++;
}
@ -585,7 +587,7 @@ checkfilesys(char *filesys)
sync();
return (4);
}
return (0);
return (rerun ? ERERUN : 0);
}
static int