[gnome-shell] shell/app: Restore NOFILE limit



commit 9862ee9b25b2137945e6b17001555e6049924be4
Author: Olivier Fourdan <ofourdan redhat com>
Date:   Wed Jan 19 10:22:57 2022 +0100

    shell/app: Restore NOFILE limit
    
    Restore the nofile limit when launching apps so that they do not
    inherit from the Shell's own limit.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2117>

 src/shell-app.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/src/shell-app.c b/src/shell-app.c
index 863f4db9d7..2ed23fab5b 100644
--- a/src/shell-app.c
+++ b/src/shell-app.c
@@ -7,6 +7,7 @@
 #include <glib/gi18n-lib.h>
 
 #include <meta/display.h>
+#include <meta/meta-context.h>
 #include <meta/meta-workspace-manager.h>
 #include <meta/meta-x11-display.h>
 
@@ -1292,6 +1293,16 @@ shell_app_request_quit (ShellApp   *app)
   return TRUE;
 }
 
+static void
+child_context_setup (gpointer user_data)
+{
+  ShellGlobal *shell_global = user_data;
+  MetaContext *meta_context;
+
+  g_object_get (shell_global, "context", &meta_context, NULL);
+  meta_context_restore_rlimit_nofile (meta_context, NULL);
+}
+
 #if !defined(HAVE_GIO_DESKTOP_LAUNCH_URIS_WITH_FDS) && defined(HAVE_SYSTEMD)
 /* This sets up the launched application to log to the journal
  * using its own identifier, instead of just "gnome-session".
@@ -1302,6 +1313,8 @@ app_child_setup (gpointer user_data)
   const char *appid = user_data;
   int res;
   int journalfd = sd_journal_stream_fd (appid, LOG_INFO, FALSE);
+  ShellGlobal *shell_global = shell_global_get ();
+
   if (journalfd >= 0)
     {
       do
@@ -1312,6 +1325,8 @@ app_child_setup (gpointer user_data)
       while (G_UNLIKELY (res == -1 && errno == EINTR));
       (void) close (journalfd);
     }
+
+  child_context_setup (shell_global);
 }
 #endif
 
@@ -1396,6 +1411,7 @@ shell_app_launch (ShellApp           *app,
   gboolean ret;
   GSpawnFlags flags;
   gboolean discrete_gpu = FALSE;
+  ShellGlobal *shell_global = shell_global_get ();
 
   if (app->info == NULL)
     {
@@ -1439,7 +1455,7 @@ shell_app_launch (ShellApp           *app,
     ret = g_desktop_app_info_launch_uris_as_manager_with_fds (app->info, NULL,
                                                               context,
                                                               flags,
-                                                              NULL, NULL,
+                                                              child_context_setup, shell_global,
                                                               wait_pid, NULL,
                                                               -1,
                                                               journalfd,
@@ -1456,7 +1472,7 @@ shell_app_launch (ShellApp           *app,
 #ifdef HAVE_SYSTEMD
                                                    app_child_setup, (gpointer)shell_app_get_id (app),
 #else
-                                                   NULL, NULL,
+                                                   child_context_setup, shell_global,
 #endif
                                                    wait_pid, NULL,
                                                    error);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]