ipc: Place socket in /tmp/.looqs/, remove ipc path settings

This commit is contained in:
Albert S. 2022-05-29 09:50:47 +02:00
parent e44fb1a942
commit ad0fc74439
2 changed files with 26 additions and 6 deletions

View File

@ -5,6 +5,7 @@
#include <QProcess> #include <QProcess>
#include <QDir> #include <QDir>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QFileInfo>
#include "mainwindow.h" #include "mainwindow.h"
#include "searchresult.h" #include "searchresult.h"
@ -33,7 +34,7 @@ void enableSandbox()
exile_free_policy(policy); exile_free_policy(policy);
} }
void enableIpcSandbox(QString socketPath) void enableIpcSandbox()
{ {
struct exile_policy *policy = exile_create_policy(); struct exile_policy *policy = exile_create_policy();
if(policy == NULL) if(policy == NULL)
@ -46,8 +47,13 @@ void enableIpcSandbox(QString socketPath)
policy->drop_caps = 1; policy->drop_caps = 1;
policy->vow_promises = exile_vows_from_str("thread cpath wpath rpath unix stdio prot_exec proc shm fsnotify ioctl"); policy->vow_promises = exile_vows_from_str("thread cpath wpath rpath unix stdio prot_exec proc shm fsnotify ioctl");
QString ipcSocketPath = Common::ipcSocketPath();
QFileInfo info{ipcSocketPath};
QString ipcSocketPathDir = info.absolutePath();
std::string stdIpcSocketPath = ipcSocketPathDir.toStdString();
exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ, "/"); exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ, "/");
exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE, "/tmp"); exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE, stdIpcSocketPath.c_str());
int ret = exile_enable_policy(policy); int ret = exile_enable_policy(policy);
if(ret != 0) if(ret != 0)
{ {
@ -59,14 +65,14 @@ void enableIpcSandbox(QString socketPath)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QString socketPath = "/tmp/looqs-spawner"; QString socketPath = Common::ipcSocketPath();
if(argc > 1) if(argc > 1)
{ {
QString arg = argv[1]; QString arg = argv[1];
if(arg == "ipc") if(arg == "ipc")
{ {
Common::setupAppInfo(); Common::setupAppInfo();
enableIpcSandbox(socketPath); enableIpcSandbox();
QApplication a(argc, argv); QApplication a(argc, argv);
IpcServer *ipcserver = new IpcServer(); IpcServer *ipcserver = new IpcServer();
@ -96,6 +102,17 @@ int main(int argc, char *argv[])
return processor.process(); return processor.process();
} }
} }
QString ipcSocketPath = Common::ipcSocketPath();
QFileInfo info{ipcSocketPath};
QString ipcSocketPathDir = info.absolutePath();
QDir dir;
if(!dir.mkpath(ipcSocketPathDir))
{
qCritical() << "Failed to create dir for ipc socket" << Qt::endl;
exit(EXIT_FAILURE);
}
QProcess process; QProcess process;
QStringList args; QStringList args;
args << "ipc"; args << "ipc";

View File

@ -156,6 +156,9 @@ QString Common::databasePath()
QString Common::ipcSocketPath() QString Common::ipcSocketPath()
{ {
QSettings settings; return "/tmp/.looqs/looqs-ipc-socket";
return settings.value(SETTINGS_KEY_IPCSOCKETPATH, "/tmp/looqs-spawner").toString();
/* May not a good idea to set it in the settings and probably nobody would ever bother to change it anyway */
// QSettings settings;
// return settings.value(SETTINGS_KEY_IPCSOCKETPATH, "/tmp/.looqs/looqs-ipc-socket").toString();
} }