Quellcode durchsuchen

fixed few issues

UwU vor 1 Monat
Ursprung
Commit
55c56a0a0c

+ 10 - 2
src/WallpaperEngine/Application/ApplicationContext.cpp

@@ -321,14 +321,22 @@ void ApplicationContext::loadSettingsFromArgv () {
 	.default_value (0)
 	.hidden ()
 	.action ([this] (const std::string& value) -> void {
-	    this->settings.general.webHostWidth = static_cast<uint32_t> (std::stoul (value));
+	    try {
+		this->settings.general.webHostWidth = static_cast<uint32_t> (std::stoul (value));
+	    } catch (const std::exception&) {
+		sLog.exception ("Invalid --web-host-width value: ", value);
+	    }
 	});
 
     backgroundGroup.add_argument ("--web-host-height")
 	.default_value (0)
 	.hidden ()
 	.action ([this] (const std::string& value) -> void {
-	    this->settings.general.webHostHeight = static_cast<uint32_t> (std::stoul (value));
+	    try {
+		this->settings.general.webHostHeight = static_cast<uint32_t> (std::stoul (value));
+	    } catch (const std::exception&) {
+		sLog.exception ("Invalid --web-host-height value: ", value);
+	    }
 	});
 
     backgroundMode.add_argument ("-w", "--window")

+ 12 - 21
src/WallpaperEngine/Render/Wallpapers/CWeb.cpp

@@ -10,9 +10,8 @@
 
 #include <chrono>
 #include <csignal>
-#include <cstdlib>
-#include <dirent.h>
 #include <sys/prctl.h>
+#include <sys/syscall.h>
 #include <sys/wait.h>
 #include <thread>
 #include <unistd.h>
@@ -23,26 +22,13 @@ using namespace WallpaperEngine::WebBrowser::IPC;
 
 namespace {
 // Closes every fd but stdio, so the exec'd CEF child doesn't inherit the parent's
-// Wayland/EGL/X11/audio connections.
+// Wayland/EGL/X11/audio connections. Must be async-signal-safe: this runs in the fork()ed child
+// of a process that may have other threads running (SDL audio), so only a raw syscall - never
+// opendir/readdir, which allocate - is safe to call here before execv().
 void closeInheritedFds () {
-    DIR* dir = opendir ("/proc/self/fd");
-
-    if (dir == nullptr) {
-	return;
-    }
-
-    const int dirFd = dirfd (dir);
-
-    while (dirent* entry = readdir (dir)) {
-	char* end = nullptr;
-	const long fd = std::strtol (entry->d_name, &end, 10);
-
-	if (end != entry->d_name && *end == '\0' && fd > 2 && fd != dirFd) {
-	    close (static_cast<int> (fd));
-	}
-    }
-
-    closedir (dir);
+#if defined(SYS_close_range)
+    syscall (SYS_close_range, 3u, ~0u, 0u);
+#endif
 }
 } // namespace
 
@@ -145,6 +131,11 @@ void CWeb::setSize (const int width, const int height) {
 }
 
 void CWeb::renderFrame (const glm::ivec4& viewport) {
+    if (!this->m_helperFailureLogged && this->m_shm->helperFailed.load (std::memory_order_relaxed)) {
+	sLog.error ("CWeb: host process failed to start, this web wallpaper will not render");
+	this->m_helperFailureLogged = true;
+    }
+
     // ensure the viewport matches the window size, and resize if needed
     if (viewport.z != this->getWidth () || viewport.w != this->getHeight ()) {
 	this->setSize (viewport.z, viewport.w);

+ 1 - 0
src/WallpaperEngine/Render/Wallpapers/CWeb.h

@@ -61,6 +61,7 @@ private:
     uint32_t m_uploadedTextureWidth = 0;
     uint32_t m_uploadedTextureHeight = 0;
     pid_t m_hostPid = -1;
+    bool m_helperFailureLogged = false;
 
     int m_width = 16;
     int m_height = 17;