/*---------------------------------------------------------------------- handle hang up signal -- SIGUSR2 Not much to do. Rely on periodic mail file check pointing. ----------------------------------------------------------------------*/ static RETSIGTYPE usr2_signal(int sig) { char c, *mbox, mboxbuf[20]; int i; MAILSTREAM *stream; NETMBX mb; for(i = 0; i < ps_global->s_pool.nstream; i++) { stream = ps_global->s_pool.streams[i]; if(stream && sp_flagged(stream, SP_LOCKED) && !sp_dead_stream(stream) && !stream->lock && !stream->rdonly && stream->mailbox && (c = *stream->mailbox) != '{' && c != '*') { pine_mail_check(stream); /* write latest state */ stream->rdonly = 1; /* and become read-only */ (void) pine_mail_ping(stream); mbox = stream->mailbox; if(!strucmp(stream->mailbox, ps_global->inbox_name) || !strcmp(stream->mailbox, ps_global->VAR_INBOX_PATH) || !strucmp(stream->original_mailbox, ps_global->inbox_name) || !strcmp(stream->original_mailbox, ps_global->VAR_INBOX_PATH)) mbox = "INBOX"; else if(mail_valid_net_parse(stream->mailbox, &mb) && mb.mailbox) mbox = mb.mailbox; q_status_message1(SM_ASYNC, 3, 7, _("Another email program is accessing %s. Session now Read-Only."), short_str((mbox && *mbox) ? mbox : "folder", mboxbuf, sizeof(mboxbuf), 19, FrontDots)); dprint((1, "** folder %s went read-only **\n\n", stream->mailbox)); } } }
int check_point(MAILSTREAM *stream, CheckPointTime timing, int flags) { int freq, tm, check_count, tst1 = 0, tst2 = 0, accel; long since_last_input, since_first_change; time_t now, then; #define AT_LEAST (180) #define MIN_LONG_CHK_IDLE (10) if(!stream || stream->rdonly || stream->halfopen || (check_count = sp_check_cnt(stream)) == 0) return(0); since_last_input = (long) time(0) - (long) time_of_last_input(); if(timing == GoodTime && since_last_input <= 0) timing = VeryBadTime; else if(timing == GoodTime && since_last_input <= 4) timing = BadTime; dprint((9, "check_point(%s: %s)\n", timing == GoodTime ? "GoodTime" : timing == BadTime ? "BadTime" : timing == VeryBadTime ? "VeryBadTime" : "DoItNow", STREAMNAME(stream))); freq = CHECK_POINT_FREQ * (timing==GoodTime ? 1 : timing==BadTime ? 3 : 4); tm = CHECK_POINT_TIME * (timing==GoodTime ? 2 : timing==BadTime ? 4 : 6); tm = MAX(100, tm); if(timing == DoItNow){ dprint((9, "DoItNow\n")); } else{ since_first_change = (long) (time(0) - sp_first_status_change(stream)); accel = MIN(3, MAX(1, (4 * since_first_change)/tm)); tst1 = ((check_count * since_last_input) >= (30/accel) * freq); tst2 = ((since_first_change >= tm) && (since_last_input >= MIN_LONG_CHK_IDLE)); dprint((9, "Chk changes(%d) x since_last_input(%ld) (=%ld) >= freq(%d) x 30/%d (=%d) ? %s\n", check_count, since_last_input, check_count * since_last_input, freq, accel, (30/accel)*freq, tst1 ? "Yes" : "No")); dprint((9, " or since_1st_change(%ld) >= tm(%d) && since_last_input >= %d ? %s\n", since_first_change, tm, MIN_LONG_CHK_IDLE, tst2 ? "Yes" : "No")); } if(timing == DoItNow || tst1 || tst2){ if(timing == DoItNow || time(0) - sp_last_chkpnt_done(stream) >= AT_LEAST){ then = time(0); dprint((2, "Checkpoint: %s Since 1st change: %ld secs idle: %ld secs\n", debug_time(0,1), (long) (then - sp_first_status_change(stream)), since_last_input)) ; if((flags & NM_STATUS_MSG) && pith_opt_checkpoint_cue) (*pith_opt_checkpoint_cue)(TRUE); pine_mail_check(stream); /* write file state */ now = time(0); dprint((2, "Checkpoint complete: %s%s%s%s\n", debug_time(0,1), (now-then > 0) ? " (elapsed: " : "", (now-then > 0) ? comatose((long)(now-then)) : "", (now-then > 0) ? " secs)" : "")); if((flags & NM_STATUS_MSG) && pith_opt_checkpoint_cue) (*pith_opt_checkpoint_cue)(FALSE); return(1); } else{ dprint((9, "Skipping checkpoint since last was only %ld secs ago (< %d)\n", (long) (time(0) - sp_last_chkpnt_done(stream)), AT_LEAST)); } } return(0); }