| | @@ -42,10 +42,11 @@ |
| 42 | 42 | #include "backoffice.h" |
| 43 | 43 | #include <time.h> |
| 44 | 44 | #if defined(_WIN32) |
| 45 | 45 | # include <windows.h> |
| 46 | 46 | #else |
| 47 | +# include <unistd.h> |
| 47 | 48 | # include <sys/types.h> |
| 48 | 49 | # include <signal.h> |
| 49 | 50 | #endif |
| 50 | 51 | |
| 51 | 52 | /* |
| | @@ -164,10 +165,28 @@ |
| 164 | 165 | return (sqlite3_uint64)GetCurrentProcessId(); |
| 165 | 166 | #else |
| 166 | 167 | return (sqlite3_uint64)getpid(); |
| 167 | 168 | #endif |
| 168 | 169 | } |
| 170 | + |
| 171 | +/* |
| 172 | +** Set an alarm to cause the process to exit after "x" seconds. This |
| 173 | +** prevents any kind of bug from keeping a backoffice process running |
| 174 | +** indefinitely. |
| 175 | +*/ |
| 176 | +#if !defined(_WIN32) |
| 177 | +static void backofficeSigalrmHandler(int x){ |
| 178 | + fossil_panic("backoffice timeout"); |
| 179 | +} |
| 180 | +#endif |
| 181 | +static void backofficeTimeout(int x){ |
| 182 | +#if !defined(_WIN32) |
| 183 | + signal(SIGALRM, backofficeSigalrmHandler); |
| 184 | + alarm(x); |
| 185 | +#endif |
| 186 | +} |
| 187 | + |
| 169 | 188 | |
| 170 | 189 | /* |
| 171 | 190 | ** COMMAND: test-process-id |
| 172 | 191 | ** |
| 173 | 192 | ** Usage: %fossil [--sleep N] PROCESS-ID ... |
| | @@ -214,10 +233,11 @@ |
| 214 | 233 | } |
| 215 | 234 | if( db_transaction_nesting_depth()!=0 ){ |
| 216 | 235 | fossil_panic("transaction %s not closed prior to backoffice processing", |
| 217 | 236 | db_transaction_start_point()); |
| 218 | 237 | } |
| 238 | + backofficeTimeout(BKOFCE_LEASE_TIME*2); |
| 219 | 239 | idSelf = backofficeProcessId(); |
| 220 | 240 | while(1){ |
| 221 | 241 | tmNow = time(0); |
| 222 | 242 | db_begin_write(); |
| 223 | 243 | backofficeReadLease(&x); |
| | @@ -257,10 +277,13 @@ |
| 257 | 277 | ** to expire before continuing. */ |
| 258 | 278 | x.idNext = idSelf; |
| 259 | 279 | x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME; |
| 260 | 280 | backofficeWriteLease(&x); |
| 261 | 281 | db_end_transaction(0); |
| 282 | + if( g.fAnyTrace ){ |
| 283 | + fprintf(stderr, "/***** Backoffice On-deck %d *****/\n", getpid()); |
| 284 | + } |
| 262 | 285 | if( x.tmCurrent >= tmNow ){ |
| 263 | 286 | sqlite3_sleep(1000*(x.tmCurrent - tmNow + 1)); |
| 264 | 287 | }else{ |
| 265 | 288 | if( lastWarning+warningDelay < tmNow ){ |
| 266 | 289 | fossil_warning( |
| 267 | 290 | |