1 /* 2 ** Copyright 2002-2006, Double Precision Inc. 3 ** 4 ** See COPYING for distribution information. 5 */ 6 #ifndef libmail_mboxsighandler_H 7 #define libmail_mboxsighandler_H 8 9 #include "libmail_config.h" 10 #include "mbox.H" 11 12 #include <sys/types.h> 13 #include <sys/stat.h> 14 #include <unistd.h> 15 16 LIBMAIL_START 17 18 /////////////////////////////////////////////////////////////////////// 19 // 20 // Trap process signals when updating an mboxAccount file. A received signal 21 // restores an mboxAccount file to its original size. 22 23 class mbox::sighandler { 24 25 int fd; 26 off_t origSize; 27 28 static void handler(int); 29 30 static mbox::sighandler *curHandler; 31 32 public: 33 sighandler(int fd); getOrigSize()34 off_t getOrigSize() const { return (origSize); } 35 void block(); rollback()36 void rollback() const 37 { 38 if (ftruncate(fd, origSize) < 0) 39 ; // Ignore gcc warning 40 } 41 42 ~sighandler(); 43 }; 44 45 LIBMAIL_END 46 47 #endif 48