forked from openkylin/ukui-search
Adjust the logic between parent and child processes, named pipes to be added.
This commit is contained in:
parent
452896a354
commit
501e252bf7
|
@ -2,24 +2,6 @@
|
|||
#include "first-index.h"
|
||||
#include <QDebug>
|
||||
|
||||
void handler(int){
|
||||
qDebug() << "Recieved SIGTERM!";
|
||||
GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "2");
|
||||
GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "2");
|
||||
GlobalSettings::getInstance()->setValue(INDEX_GENERATOR_NORMAL_EXIT, "2");
|
||||
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "2");
|
||||
|
||||
|
||||
qDebug() << "indexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
|
||||
qDebug() << "contentIndexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString();
|
||||
|
||||
// InotifyIndex::getInstance("/home")->~InotifyIndex();
|
||||
qDebug() << "~IndexGenerator() end!" << endl;
|
||||
|
||||
//wait linux kill this thread forcedly
|
||||
// while (true);
|
||||
}
|
||||
|
||||
#define NEW_QUEUE(a) a = new QQueue<QString>(); qDebug("---------------------------%s %s %s new at %d..",__FILE__,__FUNCTION__,#a,__LINE__);
|
||||
//#define DELETE_QUEUE(a )
|
||||
|
||||
|
@ -94,11 +76,11 @@ void FirstIndex::run(){
|
|||
else{
|
||||
//if the parameter is false, index won't be rebuild
|
||||
//if it is true, index will be rebuild
|
||||
this->p_indexGenerator = IndexGenerator::getInstance(true,this);
|
||||
p_indexGenerator = IndexGenerator::getInstance(true,this);
|
||||
}
|
||||
}
|
||||
else{
|
||||
this->p_indexGenerator = IndexGenerator::getInstance(false,this);
|
||||
p_indexGenerator = IndexGenerator::getInstance(false,this);
|
||||
}
|
||||
|
||||
// this->q_content_index->enqueue(QString("/home/zhangzihao/Desktop/qwerty/四库全书.txt"));
|
||||
|
@ -110,6 +92,7 @@ void FirstIndex::run(){
|
|||
pid = fork();
|
||||
if(pid == 0)
|
||||
{
|
||||
prctl(PR_SET_PDEATHSIG, SIGKILL);
|
||||
prctl(PR_SET_NAME,"first-index");
|
||||
FileUtils::_index_status = CREATING_INDEX;
|
||||
QSemaphore sem(5);
|
||||
|
@ -166,9 +149,9 @@ void FirstIndex::run(){
|
|||
if (this->q_content_index)
|
||||
delete this->q_content_index;
|
||||
this->q_content_index = nullptr;
|
||||
if (this->p_indexGenerator)
|
||||
delete this->p_indexGenerator;
|
||||
this->p_indexGenerator = nullptr;
|
||||
if (p_indexGenerator)
|
||||
delete p_indexGenerator;
|
||||
p_indexGenerator = nullptr;
|
||||
|
||||
QThreadPool::globalInstance()->releaseThread();
|
||||
QThreadPool::globalInstance()->waitForDone();
|
||||
|
@ -183,9 +166,6 @@ void FirstIndex::run(){
|
|||
}
|
||||
|
||||
FileUtils::_index_status = FINISH_CREATING_INDEX;
|
||||
qDebug() << "sigset start!";
|
||||
sigset( SIGTERM, handler);
|
||||
qDebug() << "sigset end!";
|
||||
|
||||
//quit() is shit!!!
|
||||
// return;
|
||||
|
|
|
@ -1,5 +1,23 @@
|
|||
#include "inotify-index.h"
|
||||
|
||||
void handler(int){
|
||||
qDebug() << "Recieved SIGTERM!";
|
||||
GlobalSettings::getInstance()->setValue(INDEX_DATABASE_STATE, "2");
|
||||
GlobalSettings::getInstance()->setValue(CONTENT_INDEX_DATABASE_STATE, "2");
|
||||
GlobalSettings::getInstance()->setValue(INDEX_GENERATOR_NORMAL_EXIT, "2");
|
||||
GlobalSettings::getInstance()->setValue(INOTIFY_NORMAL_EXIT, "2");
|
||||
|
||||
|
||||
qDebug() << "indexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(INDEX_DATABASE_STATE).toString();
|
||||
qDebug() << "contentIndexDataBaseStatus: " << GlobalSettings::getInstance()->getValue(CONTENT_INDEX_DATABASE_STATE).toString();
|
||||
_exit(0);
|
||||
|
||||
// InotifyIndex::getInstance("/home")->~InotifyIndex();
|
||||
|
||||
//wait linux kill this thread forcedly
|
||||
// while (true);
|
||||
}
|
||||
|
||||
InotifyIndex::InotifyIndex(const QString& path) : Traverse_BFS(path)
|
||||
{
|
||||
/*-------------ukuisearchdbus Test start-----------------*/
|
||||
|
@ -111,7 +129,7 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp){
|
|||
if (event->mask & IN_CREATE){
|
||||
if (event->mask & IN_ISDIR){
|
||||
AddWatch(currentPath[event->wd] + '/' + event->name);
|
||||
this->setPath(currentPath[event->wd] + '/' + event->name);
|
||||
setPath(currentPath[event->wd] + '/' + event->name);
|
||||
Traverse();
|
||||
}
|
||||
|
||||
|
@ -166,7 +184,7 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp){
|
|||
RemoveWatch(currentPath[event->wd] + '/' + event->name);
|
||||
IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));
|
||||
AddWatch(currentPath[event->wd] + '/' + event->name);
|
||||
this->setPath(currentPath[event->wd] + '/' + event->name);
|
||||
setPath(currentPath[event->wd] + '/' + event->name);
|
||||
Traverse();
|
||||
|
||||
indexQueue->enqueue(QVector<QString>() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0"));
|
||||
|
@ -266,6 +284,10 @@ next:
|
|||
*/
|
||||
|
||||
void InotifyIndex::run(){
|
||||
qDebug() << "sigset start!";
|
||||
sigset( SIGTERM, handler);
|
||||
qDebug() << "sigset end!";
|
||||
|
||||
char buf[BUF_LEN] __attribute__((aligned(8)));
|
||||
|
||||
ssize_t numRead;
|
||||
|
@ -278,6 +300,7 @@ void InotifyIndex::run(){
|
|||
pid = fork();
|
||||
if(pid == 0)
|
||||
{
|
||||
prctl(PR_SET_PDEATHSIG, SIGKILL);
|
||||
prctl(PR_SET_NAME,"inotify-index");
|
||||
if (numRead == 0) {
|
||||
qDebug() << "read() from inotify fd returned 0!";
|
||||
|
@ -286,19 +309,20 @@ void InotifyIndex::run(){
|
|||
qDebug() << "read";
|
||||
}
|
||||
eventProcess(buf, numRead);
|
||||
QTimer* liveTime = new QTimer(this);
|
||||
bool b_timeout = false;
|
||||
liveTime->setInterval(30000);
|
||||
connect(liveTime, &QTimer::timeout, this, [&](){
|
||||
// _exit(0);
|
||||
b_timeout = true;
|
||||
});
|
||||
QTimer* liveTime = new QTimer();
|
||||
//restart inotify-index proccess per minute
|
||||
liveTime->setInterval(60000);
|
||||
liveTime->start();
|
||||
|
||||
// connect(liveTime, &QTimer::timeout, [ = ](){
|
||||
//// _exit(0);
|
||||
// *b_timeout = 1;
|
||||
// });
|
||||
for (;;){
|
||||
numRead = read(m_fd, buf, BUF_LEN);
|
||||
liveTime->stop();
|
||||
this->eventProcess(buf, numRead);
|
||||
if (b_timeout){
|
||||
if (liveTime->remainingTime() < 1){
|
||||
_exit(0);
|
||||
}
|
||||
liveTime->start();
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "file-utils.h"
|
||||
#include "first-index.h"
|
||||
|
||||
#define BUF_LEN 1024
|
||||
#define BUF_LEN 1024000
|
||||
class InotifyIndex;
|
||||
static InotifyIndex* global_instance_of_index = nullptr;
|
||||
class InotifyIndex : public QThread, public Traverse_BFS
|
||||
|
|
|
@ -10,6 +10,7 @@ class Traverse_BFS
|
|||
{
|
||||
public:
|
||||
void Traverse();
|
||||
virtual ~Traverse_BFS() = default;
|
||||
virtual void DoSomething(const QFileInfo&) = 0;
|
||||
void setPath(const QString&);
|
||||
protected:
|
||||
|
|
|
@ -186,7 +186,7 @@ int main(int argc, char *argv[])
|
|||
// FirstIndex* fi = new FirstIndex("/home/zhangzihao/Desktop/qwerty");
|
||||
FirstIndex fi("/home");
|
||||
fi.start();
|
||||
fi.wait();
|
||||
// fi.wait();
|
||||
// fi->wait();
|
||||
// fi->exit();
|
||||
// delete fi;
|
||||
|
|
Loading…
Reference in New Issue