| ︙ | | | ︙ | |
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
*/
#include "config.h"
#include "backoffice.h"
#include <time.h>
#if defined(_WIN32)
# include <windows.h>
#else
# include <sys/types.h>
# include <signal.h>
#endif
/*
** The BKOFCE_LEASE_TIME is the amount of time for which a single backoffice
** processing run is valid. Each backoffice run monopolizes the lease for
|
>
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
*/
#include "config.h"
#include "backoffice.h"
#include <time.h>
#if defined(_WIN32)
# include <windows.h>
#else
# include <unistd.h>
# include <sys/types.h>
# include <signal.h>
#endif
/*
** The BKOFCE_LEASE_TIME is the amount of time for which a single backoffice
** processing run is valid. Each backoffice run monopolizes the lease for
|
| ︙ | | | ︙ | |
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
static sqlite3_uint64 backofficeProcessId(void){
#if defined(_WIN32)
return (sqlite3_uint64)GetCurrentProcessId();
#else
return (sqlite3_uint64)getpid();
#endif
}
/*
** COMMAND: test-process-id
**
** Usage: %fossil [--sleep N] PROCESS-ID ...
**
** Show the current process id, and also tell whether or not all other
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
static sqlite3_uint64 backofficeProcessId(void){
#if defined(_WIN32)
return (sqlite3_uint64)GetCurrentProcessId();
#else
return (sqlite3_uint64)getpid();
#endif
}
/*
** Set an alarm to cause the process to exit after "x" seconds. This
** prevents any kind of bug from keeping a backoffice process running
** indefinitely.
*/
#if !defined(_WIN32)
static void backofficeSigalrmHandler(int x){
fossil_panic("backoffice timeout");
}
#endif
static void backofficeTimeout(int x){
#if !defined(_WIN32)
signal(SIGALRM, backofficeSigalrmHandler);
alarm(x);
#endif
}
/*
** COMMAND: test-process-id
**
** Usage: %fossil [--sleep N] PROCESS-ID ...
**
** Show the current process id, and also tell whether or not all other
|
| ︙ | | | ︙ | |
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
if( g.db==0 ){
fossil_panic("database not open for backoffice processing");
}
if( db_transaction_nesting_depth()!=0 ){
fossil_panic("transaction %s not closed prior to backoffice processing",
db_transaction_start_point());
}
idSelf = backofficeProcessId();
while(1){
tmNow = time(0);
db_begin_write();
backofficeReadLease(&x);
if( x.tmNext>=tmNow
&& x.idNext!=idSelf
|
>
|
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
if( g.db==0 ){
fossil_panic("database not open for backoffice processing");
}
if( db_transaction_nesting_depth()!=0 ){
fossil_panic("transaction %s not closed prior to backoffice processing",
db_transaction_start_point());
}
backofficeTimeout(BKOFCE_LEASE_TIME*2);
idSelf = backofficeProcessId();
while(1){
tmNow = time(0);
db_begin_write();
backofficeReadLease(&x);
if( x.tmNext>=tmNow
&& x.idNext!=idSelf
|
| ︙ | | | ︙ | |
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
}
/* This process needs to queue up and wait for the current lease
** to expire before continuing. */
x.idNext = idSelf;
x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME;
backofficeWriteLease(&x);
db_end_transaction(0);
if( x.tmCurrent >= tmNow ){
sqlite3_sleep(1000*(x.tmCurrent - tmNow + 1));
}else{
if( lastWarning+warningDelay < tmNow ){
fossil_warning(
"backoffice process %lld still running after %d seconds",
x.idCurrent, (int)(BKOFCE_LEASE_TIME + tmNow - x.tmCurrent));
|
>
>
>
|
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
}
/* This process needs to queue up and wait for the current lease
** to expire before continuing. */
x.idNext = idSelf;
x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME;
backofficeWriteLease(&x);
db_end_transaction(0);
if( g.fAnyTrace ){
fprintf(stderr, "/***** Backoffice On-deck %d *****/\n", getpid());
}
if( x.tmCurrent >= tmNow ){
sqlite3_sleep(1000*(x.tmCurrent - tmNow + 1));
}else{
if( lastWarning+warningDelay < tmNow ){
fossil_warning(
"backoffice process %lld still running after %d seconds",
x.idCurrent, (int)(BKOFCE_LEASE_TIME + tmNow - x.tmCurrent));
|
| ︙ | | | ︙ | |