If fgets(3) fails in getbounds(), show strerror(3) if not an EOF. Also fix

a FILE* leak in getbounds().

Submitted by:	Conrad Meyer <conrad.meyer@isilon.com>
PR:		192032
Sponsored by:	EMC / Isilon Storage Division
MFC after:	1 week
This commit is contained in:
Bryan Drewery 2014-09-17 19:09:58 +00:00
parent f382031d34
commit 5e93a4b46b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=271720

View File

@ -151,7 +151,10 @@ getbounds(void) {
}
if (fgets(buf, sizeof buf, fp) == NULL) {
syslog(LOG_WARNING, "unable to read from bounds, using 0");
if (feof(fp))
syslog(LOG_WARNING, "bounds file is empty, using 0");
else
syslog(LOG_WARNING, "bounds file: %s", strerror(errno));
fclose(fp);
return (ret);
}
@ -160,6 +163,7 @@ getbounds(void) {
ret = (int)strtol(buf, NULL, 10);
if (ret == 0 && (errno == EINVAL || errno == ERANGE))
syslog(LOG_WARNING, "invalid value found in bounds, using 0");
fclose(fp);
return (ret);
}