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