From 681e76c551df3e1c9daf07d0b8075d2cca77c832 Mon Sep 17 00:00:00 2001 From: bit6tream Date: Wed, 22 Nov 2023 01:48:31 +0300 Subject: [PATCH 1/2] (#1693) Notify user if /tmp directory has `noexec` mount option Minecraft versions starting from 1.19 would not start at all if /tmp is mounted as `noexec`. Signed-off-by: bit6tream --- launcher/Application.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index be252f1c5..619215162 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -82,6 +82,7 @@ #include #include +#include #include #include @@ -132,6 +133,10 @@ #include "gamemode_client.h" #endif +#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) +#include +#endif + #if defined(Q_OS_MAC) #if defined(SPARKLE_ENABLED) #include "updater/MacSparkleUpdater.h" @@ -988,6 +993,36 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) } } +#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) + + // notify user if /tmp is mounted with `noexec` (#1693) + { + FILE* description = setmntent(MOUNTED, "r"); + mntent* info = nullptr; + + while ((info = getmntent(description)) != nullptr) { + std::string_view directory = info->mnt_dir; + std::string_view options = info->mnt_opts; + + if (directory == "/tmp" && options.rfind("noexec") != std::string_view::npos) { + auto infoMsg = + tr("Your /tmp directory is currently mounted with the 'noexec' flag enabled.\n" + "Some versions of Minecraft may not launch.\n"); + auto msgBox = new QMessageBox(QMessageBox::Information, tr("Incompatible system configuration"), infoMsg, QMessageBox::Ok); + msgBox->setDefaultButton(QMessageBox::Ok); + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->setMinimumWidth(460); + msgBox->adjustSize(); + msgBox->open(); + break; + } + } + + endmntent(description); + } + +#endif + if (createSetupWizard()) { return; } From d414599974c6a8dc1a11fa769dff9e0f8feb5f01 Mon Sep 17 00:00:00 2001 From: bit6tream Date: Thu, 23 Nov 2023 15:19:04 +0300 Subject: [PATCH 2/2] (#1693) Use a better approach to detect a noexec mount option Signed-off-by: bit6tream --- launcher/Application.cpp | 55 ++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 619215162..cfede9dc1 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -82,7 +82,6 @@ #include #include -#include #include #include @@ -133,8 +132,13 @@ #include "gamemode_client.h" #endif -#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) -#include +#if defined(Q_OS_LINUX) +#include +#endif + +#if defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) +#include +#include #endif #if defined(Q_OS_MAC) @@ -993,36 +997,37 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) } } -#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) - // notify user if /tmp is mounted with `noexec` (#1693) { - FILE* description = setmntent(MOUNTED, "r"); - mntent* info = nullptr; + bool is_tmp_noexec = false; - while ((info = getmntent(description)) != nullptr) { - std::string_view directory = info->mnt_dir; - std::string_view options = info->mnt_opts; +#if defined(Q_OS_LINUX) - if (directory == "/tmp" && options.rfind("noexec") != std::string_view::npos) { - auto infoMsg = - tr("Your /tmp directory is currently mounted with the 'noexec' flag enabled.\n" - "Some versions of Minecraft may not launch.\n"); - auto msgBox = new QMessageBox(QMessageBox::Information, tr("Incompatible system configuration"), infoMsg, QMessageBox::Ok); - msgBox->setDefaultButton(QMessageBox::Ok); - msgBox->setAttribute(Qt::WA_DeleteOnClose); - msgBox->setMinimumWidth(460); - msgBox->adjustSize(); - msgBox->open(); - break; - } - } + struct statvfs tmp_stat; + statvfs("/tmp", &tmp_stat); + is_tmp_noexec = tmp_stat.f_flag & ST_NOEXEC; - endmntent(description); - } +#elif defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) + + struct statfs tmp_stat; + statfs("/tmp", &tmp_stat); + is_tmp_noexec = tmp_stat.f_flags & MNT_NOEXEC; #endif + if (is_tmp_noexec) { + auto infoMsg = + tr("Your /tmp directory is currently mounted with the 'noexec' flag enabled.\n" + "Some versions of Minecraft may not launch.\n"); + auto msgBox = new QMessageBox(QMessageBox::Information, tr("Incompatible system configuration"), infoMsg, QMessageBox::Ok); + msgBox->setDefaultButton(QMessageBox::Ok); + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->setMinimumWidth(460); + msgBox->adjustSize(); + msgBox->open(); + } + } + if (createSetupWizard()) { return; }