cyr_expire "-p prefix", don't segfault on damaged cache

Bron Gondwana brong at
Sun Sep 2 20:29:08 EDT 2007

As I mentioned earlier on the train... the patch I wrote last night
to avoid segfaults when cyr_expire hit broken cyrus.cache files.

We had maybe 30 of them spread amongst our machines, and each one
would cause a segfault in cyr_expire.  Unfortunately, there wasn't
enough information being logged to see which mailbox caused the issue.

I could use the last "cyr_expire.*expunged $n messages from $mailbox"
message in the syslog to get a rough idea, then use the -p option to
run over the same area and strace the process.  Rather crap though,
and still segfaulting.

So I wrote the other bit to log the error and keep going instead.
Along with our monitoring this means that the weekly cyr_expire
runs will continue to work fine (Sunday was low-IO day, not so much
now we run cyr_expire there!) and on Monday I can read my emails and
go clean up the affected mailboxes.

Later once I have a bit more data I can try and figure out why the
corruption - but I suspect it's mainly crashes in the past.  Hopefully
this is a once-off job anyway.

I think the "stop segfaults" code is worth inclusion:

            for (cache_ent = 0; cache_ent < NUM_CACHE_FIELDS; cache_ent++) {
                cacheitem = CACHE_ITEM_NEXT(cacheitem);
+               if ((cacheitem < (mailbox->cache_base + cache_offset)) ||
+                   (cacheitem > (mailbox->cache_base + mailbox->cache_len))) {
+                   syslog(LOG_ERR, "IOERROR: reading cache record for %s: got bogus offset %d for %u/%lu; try reconstruct",
+                                mailbox->name, cacheitem - (mailbox->cache_base + cache_offset), msgno, mailbox->exists);
+                   return IMAP_IOERROR;
+               }

The -p option - well, it's handy for cleaning up just one 
user's expunged files if they have something sensitive in
there, or are wasting particularly much disk space for
whatever reason and you don't want the IO hit/time use of
running a complete cyr_expire run.  Also you can run with
different options (we use -X 7 -D 7 -E 1 usually) to clean
that mailbox up early. is updated with this patch too.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: cyrus-expire-prefix-2.3.9.diff
Type: text/x-diff
Size: 3260 bytes
Desc: not available
Url : 

More information about the Cyrus-devel mailing list