return(-1);
}
- /* get the position in file to be sought */
- if(es->offset)
- last = es->offset;
- else {
+ while(1) { /* try, try, try */
+
+ /* get the position in file to be sought */
+ if(es->offset)
+ last = es->offset;
+ else {
#if !defined(IL_NOTIFICATIONS)
- if(eq_b == eq_l)
- last = es->last_committed_ls;
- else
+ if(eq_b == eq_l)
+ last = es->last_committed_ls;
+ else
#endif
- /* last = min(ls, bs) */
- last = (es->last_committed_bs < es->last_committed_ls) ? es->last_committed_bs : es->last_committed_ls;
- }
-
- il_log(LOG_DEBUG, " setting starting file position to %ld\n", last);
- il_log(LOG_DEBUG, " bytes sent to logging server: %d\n", es->last_committed_ls);
- il_log(LOG_DEBUG, " bytes sent to bookkeeping server: %d\n", es->last_committed_bs);
+ /* last = min(ls, bs) */
+ /* I took the liberty to optimize this,
+ since LS is not used. */
+ /* last = (es->last_committed_bs <
+ es->last_committed_ls) ? es->last_committed_bs :
+ es->last_committed_ls; */
+ last = es->last_committed_bs;
+ }
- /* skip all committed or already enqueued events */
- if(fseek(ef, last, SEEK_SET) < 0) {
- set_error(IL_SYS, errno, "event_store_recover: error setting position for read");
- event_store_unlock(es);
- fclose(ef);
- return(-1);
+ il_log(LOG_DEBUG, " setting starting file position to %ld\n", last);
+ il_log(LOG_DEBUG, " bytes sent to logging server: %d\n", es->last_committed_ls);
+ il_log(LOG_DEBUG, " bytes sent to bookkeeping server: %d\n", es->last_committed_bs);
+
+ if(last > 0) {
+ int c;
+
+ /* skip all committed or already enqueued events */
+ /* be careful - check, if the offset really points to the
+ beginning of event string */
+ if(fseek(ef, last-1, SEEK_SET) < 0) {
+ set_error(IL_SYS, errno, "event_store_recover: error setting position for read");
+ event_store_unlock(es);
+ fclose(ef);
+ return(-1);
+ }
+ /* the last enqueued event MUST end with EVENT_SEPARATOR,
+ even if the offset points at EOF */
+ if((c=fgetc(ef)) != EVENT_SEPARATOR) {
+ /* Houston, we have got a problem */
+ il_log(LOG_WARNING,
+ " file position %ld does not point at the beginning of event string, backing off!\n",
+ last);
+ /* now, where were we? */
+ if(es->offset) {
+ /* next try will be with
+ last_commited_bs */
+ es->offset = 0;
+ } else {
+ /* this is really weird... back off completely */
+ es->last_committed_ls = es->last_committed_bs = 0;
+ }
+ } else {
+ /* OK, break out of the loop */
+ break;
+ }
+ } else {
+ /* this breaks out of the loop, we are starting at
+ * the beginning of file
+ */
+ if(fseek(ef, 0, SEEK_SET) < 0) {
+ set_error(IL_SYS, errno, "event_store_recover: error setting position for read");
+ event_store_unlock(es);
+ fclose(ef);
+ return(-1);
+ }
+ break;
+ }
}
/* enqueue all remaining events */
msg = server_msg_create(event_s, last);
free(event_s);
if(msg == NULL) {
- break;
+ il_log(LOG_ALERT, " event file corrupted! Please move it to quarantine (ie. somewhere else) and restart interlogger.\n");
+ break;
}
msg->es = es;