File indexing completed on 2024-04-28 03:51:40
0001 /* 0002 This file is part of the KDE Baloo Project 0003 SPDX-FileCopyrightText: 2023 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #include <KCrash> 0009 #include <QCoreApplication> 0010 #include <QFile> 0011 #include <QSocketNotifier> 0012 #include <QTimer> 0013 0014 #include "baloodebug.h" 0015 #include "extractor/commandpipe.h" 0016 0017 #include <signal.h> 0018 #include <sys/resource.h> 0019 #include <unistd.h> //for STDIN_FILENO 0020 0021 int main(int argc, char* argv[]) 0022 { 0023 using Baloo::Private::WorkerPipe; 0024 0025 // Disable writing core dumps, we may crash on purpose 0026 struct rlimit corelimit{0, 0}; 0027 setrlimit(RLIMIT_CORE, &corelimit); 0028 // DrKonqi blocks the signal and causes timeout of the QSignalSpy 0029 KCrash::setDrKonqiEnabled(false); 0030 QCoreApplication app(argc, argv); 0031 0032 QFile input; 0033 input.open(STDIN_FILENO, QIODevice::ReadOnly | QIODevice::Unbuffered); 0034 QSocketNotifier inputNotifier(STDIN_FILENO, QSocketNotifier::Read); 0035 0036 QFile output; 0037 output.open(STDOUT_FILENO, QIODevice::WriteOnly | QIODevice::Unbuffered); 0038 0039 WorkerPipe worker(&input, &output); 0040 QObject::connect(&inputNotifier, &QSocketNotifier::activated, 0041 &worker, &WorkerPipe::processIdData); 0042 0043 QObject::connect(&worker, &WorkerPipe::inputEnd, &QCoreApplication::quit); 0044 QObject::connect(&worker, &WorkerPipe::newDocumentIds, 0045 [&worker](const QVector<quint64>& ids) { 0046 QTimer::singleShot(0, [&worker, ids]() { 0047 qCInfo(BALOO) << "Processing ..."; 0048 0049 for(auto id : ids) { 0050 worker.urlStarted(QString::number(id)); 0051 0052 if (id == 0) { 0053 raise(SIGSEGV); 0054 } else if (id == 1) { 0055 exit(1); 0056 } else if (id == 2) { 0057 exit(2); 0058 } else if (id < 100) { 0059 worker.urlFailed(QString::number(id)); 0060 } else { 0061 worker.urlFinished(QString::number(id)); 0062 } 0063 } 0064 worker.batchFinished(); 0065 qCInfo(BALOO) << "Processing done"; 0066 }); 0067 }); 0068 0069 return app.exec(); 0070 }