|
a/src/index/recollindex.cpp |
|
b/src/index/recollindex.cpp |
|
... |
|
... |
34 |
#include <string>
|
34 |
#include <string>
|
35 |
#include <cstdlib>
|
35 |
#include <cstdlib>
|
36 |
|
36 |
|
37 |
using namespace std;
|
37 |
using namespace std;
|
38 |
|
38 |
|
39 |
#include "debuglog.h"
|
39 |
#include "log.h"
|
40 |
#include "rclinit.h"
|
40 |
#include "rclinit.h"
|
41 |
#include "indexer.h"
|
41 |
#include "indexer.h"
|
42 |
#include "smallut.h"
|
42 |
#include "smallut.h"
|
43 |
#include "chrono.h"
|
43 |
#include "chrono.h"
|
44 |
#include "pathut.h"
|
44 |
#include "pathut.h"
|
|
... |
|
... |
146 |
// If we are in the monitor, we also need to check X11 status
|
146 |
// If we are in the monitor, we also need to check X11 status
|
147 |
// during the initial indexing pass (else the user could log
|
147 |
// during the initial indexing pass (else the user could log
|
148 |
// out and the indexing would go on, not good (ie: if the user
|
148 |
// out and the indexing would go on, not good (ie: if the user
|
149 |
// logs in again, the new recollindex will fail).
|
149 |
// logs in again, the new recollindex will fail).
|
150 |
if ((op_flags & OPT_m) && !(op_flags & OPT_x) && !x11IsAlive()) {
|
150 |
if ((op_flags & OPT_m) && !(op_flags & OPT_x) && !x11IsAlive()) {
|
151 |
LOGDEB(("X11 session went away during initial indexing pass\n"));
|
151 |
LOGDEB("X11 session went away during initial indexing pass\n" );
|
152 |
stopindexing = true;
|
152 |
stopindexing = true;
|
153 |
return false;
|
153 |
return false;
|
154 |
}
|
154 |
}
|
155 |
#endif
|
155 |
#endif
|
156 |
return true;
|
156 |
return true;
|
|
... |
|
... |
164 |
static MyUpdater *updater;
|
164 |
static MyUpdater *updater;
|
165 |
|
165 |
|
166 |
static void sigcleanup(int sig)
|
166 |
static void sigcleanup(int sig)
|
167 |
{
|
167 |
{
|
168 |
fprintf(stderr, "Got signal, registering stop request\n");
|
168 |
fprintf(stderr, "Got signal, registering stop request\n");
|
169 |
LOGDEB(("Got signal, registering stop request\n"));
|
169 |
LOGDEB("Got signal, registering stop request\n" );
|
170 |
CancelCheck::instance().setCancel();
|
170 |
CancelCheck::instance().setCancel();
|
171 |
stopindexing = 1;
|
171 |
stopindexing = 1;
|
172 |
}
|
172 |
}
|
173 |
|
173 |
|
174 |
static void makeIndexerOrExit(RclConfig *config, bool inPlaceReset)
|
174 |
static void makeIndexerOrExit(RclConfig *config, bool inPlaceReset)
|
|
... |
|
... |
299 |
static bool checktopdirs(RclConfig *config, vector<string>& nonexist)
|
299 |
static bool checktopdirs(RclConfig *config, vector<string>& nonexist)
|
300 |
{
|
300 |
{
|
301 |
vector<string> tdl;
|
301 |
vector<string> tdl;
|
302 |
if (!config->getConfParam("topdirs", &tdl)) {
|
302 |
if (!config->getConfParam("topdirs", &tdl)) {
|
303 |
cerr << "No 'topdirs' parameter in configuration\n";
|
303 |
cerr << "No 'topdirs' parameter in configuration\n";
|
304 |
LOGERR(("recollindex:No 'topdirs' parameter in configuration\n"));;
|
304 |
LOGERR("recollindex:No 'topdirs' parameter in configuration\n" );;
|
305 |
return false;
|
305 |
return false;
|
306 |
}
|
306 |
}
|
307 |
|
307 |
|
308 |
for (vector<string>::iterator it = tdl.begin(); it != tdl.end(); it++) {
|
308 |
for (vector<string>::iterator it = tdl.begin(); it != tdl.end(); it++) {
|
309 |
*it = path_tildexpand(*it);
|
309 |
*it = path_tildexpand(*it);
|
310 |
if (!it->size() || !path_isabsolute(*it)) {
|
310 |
if (!it->size() || !path_isabsolute(*it)) {
|
311 |
if ((*it)[0] == '~') {
|
311 |
if ((*it)[0] == '~') {
|
312 |
cerr << "Tilde expansion failed: " << *it << endl;
|
312 |
cerr << "Tilde expansion failed: " << *it << endl;
|
313 |
LOGERR(("recollindex: tilde expansion failed: %s\n",
|
313 |
LOGERR("recollindex: tilde expansion failed: " << *it << "\n" );
|
314 |
it->c_str()));
|
|
|
315 |
} else {
|
314 |
} else {
|
316 |
cerr << "Not an absolute path: " << *it << endl;
|
315 |
cerr << "Not an absolute path: " << *it << endl;
|
317 |
LOGERR(("recollindex: not an absolute path: %s\n",
|
316 |
LOGERR("recollindex: not an absolute path: " << *it << "\n" );
|
318 |
it->c_str()));
|
|
|
319 |
}
|
317 |
}
|
320 |
return false;
|
318 |
return false;
|
321 |
}
|
319 |
}
|
322 |
if (!path_exists(*it)) {
|
320 |
if (!path_exists(*it)) {
|
323 |
nonexist.push_back(*it);
|
321 |
nonexist.push_back(*it);
|
|
... |
|
... |
514 |
}
|
512 |
}
|
515 |
|
513 |
|
516 |
string rundir;
|
514 |
string rundir;
|
517 |
config->getConfParam("idxrundir", rundir);
|
515 |
config->getConfParam("idxrundir", rundir);
|
518 |
if (!rundir.compare("tmp")) {
|
516 |
if (!rundir.compare("tmp")) {
|
519 |
LOGINFO(("recollindex: changing current directory to [%s]\n",
|
517 |
LOGINFO("recollindex: changing current directory to [" << (tmplocation()) << "]\n" );
|
520 |
tmplocation().c_str()));
|
|
|
521 |
if (chdir(tmplocation().c_str()) < 0) {
|
518 |
if (chdir(tmplocation().c_str()) < 0) {
|
522 |
LOGERR(("chdir(%s) failed, errno %d\n",
|
519 |
LOGERR("chdir(" << (tmplocation()) << ") failed, errno " << (errno) << "\n" );
|
523 |
tmplocation().c_str(), errno));
|
|
|
524 |
}
|
520 |
}
|
525 |
} else if (!rundir.empty()) {
|
521 |
} else if (!rundir.empty()) {
|
526 |
LOGINFO(("recollindex: changing current directory to [%s]\n",
|
522 |
LOGINFO("recollindex: changing current directory to [" << (rundir) << "]\n" );
|
527 |
rundir.c_str()));
|
|
|
528 |
if (chdir(rundir.c_str()) < 0) {
|
523 |
if (chdir(rundir.c_str()) < 0) {
|
529 |
LOGERR(("chdir(%s) failed, errno %d\n",
|
524 |
LOGERR("chdir(" << (rundir) << ") failed, errno " << (errno) << "\n" );
|
530 |
rundir.c_str(), errno));
|
|
|
531 |
}
|
525 |
}
|
532 |
}
|
526 |
}
|
533 |
|
527 |
|
534 |
bool rezero((op_flags & OPT_z) != 0);
|
528 |
bool rezero((op_flags & OPT_z) != 0);
|
535 |
bool inPlaceReset((op_flags & OPT_Z) != 0);
|
529 |
bool inPlaceReset((op_flags & OPT_Z) != 0);
|
|
... |
|
... |
548 |
Pidfile pidfile(config->getPidfile());
|
542 |
Pidfile pidfile(config->getPidfile());
|
549 |
updater = new MyUpdater(config);
|
543 |
updater = new MyUpdater(config);
|
550 |
|
544 |
|
551 |
// Log something at LOGINFO to reset the trace file. Else at level
|
545 |
// Log something at LOGINFO to reset the trace file. Else at level
|
552 |
// 3 it's not even truncated if all docs are up to date.
|
546 |
// 3 it's not even truncated if all docs are up to date.
|
553 |
LOGINFO(("recollindex: starting up\n"));
|
547 |
LOGINFO("recollindex: starting up\n" );
|
554 |
#ifndef _WIN32
|
548 |
#ifndef _WIN32
|
555 |
if (setpriority(PRIO_PROCESS, 0, 20) != 0) {
|
549 |
if (setpriority(PRIO_PROCESS, 0, 20) != 0) {
|
556 |
LOGINFO(("recollindex: can't setpriority(), errno %d\n", errno));
|
550 |
LOGINFO("recollindex: can't setpriority(), errno " << (errno) << "\n" );
|
557 |
}
|
551 |
}
|
558 |
// Try to ionice. This does not work on all platforms
|
552 |
// Try to ionice. This does not work on all platforms
|
559 |
rclIxIonice(config);
|
553 |
rclIxIonice(config);
|
560 |
#endif
|
554 |
#endif
|
561 |
|
555 |
|
|
... |
|
... |
623 |
} else if (op_flags & OPT_m) {
|
617 |
} else if (op_flags & OPT_m) {
|
624 |
if (argc != 0)
|
618 |
if (argc != 0)
|
625 |
Usage();
|
619 |
Usage();
|
626 |
lockorexit(&pidfile);
|
620 |
lockorexit(&pidfile);
|
627 |
if (!(op_flags&OPT_D)) {
|
621 |
if (!(op_flags&OPT_D)) {
|
628 |
LOGDEB(("recollindex: daemonizing\n"));
|
622 |
LOGDEB("recollindex: daemonizing\n" );
|
629 |
#ifndef _WIN32
|
623 |
#ifndef _WIN32
|
630 |
if (daemon(0,0) != 0) {
|
624 |
if (daemon(0,0) != 0) {
|
631 |
fprintf(stderr, "daemon() failed, errno %d\n", errno);
|
625 |
fprintf(stderr, "daemon() failed, errno %d\n", errno);
|
632 |
LOGERR(("daemon() failed, errno %d\n", errno));
|
626 |
LOGERR("daemon() failed, errno " << (errno) << "\n" );
|
633 |
exit(1);
|
627 |
exit(1);
|
634 |
}
|
628 |
}
|
635 |
#endif
|
629 |
#endif
|
636 |
}
|
630 |
}
|
637 |
// Need to rewrite pid, it changed
|
631 |
// Need to rewrite pid, it changed
|
638 |
pidfile.write_pid();
|
632 |
pidfile.write_pid();
|
639 |
#ifndef _WIN32
|
633 |
#ifndef _WIN32
|
640 |
// Not too sure if I have to redo the nice thing after daemon(),
|
634 |
// Not too sure if I have to redo the nice thing after daemon(),
|
641 |
// can't hurt anyway (easier than testing on all platforms...)
|
635 |
// can't hurt anyway (easier than testing on all platforms...)
|
642 |
if (setpriority(PRIO_PROCESS, 0, 20) != 0) {
|
636 |
if (setpriority(PRIO_PROCESS, 0, 20) != 0) {
|
643 |
LOGINFO(("recollindex: can't setpriority(), errno %d\n", errno));
|
637 |
LOGINFO("recollindex: can't setpriority(), errno " << (errno) << "\n" );
|
644 |
}
|
638 |
}
|
645 |
// Try to ionice. This does not work on all platforms
|
639 |
// Try to ionice. This does not work on all platforms
|
646 |
rclIxIonice(config);
|
640 |
rclIxIonice(config);
|
647 |
#endif
|
641 |
#endif
|
648 |
|
642 |
|
649 |
if (sleepsecs > 0) {
|
643 |
if (sleepsecs > 0) {
|
650 |
LOGDEB(("recollindex: sleeping %d\n", sleepsecs));
|
644 |
LOGDEB("recollindex: sleeping " << (sleepsecs) << "\n" );
|
651 |
for (int i = 0; i < sleepsecs; i++) {
|
645 |
for (int i = 0; i < sleepsecs; i++) {
|
652 |
sleep(1);
|
646 |
sleep(1);
|
653 |
// Check that x11 did not go away while we were sleeping.
|
647 |
// Check that x11 did not go away while we were sleeping.
|
654 |
if (!(op_flags & OPT_x) && !x11IsAlive()) {
|
648 |
if (!(op_flags & OPT_x) && !x11IsAlive()) {
|
655 |
LOGDEB(("X11 session went away during initial sleep period\n"));
|
649 |
LOGDEB("X11 session went away during initial sleep period\n" );
|
656 |
exit(0);
|
650 |
exit(0);
|
657 |
}
|
651 |
}
|
658 |
}
|
652 |
}
|
659 |
}
|
653 |
}
|
660 |
if (!(op_flags & OPT_n)) {
|
654 |
if (!(op_flags & OPT_n)) {
|
661 |
makeIndexerOrExit(config, inPlaceReset);
|
655 |
makeIndexerOrExit(config, inPlaceReset);
|
662 |
LOGDEB(("Recollindex: initial indexing pass before monitoring\n"));
|
656 |
LOGDEB("Recollindex: initial indexing pass before monitoring\n" );
|
663 |
if (!confindexer->index(rezero, ConfIndexer::IxTAll, indexerFlags)
|
657 |
if (!confindexer->index(rezero, ConfIndexer::IxTAll, indexerFlags)
|
664 |
|| stopindexing) {
|
658 |
|| stopindexing) {
|
665 |
LOGERR(("recollindex, initial indexing pass failed, "
|
659 |
LOGERR("recollindex, initial indexing pass failed, not going into monitor mode\n" );
|
666 |
"not going into monitor mode\n"));
|
|
|
667 |
exit(1);
|
660 |
exit(1);
|
668 |
} else {
|
661 |
} else {
|
669 |
// Record success of indexing pass with failed files retries.
|
662 |
// Record success of indexing pass with failed files retries.
|
670 |
if (!(indexerFlags & ConfIndexer::IxFNoRetryFailed)) {
|
663 |
if (!(indexerFlags & ConfIndexer::IxFNoRetryFailed)) {
|
671 |
checkRetryFailed(config, true);
|
664 |
checkRetryFailed(config, true);
|
672 |
}
|
665 |
}
|
673 |
}
|
666 |
}
|
674 |
deleteZ(confindexer);
|
667 |
deleteZ(confindexer);
|
675 |
#ifndef _WIN32
|
668 |
#ifndef _WIN32
|
676 |
o_reexec->insertArgs(vector<string>(1, "-n"));
|
669 |
o_reexec->insertArgs(vector<string>(1, "-n"));
|
677 |
LOGINFO(("recollindex: reexecuting with -n after initial full pass\n"));
|
670 |
LOGINFO("recollindex: reexecuting with -n after initial full pass\n" );
|
678 |
// Note that -n will be inside the reexec when we come
|
671 |
// Note that -n will be inside the reexec when we come
|
679 |
// back, but the monitor will explicitely strip it before
|
672 |
// back, but the monitor will explicitely strip it before
|
680 |
// starting a config change exec to ensure that we do a
|
673 |
// starting a config change exec to ensure that we do a
|
681 |
// purging pass in this case.
|
674 |
// purging pass in this case.
|
682 |
o_reexec->reexec();
|
675 |
o_reexec->reexec();
|
|
... |
|
... |
722 |
updater->update();
|
715 |
updater->update();
|
723 |
}
|
716 |
}
|
724 |
return !status;
|
717 |
return !status;
|
725 |
}
|
718 |
}
|
726 |
}
|
719 |
}
|
|
|
720 |
|