sm_NORMAL,
sm_FLUSHING,
sm_FLUSHFAIL,
- sm_SEPARATED1,
- sm_SEPARATED2, /* must follow SEPARATED2 - see feedfile_eof */
- sm_DROPPING1,
- sm_DROPPING2, /* must follow DROPPING1 - see feedfile_eof */
+ sm_SEPARATED,
+ sm_DROPPING,
} StateMachineState;
struct Conn {
assert(ipf != main_input_file); /* promised by tailing_try_read */
assert(ipf == old_input_file);
- if (sms==sm_SEPARATED1) SMS(SEPARATED2, 0, "eof on old feed file");
- else if (sms==sm_DROPPING1) SMS(DROPPING2, 0, "eof on dead feed file");
- else abort();
-
inputfile_tailing_stop(ipf);
+ assert(ipf->fd >= 0);
+ if (close(ipf->fd)) sysdie("could not close input file %s", ipf->path);
+ ipf->fd= -1;
+
+ assert(sms==sm_SEPARATED || sms==sm_DROPPING);
+
if (main_input_file)
inputfile_tailing_start(main_input_file);
}
assert(!ipf->rd); /* must have had inputfile_tailing_stop */
assert(!ipf->inprogress); /* no dangling pointers pointing here */
- if (close(ipf->fd)) sysdie("could not close input file %s", ipf->path);
+ if (ipf->fd>=0)
+ if (close(ipf->fd)) sysdie("could not close input file %s", ipf->path);
free(ipf);
}
return r;
}
if (!r) {
- if (ipf==main_input_file) { errno=EAGAIN; return -1; }
- assert(sms==sm_SEPARATED1 || sms==sm_DROPPING1);
+ if (ipf==main_input_file) {
+ errno=EAGAIN;
+ return -1;
+ } else if (ipf==old_input_file) {
+ assert(ipf->fd>=0);
+ assert(sms==sm_SEPARATED || sms==sm_DROPPING);
+ } else if (ipf==backlog_input_file) {
+ assert(ipf->fd>=0);
+ } else {
+ abort();
+ }
}
return r;
}
| | open F \
| V V
| ============= ============
- | SEPARATED1 DROPPING1
+ | SEPARATED/ DROPPING/
+ | old->fd>=0 old->fd>=0
| [Separated] [Dropping]
| main F idle main none
| old D tail old D tail
| | |
^ | EOF ON D | EOF ON D
| V V
- | ============= ============
- | SEPARATED2 DROPPING2
+ | =============== ===============
+ | SEPARATED/ DROPPING/
+ | old->fd==-1 old->fd==-1
| [Finishing] [Dropping]
| main F tail main none
- | old D idle old D idle
- | ============= ============
+ | old D closed old D closed
+ | =============== ===============
| | |
| | ALL D PROCESSED | ALL D PROCESSED
| V install defer as backlog V install defer as backlog
spawn_inndcomm_flush(); /* => Flushing, sets sms to sm_FLUSHING */
} else {
/* F!=D => Separated */
- SMS(SEPARATED1, 0, "found both old and current feed files");
+ SMS(SEPARATED, 0, "found both old and current feed files");
startup_set_input_file(file_d);
}
} else { /*!file_d*/
struct timeval now, void *u) {
struct stat stab;
- int done= (sms==sm_SEPARATED2 || sms==sm_DROPPING2)
- && old_input_file->inprogress;
+ int done= (sms==sm_SEPARATED || sms==sm_DROPPING)
+ && old_input_file->fd==-1
+ && !old_input_file->inprogress;
if (!done) return;
r= fstat(fileno(defer), &stab);
if (unlink(path_duct))
sysdie("could not unlink old duct file %s", path_duct);
- if (sms==sm_DROPPING2) {
+ if (sms==sm_DROPPING) {
notice("feed dropped and our work is complete"
" (but check for backlog files)");
exit(0);
warn("feed has been dropped by innd, finishing up");
old_input_file= main_input_file;
main_input_file= 0;
- SMS(DROPPING1, 0, "dropped by innd");
+ SMS(DROPPING, 0, "dropped by innd");
return OOP_CONTINUE;
case 0:
main_input_file= open_input_file(feedfile);
if (!main_input_file)
die("flush succeeded but feedfile %s does not exist!", feedfile);
- SMS(SEPARATED1, 0, "feed file missing");
+ SMS(SEPARATED, 0, "feed file missing");
return OOP_CONTINUE;
default: