~ubuntu-branches/ubuntu/quantal/recoll/quantal

« back to all changes in this revision

Viewing changes to index/recollindex.cpp

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2012-03-27 12:15:51 UTC
  • mfrom: (1.3.8)
  • Revision ID: package-import@ubuntu.com-20120327121551-nmntidzpehudushy
Tags: 1.17.1-1
* New upstream release.
* Enable Python module resulting into new binary: python-recoll.
* debian/control:
  + Updated Build-Deps: libqtwebkit-dev, python-all-dev.
  + Added python-recoll binary.
  + Updated Standards-Version to 3.9.3
* debian/rules:
  + Build Python module by default.
* debian/recoll.menu, debian/python-recoll.install, debian/recoll.install:
  + Changes for new binary package.
* debian/copyright:
  + Updated to copyright-format 1.0
  + Updated upstream and Debian copyright.
  + Fixed unicode.org/copyright.html URL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <errno.h>
24
24
#include <sys/time.h>
25
25
#include <sys/resource.h>
 
26
#include <fcntl.h>
26
27
 
27
28
#include <iostream>
28
29
#include <list>
44
45
#include "recollindex.h"
45
46
#include "fsindexer.h"
46
47
#include "rclionice.h"
 
48
#include "execmd.h"
47
49
 
48
50
// Command line options
49
51
static int     op_flags;
62
64
#define OPT_l     0x1000
63
65
#define OPT_b     0x2000
64
66
#define OPT_f     0x4000
 
67
#define OPT_C     0x8000
 
68
 
 
69
ReExec *o_reexec;
65
70
 
66
71
// Globals for atexit cleanup
67
72
static ConfIndexer *confindexer;
76
81
// indexing routines.
77
82
int stopindexing;
78
83
 
79
 
// Mainly used to request indexing stop, we currently do not use the
80
 
// current file name
 
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 {
82
88
 public:
83
 
    virtual bool update() {
 
89
    MyUpdater(RclConfig *config) 
 
90
        : m_prevphase(DbIxStatus::DBIXS_NONE)
 
91
    {
 
92
        m_fd = open(config->getIdxStatusFile().c_str(), 
 
93
                    O_WRONLY|O_CREAT|O_TRUNC, 0600);
 
94
        if (m_fd < 0)
 
95
            LOGERR(("Can't open/create status file: [%s]\n",
 
96
                    config->getIdxStatusFile().c_str()));
 
97
    }
 
98
 
 
99
    virtual bool update() 
 
100
    {
 
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;
 
104
            m_chron.restart();
 
105
            lseek(m_fd, 0, 0);
 
106
            int fd1 = dup(m_fd);
 
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
 
115
            fclose(fp); 
 
116
        }
 
117
 
84
118
        if (stopindexing) {
85
119
            return false;
86
120
        }
87
121
 
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"));
94
 
          stopindexing = true;
95
 
          return false;
 
127
            LOGDEB(("X11 session went away during initial indexing pass\n"));
 
128
            stopindexing = true;
 
129
            return false;
96
130
        }
97
131
 
98
132
        return true;
99
133
    }
 
134
 
 
135
private:
 
136
    int    m_fd;
 
137
    Chrono m_chron;
 
138
    DbIxStatus::Phase m_prevphase;
100
139
};
101
 
static MyUpdater updater;
 
140
static MyUpdater *updater;
102
141
 
103
142
static void sigcleanup(int sig)
104
143
{
111
150
static bool makeIndexer(RclConfig *config)
112
151
{
113
152
    if (!confindexer)
114
 
        confindexer = new ConfIndexer(config, &updater);
 
153
        confindexer = new ConfIndexer(config, updater);
115
154
    if (!confindexer) {
116
155
        cerr << "Cannot create indexer" << endl;
117
156
        exit(1);
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 */
236
276
    }
237
277
}
238
278
 
239
 
int main(int argc, const char **argv)
 
279
int main(int argc, char **argv)
240
280
{
241
281
    string a_config;
242
282
    int sleepsecs = 60;
 
283
    o_reexec = new ReExec;
 
284
    o_reexec->init(argc, argv);
243
285
 
244
286
    thisprog = argv[0];
245
287
    argc--; argv++;
255
297
                a_config = *(++argv);
256
298
                argc--; goto b1;
257
299
#ifdef RCL_MONITOR
 
300
            case 'C': op_flags |= OPT_C; break;
258
301
            case 'D': op_flags |= OPT_D; break;
259
302
#endif
260
303
            case 'e': op_flags |= OPT_e; break;
298
341
        cerr << "Configuration problem: " << reason << endl;
299
342
        exit(1);
300
343
    }
 
344
    o_reexec->atexit(cleanup);
 
345
 
301
346
    bool rezero(op_flags & OPT_z);
302
347
    Pidfile pidfile(config->getPidfile());
 
348
    updater = new MyUpdater(config);
303
349
 
304
350
    if (setpriority(PRIO_PROCESS, 0, 20) != 0) {
305
351
        LOGINFO(("recollindex: can't setpriority(), errno %d\n", errno));
383
429
              }
384
430
            }
385
431
        }
386
 
 
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"));
390
435
          exit(1);
391
436
        }
 
437
        if (updater) {
 
438
            updater->status.phase = DbIxStatus::DBIXS_MONITOR;
 
439
            updater->status.fn.clear();
 
440
            updater->update();
 
441
        }
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);
412
464
    } else {
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);
417
469
        if (!status) 
418
470
            cerr << "Indexing failed" << endl;
419
471
        if (!confindexer->getReason().empty())
420
472
            cerr << confindexer->getReason() << endl;
 
473
 
 
474
        if (updater) {
 
475
            updater->status.phase = DbIxStatus::DBIXS_DONE;
 
476
            updater->status.fn.clear();
 
477
            updater->update();
 
478
        }
421
479
        return !status;
422
480
    }
423
481
}
424