76
81
// indexing routines.
79
// Mainly used to request indexing stop, we currently do not use the
84
// Receive status updates from the ongoing indexing operation
85
// Also check for an interrupt request and return the info to caller which
86
// should subsequently orderly terminate what it is doing.
81
87
class MyUpdater : public DbIxStatusUpdater {
83
virtual bool update() {
89
MyUpdater(RclConfig *config)
90
: m_prevphase(DbIxStatus::DBIXS_NONE)
92
m_fd = open(config->getIdxStatusFile().c_str(),
93
O_WRONLY|O_CREAT|O_TRUNC, 0600);
95
LOGERR(("Can't open/create status file: [%s]\n",
96
config->getIdxStatusFile().c_str()));
101
// Update the status file. Avoid doing it too often
102
if (status.phase != m_prevphase || m_chron.millis() > 300) {
103
m_prevphase = status.phase;
107
FILE *fp = fdopen(fd1, "w");
108
fprintf(fp, "phase = %d\n", int(status.phase));
109
fprintf(fp, "docsdone = %d\n", status.docsdone);
110
fprintf(fp, "filesdone = %d\n", status.filesdone);
111
fprintf(fp, "dbtotdocs = %d\n", status.dbtotdocs);
112
fprintf(fp, "fn = %s\n", status.fn.c_str());
113
ftruncate(m_fd, off_t(ftell(fp)));
114
// Flush data and closes fd1. m_fd still valid
84
118
if (stopindexing) {
88
// If we are in the monitor, we also need to check x status
122
// If we are in the monitor, we also need to check X11 status
89
123
// during the initial indexing pass (else the user could log
90
124
// out and the indexing would go on, not good (ie: if the user
91
125
// logs in again, the new recollindex will fail).
92
126
if ((op_flags & OPT_m) && !(op_flags & OPT_x) && !x11IsAlive()) {
93
LOGDEB(("X11 session went away during initial indexing pass\n"));
127
LOGDEB(("X11 session went away during initial indexing pass\n"));
138
DbIxStatus::Phase m_prevphase;
101
static MyUpdater updater;
140
static MyUpdater *updater;
103
142
static void sigcleanup(int sig)
189
228
" Index everything according to configuration file\n"
190
229
" -z : reset database before starting indexing\n"
191
230
#ifdef RCL_MONITOR
192
"recollindex -m [-w <secs>] -x [-D]\n"
231
"recollindex -m [-w <secs>] -x [-D] [-C]\n"
193
232
" Perform real time indexing. Don't become a daemon if -D is set.\n"
194
233
" -w sets number of seconds to wait before starting.\n"
234
" -C disables monitoring config for changes/reexecuting.\n"
195
235
#ifndef DISABLE_X11MON
196
236
" -x disables exit on end of x11 session\n"
197
237
#endif /* DISABLE_X11MON */
298
341
cerr << "Configuration problem: " << reason << endl;
344
o_reexec->atexit(cleanup);
301
346
bool rezero(op_flags & OPT_z);
302
347
Pidfile pidfile(config->getPidfile());
348
updater = new MyUpdater(config);
304
350
if (setpriority(PRIO_PROCESS, 0, 20) != 0) {
305
351
LOGINFO(("recollindex: can't setpriority(), errno %d\n", errno));
387
confindexer = new ConfIndexer(config, &updater);
432
confindexer = new ConfIndexer(config, updater);
388
433
if (!confindexer->index(rezero, ConfIndexer::IxTAll) || stopindexing) {
389
434
LOGERR(("recollindex, initial indexing pass failed, not going into monitor mode\n"));
438
updater->status.phase = DbIxStatus::DBIXS_MONITOR;
439
updater->status.fn.clear();
392
442
deleteZ(confindexer);
393
443
int opts = RCLMON_NONE;
394
444
if (op_flags & OPT_D)
395
445
opts |= RCLMON_NOFORK;
446
if (op_flags & OPT_C)
447
opts |= RCLMON_NOCONFCHECK;
396
448
if (op_flags & OPT_x)
397
449
opts |= RCLMON_NOX11;
398
450
bool monret = startMonitor(config, opts);
413
465
lockorexit(&pidfile);
414
466
pidfile.write_pid();
415
confindexer = new ConfIndexer(config, &updater);
467
confindexer = new ConfIndexer(config, updater);
416
468
bool status = confindexer->index(rezero, ConfIndexer::IxTAll);
418
470
cerr << "Indexing failed" << endl;
419
471
if (!confindexer->getReason().empty())
420
472
cerr << confindexer->getReason() << endl;
475
updater->status.phase = DbIxStatus::DBIXS_DONE;
476
updater->status.fn.clear();