-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Move Mumble Socket and Overlay to $XDG_RUNTIME_DIR/mumble/ #5961
base: master
Are you sure you want to change the base?
Changes from all commits
15936a9
7212c49
aa15c61
bb6b2de
04bc3af
98fab94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2022 The Mumble Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file at the root of the | ||
// Mumble source tree or at <https://www.mumble.info/LICENSE>. | ||
|
||
#include "ipc_utils.h" | ||
// #include <cwalk.h> | ||
#include <string.h> | ||
|
||
#ifdef _WIN32 | ||
# include <direct.h> | ||
# include <stdlib.h> | ||
# include <malloc.h> | ||
#else | ||
# include <pwd.h> | ||
# include <stdio.h> | ||
# include <stdlib.h> | ||
# include <sys/stat.h> | ||
# include <sys/types.h> | ||
# include <unistd.h> | ||
#endif | ||
|
||
// can't trust POSIX's nor Window's PATH_MAX constants | ||
// see: https://eklitzke.org/path-max-is-tricky | ||
// https://stackoverflow.com/a/56385296 | ||
#define MUMBLE_MAX_PATH 1024 | ||
|
||
char *getRuntimePath__() { | ||
char buffer[MUMBLE_MAX_PATH]; | ||
char *path = NULL; | ||
|
||
#ifdef _WIN32 | ||
path = strdup("\0"); | ||
#elif __linux__ | ||
char *xdgRuntimeDir = getenv("XDG_RUNTIME_DIR"); | ||
if (xdgRuntimeDir == NULL || !xdgRuntimeDir) { | ||
// char uid[10]; | ||
// sprintf(uid, "%d", getuid()); | ||
xdgRuntimeDir = "/run/user/"; | ||
// cwk_path_join(xdgRuntimeDir, uid, buffer, sizeof(buffer)); | ||
snprintf(buffer, sizeof(buffer), "%s/%d", xdgRuntimeDir, getuid()); | ||
} | ||
// size_t path_len = cwk_path_join(xdgRuntimeDir, "mumble", buffer, sizeof(buffer)); | ||
int path_len = snprintf(buffer, sizeof(buffer), "%s/mumble/", xdgRuntimeDir); | ||
#else | ||
char *home = getenv("HOME"); | ||
if (home == NULL) { | ||
struct passwd *pwent = getpwuid(getuid()); | ||
if (pwent && pwent->pw_dir && pwent->pw_dir[0]) | ||
home = pwent->pw_dir; | ||
else | ||
return NULL; | ||
} | ||
if ((path = malloc(strlen(home) + 1)) == NULL) | ||
return NULL; | ||
int path_len = snprintf(buffer, sizeof(buffer), "%s/", home); | ||
#endif | ||
#if !defined _WIN32 | ||
// if (path_len != strlen(buffer)) | ||
// buffer is too small. Result is truncated | ||
if ((path = malloc(path_len + 1)) == NULL) | ||
return NULL; | ||
strcpy(path, buffer); | ||
#endif | ||
return path; | ||
} | ||
|
||
char *getAndCreateOverlayPipePath__() { | ||
char buffer[MUMBLE_MAX_PATH]; | ||
char *overlapyPipeFile = "MumbleOverlayPipe"; | ||
char *path = NULL; | ||
char *runtimePath = getRuntimePath__(); | ||
if (runtimePath == NULL) | ||
return NULL; | ||
#if !defined __linux__ && !defined _WIN32 | ||
char *path_template = "%s.%s"; | ||
#else | ||
char *path_template = "%s%s"; | ||
#endif | ||
#if _WIN32 | ||
/* | ||
* on Windows we don't create the directory as getRuntimePath__() returns an empty string. | ||
* _mkdir(runtimePath); | ||
*/ | ||
#else | ||
mkdir(runtimePath, 0755); | ||
#endif | ||
// size_t path_len = cwk_path_join(runtimePath, overlapyPipeFile, buffer, sizeof(buffer)); | ||
int path_len = snprintf(buffer, sizeof(buffer), path_template, runtimePath, overlapyPipeFile); | ||
// if (path_len != strlen(path)) | ||
// path is too small. Result is truncated | ||
if ((path = malloc(path_len + 1)) == NULL) | ||
return NULL; | ||
strcpy(path, buffer); | ||
free(runtimePath); | ||
return path; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2022 The Mumble Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file at the root of the | ||
// Mumble source tree or at <https://www.mumble.info/LICENSE>. | ||
|
||
#ifndef MUMBLE_OVERLAY_IPC_UTILS_H__ | ||
#define MUMBLE_OVERLAY_IPC_UTILS_H__ | ||
|
||
char *getRuntimePath__(); | ||
|
||
char *getAndCreateOverlayPipePath__(); | ||
|
||
#endif // MUMBLE_OVERLAY_IPC_UTILS_H__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2021-2022 The Mumble Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file at the root of the | ||
// Mumble source tree or at <https://www.mumble.info/LICENSE>. | ||
|
||
#include "IPCUtils.h" | ||
extern "C" { | ||
#include "../../overlay/ipc_utils.h" | ||
} | ||
|
||
#include <QDir> | ||
#include <QProcessEnvironment> | ||
#include <QString> | ||
|
||
namespace Mumble { | ||
const std::string getRuntimePath(void) { | ||
char *c_mumbleRuntimePath = getRuntimePath__(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have to delete the allocated buffer once you are done with it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I change this to directly assigning the result to a I'll wrap the function call into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You still have to delete the source buffer as converting a C string into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's not possible to create a |
||
if (c_mumbleRuntimePath == NULL) | ||
return ""; | ||
std::string mumbleRuntimePath = c_mumbleRuntimePath; | ||
std::free(c_mumbleRuntimePath); | ||
return mumbleRuntimePath; | ||
} | ||
|
||
const std::string getAndCreateOverlayPipePath(void) { | ||
char *c_pipepath = getAndCreateOverlayPipePath__(); | ||
if (c_pipepath == NULL) | ||
return ""; | ||
std::string pipepath = c_pipepath; | ||
std::free(c_pipepath); | ||
return pipepath; | ||
} | ||
|
||
const std::string getAndCreateSocketPath(const std::string &basename) { | ||
const std::string mumbleRuntimePath = getRuntimePath(); | ||
#ifdef Q_OS_WIN | ||
return basename; | ||
#endif | ||
if (mumbleRuntimePath.empty()) | ||
return ""; | ||
QString qMumbleRuntimePath = QString::fromUtf8(mumbleRuntimePath.data(), int(mumbleRuntimePath.size())); | ||
QDir(qMumbleRuntimePath).mkpath("."); | ||
#ifdef Q_OS_LINUX | ||
std::string pipepath = mumbleRuntimePath + basename + "Socket"; | ||
#else // MAC or BSD | ||
const std::string pipepath = mumbleRuntimePath + "." + basename + "Socket"; | ||
#endif | ||
return pipepath; | ||
} | ||
|
||
}; // namespace Mumble |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2021-2022 The Mumble Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file at the root of the | ||
// Mumble source tree or at <https://www.mumble.info/LICENSE>. | ||
|
||
#ifndef MUMBLE_MUMBLE_IPCUTILS_H_ | ||
#define MUMBLE_MUMBLE_IPCUTILS_H_ | ||
|
||
#include <string> | ||
|
||
namespace Mumble { | ||
|
||
/** | ||
* @returns The path to MumbleOverlayPipe | ||
*/ | ||
const std::string getAndCreateOverlayPipePath(); | ||
|
||
/** | ||
* @returns The path to MumbleSocket | ||
*/ | ||
const std::string getAndCreateSocketPath(const std::string &); | ||
|
||
/** | ||
* @returns The path where Mumble sets up MumbleOverlayPipe and MumbleSocket | ||
*/ | ||
const std::string getRuntimePath(); | ||
|
||
}; // namespace Mumble | ||
|
||
#endif // MUMBLE_MUMBLE_IPCUTILS_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the double-underscores in the name? Usually that is reserved for internal library functions and should be avoided in userspace land
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used this notation to distinguish it from the functions in
src/mumble/IPCUtils[.h, .cpp]
. They wrap the C functions in C++.If you have better a idea, please tell me! I'm short of creativity hahahaha