Add named pipe to control the order of two child process.

This commit is contained in:
zhangzihao 2021-01-22 09:49:44 +08:00
parent 501e252bf7
commit add5b7bb46
6 changed files with 73 additions and 3 deletions

View File

@ -11,6 +11,8 @@
#include <QMimeType> #include <QMimeType>
#include <QQueue> #include <QQueue>
#include "uchardet/uchardet.h" #include "uchardet/uchardet.h"
size_t FileUtils::_max_index_count = 0; size_t FileUtils::_max_index_count = 0;
size_t FileUtils::_current_index_count = 0; size_t FileUtils::_current_index_count = 0;
unsigned short FileUtils::_index_status = INITIAL_STATE; unsigned short FileUtils::_index_status = INITIAL_STATE;

View File

@ -1,6 +1,12 @@
#ifndef FILEUTILS_H #ifndef FILEUTILS_H
#define FILEUTILS_H #define FILEUTILS_H
#include "gobject-template.h" #include "gobject-template.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <QString> #include <QString>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QIcon> #include <QIcon>
@ -10,6 +16,8 @@
#define CREATING_INDEX 1 #define CREATING_INDEX 1
#define FINISH_CREATING_INDEX 2 #define FINISH_CREATING_INDEX 2
#define UKUI_SEARCH_PIPE_PATH "/tmp/ukuisearch"
class LIBSEARCH_EXPORT FileUtils class LIBSEARCH_EXPORT FileUtils
{ {

View File

@ -2,7 +2,7 @@
#include "first-index.h" #include "first-index.h"
#include <QDebug> #include <QDebug>
#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 )
FirstIndex::FirstIndex(const QString& path) : Traverse_BFS(path) FirstIndex::FirstIndex(const QString& path) : Traverse_BFS(path)
@ -63,6 +63,18 @@ void FirstIndex::DoSomething(const QFileInfo& fileInfo){
} }
void FirstIndex::run(){ void FirstIndex::run(){
int fifo_fd;
char buffer[2];
memset(buffer, 0, sizeof(buffer));
buffer[0] = 0x1;
buffer[1] = '\0';
fifo_fd = open(UKUI_SEARCH_PIPE_PATH, O_RDWR);
if(fifo_fd == -1)
{
perror("open fifo error\n");
assert(false);
}
if (this->bool_dataBaseExist){ if (this->bool_dataBaseExist){
if (this->bool_dataBaseStatusOK){ if (this->bool_dataBaseStatusOK){
@ -165,6 +177,14 @@ void FirstIndex::run(){
waitpid(pid,NULL,0); waitpid(pid,NULL,0);
} }
int retval = write(fifo_fd, buffer, strlen(buffer));
if(retval == -1)
{
perror("write error\n");
}
printf("write data ok!\n");
close(fifo_fd);
FileUtils::_index_status = FINISH_CREATING_INDEX; FileUtils::_index_status = FINISH_CREATING_INDEX;
//quit() is shit!!! //quit() is shit!!!

View File

@ -6,7 +6,12 @@
#include <signal.h> #include <signal.h>
#include <QSemaphore> #include <QSemaphore>
#include<sys/types.h> #include<sys/types.h>
#include<unistd.h> #include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/prctl.h> #include <sys/prctl.h>
//#include <QtConcurrent> //#include <QtConcurrent>

View File

@ -284,6 +284,30 @@ next:
*/ */
void InotifyIndex::run(){ void InotifyIndex::run(){
int fifo_fd;
char buffer[2];
memset(buffer, 0, sizeof(buffer));
fifo_fd = open(UKUI_SEARCH_PIPE_PATH, O_RDWR);
if(fifo_fd == -1)
{
perror("open fifo error\n");
assert(false);
}
int retval = read(fifo_fd, buffer, sizeof(buffer));
if(retval == -1)
{
perror("read error\n");
assert(false);
}
printf("read fifo=[%s]\n", buffer);
printf("read data ok\n");
close(fifo_fd);
if (buffer[0] & 0x1){
printf("data confirmed\n");
}
unlink(UKUI_SEARCH_PIPE_PATH);
qDebug() << "sigset start!"; qDebug() << "sigset start!";
sigset( SIGTERM, handler); sigset( SIGTERM, handler);
qDebug() << "sigset end!"; qDebug() << "sigset end!";

View File

@ -26,7 +26,6 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <syslog.h> #include <syslog.h>
#include <QObject> #include <QObject>
#include <QSemaphore>
#include "qt-single-application.h" #include "qt-single-application.h"
#include "qt-local-peer.h" #include "qt-local-peer.h"
//#include "inotify-manager.h" //#include "inotify-manager.h"
@ -34,6 +33,7 @@
#include "global-settings.h" #include "global-settings.h"
#include "xatom-helper.h" #include "xatom-helper.h"
void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{ {
QByteArray localMsg = msg.toLocal8Bit(); QByteArray localMsg = msg.toLocal8Bit();
@ -92,6 +92,17 @@ void centerToScreen(QWidget* widget) {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
unlink(UKUI_SEARCH_PIPE_PATH);
int retval = mkfifo(UKUI_SEARCH_PIPE_PATH, 0777);
if(retval == -1)
{
perror("creat fifo error\n");
assert(false);
return -1;
}
printf("create fifo success\n");
qInstallMessageHandler(messageOutput); qInstallMessageHandler(messageOutput);
qRegisterMetaType<QPair<QString,QStringList>>("QPair<QString,QStringList>"); qRegisterMetaType<QPair<QString,QStringList>>("QPair<QString,QStringList>");
qRegisterMetaType<Document>("Document"); qRegisterMetaType<Document>("Document");