cleanup.c (1381B)
1 #include "mxf-send.h" 2 /* this file is too long ------------------------------------------ CLEANUPS */ 3 4 int flagcleanup; /* if 1, cleanupdir is initialized and ready */ 5 readsubdir cleanupdir; 6 datetime_sec cleanuptime; 7 8 void 9 cleanup_init() 10 { 11 flagcleanup = 0; 12 cleanuptime = now(); 13 } 14 15 void 16 cleanup_selprep(datetime_sec * wakeup) 17 { 18 if (flagcleanup) 19 *wakeup = 0; 20 if (*wakeup > cleanuptime) 21 *wakeup = cleanuptime; 22 } 23 24 void 25 cleanup_do() 26 { 27 char ch; 28 struct stat st; 29 unsigned long id; 30 31 if (!flagcleanup) { 32 if (recent < cleanuptime) 33 return; 34 readsubdir_init(&cleanupdir, "mess", pausedir); 35 flagcleanup = 1; 36 } 37 38 switch (readsubdir_next(&cleanupdir, &id)) { 39 case 1: 40 break; 41 case 0: 42 flagcleanup = 0; 43 cleanuptime = recent + SLEEP_CLEANUP; 44 default: 45 return; 46 } 47 48 fnmake_mess(id, &fn); 49 if (stat(fn.s, &st) == -1) 50 return; /* probably qmail-queue deleted it */ 51 if (recent <= st.st_atime + OSSIFIED) 52 return; 53 54 fnmake_info(id, &fn); 55 if (stat(fn.s, &st) == 0) 56 return; 57 if (errno != error_noent) 58 return; 59 fnmake_todo(id, &fn); 60 if (stat(fn.s, &st) == 0) 61 return; 62 if (errno != error_noent) 63 return; 64 65 fnmake_foop(id, &fn); 66 if (substdio_putflush(&sstoqc, fn.s, fn.len) == -1) { 67 cleandied(); 68 return; 69 } 70 if (substdio_get(&ssfromqc, &ch, 1) != 1) { 71 cleandied(); 72 return; 73 } 74 if (ch != '+') 75 log3("warning: qmail-clean unable to clean up ", fn.s, "\n"); 76 }