Merge branch '0621-dev' into 'dev-unity'

Add a systembus iface for add inotify_max_user_instance, avoid inotify_init fail.

See merge request kylin-desktop/ukui-search!50
This commit is contained in:
PengfeiZhang 2021-06-30 03:08:33 +00:00
commit edfe1a0d4b
6 changed files with 56 additions and 5 deletions

View File

@ -129,6 +129,13 @@ void InotifyWatch::stopWatch()
void InotifyWatch::run() void InotifyWatch::run()
{ {
m_inotifyFd = inotify_init();
if (m_inotifyFd > 0) {
qDebug()<<"Inotify init success!";
} else {
qWarning() << "Inotify init fail! Now try add inotify_user_instances.";
UkuiSearchQDBus usQDBus;
usQDBus.addInotifyUserInstances(128);
m_inotifyFd = inotify_init(); m_inotifyFd = inotify_init();
if (m_inotifyFd > 0) { if (m_inotifyFd > 0) {
qDebug()<<"Inotify init success!"; qDebug()<<"Inotify init success!";
@ -137,6 +144,7 @@ void InotifyWatch::run()
printf("Mesg:%s\n",strerror(errno)); printf("Mesg:%s\n",strerror(errno));
Q_ASSERT_X(0, "InotifyWatch", "Failed to initialize inotify"); Q_ASSERT_X(0, "InotifyWatch", "Failed to initialize inotify");
} }
}
this->addWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); this->addWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
this->setPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); this->setPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));

View File

@ -42,5 +42,15 @@ void UkuiSearchQDBus::setInotifyMaxUserWatches() {
// sysctl // sysctl
this->tmpSystemQDBusInterface->call("setInotifyMaxUserWatchesStep2"); this->tmpSystemQDBusInterface->call("setInotifyMaxUserWatchesStep2");
// /etc/sysctl.conf // /etc/sysctl.conf
// this->tmpSystemQDBusInterface->call("setInotifyMaxUserWatchesStep3"); // this->tmpSystemQDBusInterface->call("setInotifyMaxUserWatchesStep3");
}
int UkuiSearchQDBus::addInotifyUserInstances(int addNum)
{
QDBusReply<int> reply = tmpSystemQDBusInterface->call("AddInotifyMaxUserInstance", addNum);
if(reply.isValid()) {
qDebug() << "Set inotify_max_user_instances to" << reply.value();
} else {
qWarning() << "Call AddInotifyMaxUserInstance failed!";
}
} }

View File

@ -21,12 +21,14 @@
#define UKUISEARCHQDBUS_H #define UKUISEARCHQDBUS_H
#include <QDBusInterface> #include <QDBusInterface>
#include <QDBusReply>
namespace Zeeker { namespace Zeeker {
class UkuiSearchQDBus { class UkuiSearchQDBus {
public: public:
UkuiSearchQDBus(); UkuiSearchQDBus();
~UkuiSearchQDBus(); ~UkuiSearchQDBus();
void setInotifyMaxUserWatches(); void setInotifyMaxUserWatches();
int addInotifyUserInstances(int addNum);
private: private:
QDBusInterface* tmpSystemQDBusInterface; QDBusInterface* tmpSystemQDBusInterface;
}; };

View File

@ -730,7 +730,7 @@ void ContentWidget::onListViewRowChanged(SearchListView * listview, const int &t
if(type == SearchItem::SearchType::Contents && !m_contentDetailList.isEmpty()) { if(type == SearchItem::SearchType::Contents && !m_contentDetailList.isEmpty()) {
m_detailView->isContent = true; m_detailView->isContent = true;
m_detailView->setContent(m_contentDetailList.at(listview->currentIndex().row()), m_keyword); m_detailView->setContent(m_contentDetailList.at(listview->currentIndex().row()), m_keyword);
} else if(type == SearchItem::SearchType::Best && !m_bestContent.isEmpty() && listview->currentIndex().row() == listview->getLength() - 1) { } else if(type == SearchItem::SearchType::Best && !m_bestContent.isEmpty() && SearchItem::SearchType::Contents == m_bestList.at(listview->currentIndex().row()).first) {
m_detailView->setContent(m_bestContent, m_keyword); m_detailView->setContent(m_bestContent, m_keyword);
m_detailView->isContent = true; m_detailView->isContent = true;
m_detailView->setupWidget(SearchItem::SearchType::Contents, path); m_detailView->setupWidget(SearchItem::SearchType::Contents, path);

View File

@ -102,6 +102,36 @@ QString SysdbusRegister::setInotifyMaxUserWatchesStep3() {
return QString(ba); return QString(ba);
} }
int SysdbusRegister::AddInotifyMaxUserInstance(int addNum)
{
QFile file("/proc/sys/fs/inotify/max_user_instances");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
return -1;
QTextStream ts(&file);
QString s = ts.read(512);
int instances = s.toInt() + addNum;
QByteArray ba;
FILE * fp = NULL;
char cmd[128];
char buf[1024];
sprintf(cmd, "sysctl -w fs.inotify.max_user_instances=\"%d\"", instances);
if((fp = popen(cmd, "r")) != NULL) {
rewind(fp);
while(!feof(fp)) {
fgets(buf, sizeof(buf), fp);
ba.append(buf);
}
pclose(fp);
fp = NULL;
} else {
qWarning() << "popen open failed";
return -1;
}
return instances;
}
//The following example comes from control center //The following example comes from control center
//void SysdbusRegister::setAutoLoginStatus(QString username) { //void SysdbusRegister::setAutoLoginStatus(QString username) {

View File

@ -52,6 +52,7 @@ public slots:
Q_SCRIPTABLE QString setInotifyMaxUserWatchesStep1(); Q_SCRIPTABLE QString setInotifyMaxUserWatchesStep1();
Q_SCRIPTABLE QString setInotifyMaxUserWatchesStep2(); Q_SCRIPTABLE QString setInotifyMaxUserWatchesStep2();
Q_SCRIPTABLE QString setInotifyMaxUserWatchesStep3(); Q_SCRIPTABLE QString setInotifyMaxUserWatchesStep3();
Q_SCRIPTABLE int AddInotifyMaxUserInstance(int addNum);
// // 设置免密登录状态 // // 设置免密登录状态
// Q_SCRIPTABLE void setNoPwdLoginStatus(); // Q_SCRIPTABLE void setNoPwdLoginStatus();