Bug 1701182 - Prepend SNAP-specific prefix to shm path. r=stransky

Differential Revision: https://phabricator.services.mozilla.com/D110269
This commit is contained in:
Olivier Tilloy 2021-04-09 14:41:31 +00:00
Родитель 2ef0aed816
Коммит 17b5edfc93
5 изменённых файлов: 38 добавлений и 13 удалений

Просмотреть файл

@ -23,6 +23,7 @@
#include "imgIRequest.h"
#include "imgIContainer.h"
#include "mozilla/Sprintf.h"
#include "mozilla/WidgetUtils.h"
#include "mozilla/dom/Element.h"
#if defined(MOZ_WIDGET_GTK)
# include "nsIImageToPixbuf.h"
@ -72,17 +73,15 @@ static const MimeTypeAssociation appTypes[] = {
#define kDesktopColorGSKey "primary-color"
static bool IsRunningAsASnap() {
// SNAP holds the path to the snap, use SNAP_NAME
// which is easier to parse.
const char* snap_name = PR_GetEnv("SNAP_NAME");
const char* snapName = mozilla::widget::WidgetUtils::GetSnapInstanceName();
// return early if not set.
if (snap_name == nullptr) {
if (snapName == nullptr) {
return false;
}
// snap_name as defined on https://snapcraft.io/firefox
return (strcmp(snap_name, "firefox") == 0);
// snapName as defined on https://snapcraft.io/firefox
return (strcmp(snapName, "firefox") == 0);
}
nsresult nsGNOMEShellService::Init() {

Просмотреть файл

@ -6,6 +6,7 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/UniquePtrExtensions.h"
#include "mozilla/WidgetUtils.h"
#include <stdio.h>
#include <stdlib.h>
@ -1833,14 +1834,15 @@ nsToolkitProfileService::CreateProfile(nsIFile* aRootDir,
* get essentially the same benefits as dedicated profiles provides.
*/
bool nsToolkitProfileService::IsSnapEnvironment() {
// Copied from IsRunningAsASnap() in
// browser/components/shell/nsGNOMEShellService.cpp
// TODO: factor out this common code in one place.
const char* snap_name = PR_GetEnv("SNAP_NAME");
if (snap_name == nullptr) {
const char* snapName = mozilla::widget::WidgetUtils::GetSnapInstanceName();
// return early if not set.
if (snapName == nullptr) {
return false;
}
return (strcmp(snap_name, "firefox") == 0);
// snapName as defined on https://snapcraft.io/firefox
return (strcmp(snapName, "firefox") == 0);
}
/**

Просмотреть файл

@ -13,6 +13,7 @@
#include "nsIBidiKeyboard.h"
#include "nsIStringBundle.h"
#include "nsTArray.h"
#include "prenv.h"
#ifdef XP_WIN
# include "WinUtils.h"
#endif
@ -145,5 +146,14 @@ void WidgetUtils::GetBrandShortName(nsAString& aBrandName) {
}
}
const char* WidgetUtils::GetSnapInstanceName() {
char* instanceName = PR_GetEnv("SNAP_INSTANCE_NAME");
if (instanceName != nullptr) {
return instanceName;
}
// Compatibility for snapd <= 2.35:
return PR_GetEnv("SNAP_NAME");
}
} // namespace widget
} // namespace mozilla

Просмотреть файл

@ -93,6 +93,11 @@ class WidgetUtils {
* Get branchShortName from string bundle
*/
static void GetBrandShortName(nsAString& aBrandName);
/* When packaged as a snap, strict confinement needs to be accounted for.
See https://snapcraft.io/docs for details.
Return the snap's instance name, or null when not running as a snap. */
static const char* GetSnapInstanceName();
};
} // namespace widget

Просмотреть файл

@ -16,6 +16,7 @@
#include "nsTArray.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/StaticPrefs_widget.h"
#include "mozilla/WidgetUtils.h"
#include <sys/mman.h>
#include <fcntl.h>
@ -169,9 +170,17 @@ RefPtr<nsWaylandDisplay> WindowBackBuffer::GetWaylandDisplay() {
static int WaylandAllocateShmMemory(int aSize) {
int fd = -1;
nsCString shmPrefix("/");
const char* snapName = mozilla::widget::WidgetUtils::GetSnapInstanceName();
if (snapName != nullptr) {
shmPrefix.AppendPrintf("snap.%s.", snapName);
}
shmPrefix.Append("wayland.mozilla.ipc");
do {
static int counter = 0;
nsPrintfCString shmName("/wayland.mozilla.ipc.%d", counter++);
nsPrintfCString shmName("%s.%d", shmPrefix.get(), counter++);
fd = shm_open(shmName.get(), O_CREAT | O_RDWR | O_EXCL, 0600);
if (fd >= 0) {
// We don't want to use leaked file