Ensure that fsck(8) / fsck_ffs(8) produces the correct exit code

for missing devices.

The fsck_ffs(8) utility uses its internal function openfilesys()
when opening a disk to be checked. This change avoids the use
of pfatal() in openfilesys() which always exits with failure (exit
value 8) so that the caller can choose the correct exit value.
In the case of a non-existent device it should exit with value 3
which allows the startup system to wait for drives (such as those
attached by USB) to come online.

Reported by: karels
Tested by:   karels
PR:          262580
MFC after:   3 days
This commit is contained in:
Kirk McKusick 2022-03-16 11:37:15 -07:00
parent e997f33700
commit 2983ec0a87

View File

@ -219,10 +219,8 @@ openfilesys(char *dev)
struct stat statb;
int saved_fsreadfd;
if (stat(dev, &statb) < 0) {
pfatal("CANNOT STAT %s: %s\n", dev, strerror(errno));
if (stat(dev, &statb) < 0)
return (0);
}
if ((statb.st_mode & S_IFMT) != S_IFCHR &&
(statb.st_mode & S_IFMT) != S_IFBLK) {
if (bkgrdflag != 0 && (statb.st_flags & SF_SNAPSHOT) == 0) {
@ -240,7 +238,6 @@ openfilesys(char *dev)
saved_fsreadfd = fsreadfd;
if ((fsreadfd = open(dev, O_RDONLY)) < 0) {
fsreadfd = saved_fsreadfd;
pfatal("CANNOT OPEN %s: %s\n", dev, strerror(errno));
return (0);
}
if (saved_fsreadfd != -1)