Skip to content

Commit

Permalink
Merge branch 'jb52254_socket_address' into 'master'
Browse files Browse the repository at this point in the history
Use non-abstract unix domain socket

See merge request mer-core/maliit-framework!13
  • Loading branch information
spiiroin committed Apr 9, 2021
2 parents 867eb69 + 9ce24f8 commit 3d2ed14
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions maliit-framework/connection/serverdbusaddress.cpp
@@ -1,7 +1,8 @@
/* * This file is part of Maliit framework *
*
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* Copyright (c) 2021 Jolla Ltd.
*
* Contact: maliit-discuss@lists.maliit.org
*
Expand All @@ -18,9 +19,14 @@
#include <QDBusConnection>

#include <QDBusServer>
#include <QDir>

#include <cstdlib>

#include <sys/stat.h>

#include <unistd.h>

namespace {
const char * const MaliitServerName = "org.maliit.server";
const char * const MaliitServerObjectPath = "/org/maliit/server/address";
Expand Down Expand Up @@ -62,12 +68,33 @@ DynamicAddress::DynamicAddress()

QDBusServer* DynamicAddress::connect()
{
QLatin1String dbusAddress("unix:tmpdir=/tmp/maliit-server");

QDBusServer *server = new QDBusServer(dbusAddress);

publisher.reset(new AddressPublisher(server->address()));

QDBusServer *server = nullptr;
char *runDir = nullptr;
char *socketDir = nullptr;
char *socketFile = nullptr;
const char *env = getenv("XDG_RUNTIME_DIR");
if (env && *env == '/' && QDir(QString::fromUtf8(env)).exists())
runDir = strdup(env);
else if (asprintf(&runDir, "/run/user/%d", static_cast<int>(getuid())) < 0)
runDir = nullptr;
if (!runDir) {
qWarning("Could not determine XDG_RUNTIME_DIR");
} else if (asprintf(&socketDir, "%s/maliit-server", runDir) < 0) {
socketDir = nullptr;
} else if (asprintf(&socketFile, "%s/dbus-socket", socketDir) < 0) {
socketFile = nullptr;
} else if (mkdir(socketDir, 0770) == -1 && errno != EEXIST) {
qWarning("Failed to create %s: %s", socketDir, strerror(errno));
} else if (unlink(socketFile) == -1 && errno != ENOENT) {
qWarning("Failed to remove %s: %s", socketFile, strerror(errno));
} else {
QString dbusAddress(QStringLiteral("unix:path=%1").arg(socketFile));
server = new QDBusServer(dbusAddress);
publisher.reset(new AddressPublisher(server->address()));
}
free(socketFile);
free(socketDir);
free(runDir);
return server;
}

Expand Down

0 comments on commit 3d2ed14

Please sign in to comment.