Add fscanf checks to init.c to warn us if calls fail.

Mostly to clean up compiler warnings.
This commit is contained in:
Jesse Smith 2018-02-20 19:38:40 -04:00
parent d21c8fc44b
commit 1d24d576f1

View File

@ -362,6 +362,7 @@ static CHILD *get_record(FILE *f)
CHILD *p; CHILD *p;
do { do {
errno = 0;
switch (cmd = get_cmd(f)) { switch (cmd = get_cmd(f)) {
case C_END: case C_END:
get_void(f); get_void(f);
@ -372,34 +373,54 @@ static CHILD *get_record(FILE *f)
case C_REC: case C_REC:
break; break;
case D_RUNLEVEL: case D_RUNLEVEL:
fscanf(f, "%c\n", &runlevel); if (fscanf(f, "%c\n", &runlevel) == EOF && errno != 0) {
fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno));
}
break; break;
case D_THISLEVEL: case D_THISLEVEL:
fscanf(f, "%c\n", &thislevel); if (fscanf(f, "%c\n", &thislevel) == EOF && errno != 0) {
fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno));
}
break; break;
case D_PREVLEVEL: case D_PREVLEVEL:
fscanf(f, "%c\n", &prevlevel); if (fscanf(f, "%c\n", &prevlevel) == EOF && errno != 0) {
fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno));
}
break; break;
case D_GOTSIGN: case D_GOTSIGN:
fscanf(f, "%u\n", &got_signals); if (fscanf(f, "%u\n", &got_signals) == EOF && errno != 0) {
fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno));
}
break; break;
case D_WROTE_WTMP_REBOOT: case D_WROTE_WTMP_REBOOT:
fscanf(f, "%d\n", &wrote_wtmp_reboot); if (fscanf(f, "%d\n", &wrote_wtmp_reboot) == EOF && errno != 0) {
fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno));
}
break; break;
case D_WROTE_UTMP_REBOOT: case D_WROTE_UTMP_REBOOT:
fscanf(f, "%d\n", &wrote_utmp_reboot); if (fscanf(f, "%d\n", &wrote_utmp_reboot) == EOF && errno != 0) {
fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno));
}
break; break;
case D_SLTIME: case D_SLTIME:
fscanf(f, "%d\n", &sltime); if (fscanf(f, "%d\n", &sltime) == EOF && errno != 0) {
fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno));
}
break; break;
case D_DIDBOOT: case D_DIDBOOT:
fscanf(f, "%d\n", &did_boot); if (fscanf(f, "%d\n", &did_boot) == EOF && errno != 0) {
fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno));
}
break; break;
case D_WROTE_WTMP_RLEVEL: case D_WROTE_WTMP_RLEVEL:
fscanf(f, "%d\n", &wrote_wtmp_rlevel); if (fscanf(f, "%d\n", &wrote_wtmp_rlevel) == EOF && errno != 0) {
fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno));
}
break; break;
case D_WROTE_UTMP_RLEVEL: case D_WROTE_UTMP_RLEVEL:
fscanf(f, "%d\n", &wrote_utmp_rlevel); if (fscanf(f, "%d\n", &wrote_utmp_rlevel) == EOF && errno != 0) {
fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno));
}
break; break;
default: default:
if (cmd > 0 || cmd == C_EOF) { if (cmd > 0 || cmd == C_EOF) {
@ -418,10 +439,14 @@ static CHILD *get_record(FILE *f)
get_void(f); get_void(f);
break; break;
case C_PID: case C_PID:
fscanf(f, "%d\n", &(p->pid)); if (fscanf(f, "%d\n", &(p->pid)) == EOF && errno != 0) {
fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno));
}
break; break;
case C_EXS: case C_EXS:
fscanf(f, "%u\n", &(p->exstat)); if (fscanf(f, "%u\n", &(p->exstat)) == EOF && errno != 0) {
fprintf(stderr, "%s (%d): %s\n", __FILE__, __LINE__, strerror(errno));
}
break; break;
case C_LEV: case C_LEV:
get_string(p->rlevel, sizeof(p->rlevel), f); get_string(p->rlevel, sizeof(p->rlevel), f);