Author: kelnos
Date: 2008-10-17 08:26:18 +0000 (Fri, 17 Oct 2008)
New Revision: 28274

Modified:
   xfce4-session/trunk/ChangeLog
   xfce4-session/trunk/xfce4-session/xfsm-manager.c
   xfce4-session/trunk/xfce4-session/xfsm-startup.c
Log:
    * xfce4-session/xfsm-startup.c: Store the result of fork() in a
      temporary again to avoid possible memory access issues if
      vfork() is used.
    * xfce4-session/xfsm-manager.c: Fix a XfsmProperties leak if
      a SmRestartNever or SmRestartIfRunning client exits and doesn't
      have a discard command, or exits during initial startup.

Modified: xfce4-session/trunk/ChangeLog
===================================================================
--- xfce4-session/trunk/ChangeLog       2008-10-17 08:02:28 UTC (rev 28273)
+++ xfce4-session/trunk/ChangeLog       2008-10-17 08:26:18 UTC (rev 28274)
@@ -1,5 +1,14 @@
 2008-10-17     Brian Tarricone <[EMAIL PROTECTED]>
 
+       * xfce4-session/xfsm-startup.c: Store the result of fork() in a
+         temporary again to avoid possible memory access issues if
+         vfork() is used.
+       * xfce4-session/xfsm-manager.c: Fix a XfsmProperties leak if
+         a SmRestartNever or SmRestartIfRunning client exits and doesn't
+         have a discard command, or exits during initial startup.
+
+2008-10-17     Brian Tarricone <[EMAIL PROTECTED]>
+
        * xfce4-session/xfsm-properties.[ch]: Track the PID of properties
          that have an associated app running, whether or not it's
          registered with the SM.  Add client ID comparison function.

Modified: xfce4-session/trunk/xfce4-session/xfsm-manager.c
===================================================================
--- xfce4-session/trunk/xfce4-session/xfsm-manager.c    2008-10-17 08:02:28 UTC 
(rev 28273)
+++ xfce4-session/trunk/xfce4-session/xfsm-manager.c    2008-10-17 08:26:18 UTC 
(rev 28274)
@@ -398,29 +398,46 @@
             }
         }
     }
-  else if (manager->state == XFSM_MANAGER_IDLE && properties->discard_command 
!= NULL)
+  else
     {
-      /* Run the SmDiscardCommand after the client exited in IDLE state,
-       * but only if we don't expect the client to be restarted,
-       * whether immediately or in the next session.
-       * Unfortunately the spec isn't clear about the usage of the
-       * discard command. Have to check ksmserver/gnome-session, and
-       * come up with consistent behaviour.
-       * But for now, this work-around fixes the problem of the
-       * ever-growing number of xfwm4 session files when restarting
-       * xfwm4 within a session.
-       */
-      xfsm_verbose ("Client Id = %s exited while in IDLE state, running "
-                    "discard command now.\n\n", properties->client_id);
+      /* We get here if a SmRestartNever or SmRestartIfRunning client
+       * has exited.  SmRestartNever clients shouldn't have discard
+       * commands, but it can't hurt to run it if it has one for some
+       * reason, and might clean up garbage we don't want. */
+      xfsm_verbose ("Client Id %s exited, removing from session.\n",
+                    properties->client_id);
 
-      g_spawn_sync (properties->current_directory,
-                    properties->discard_command,
-                    properties->environment,
-                    G_SPAWN_SEARCH_PATH,
-                    NULL, NULL,
-                    NULL, NULL,
-                    NULL, NULL);
+      if (properties->discard_command != NULL)
+        {
+          /* Run the SmDiscardCommand after the client exited in any state,
+           * but only if we don't expect the client to be restarted,
+           * whether immediately or in the next session.
+           *
+           * NB: This used to also have the condition that the manager is
+           * in the IDLE state, but this was removed because I can't see
+           * why you'd treat a client that fails during startup any
+           * differently, and this fixes a potential properties leak.
+           *
+           * Unfortunately the spec isn't clear about the usage of the
+           * discard command. Have to check ksmserver/gnome-session, and
+           * come up with consistent behaviour.
+           *
+           * But for now, this work-around fixes the problem of the
+           * ever-growing number of xfwm4 session files when restarting
+           * xfwm4 within a session.
+           */
+          xfsm_verbose ("Client Id = %s: running discard command.\n\n",
+                        properties->client_id);
 
+          g_spawn_sync (properties->current_directory,
+                        properties->discard_command,
+                        properties->environment,
+                        G_SPAWN_SEARCH_PATH,
+                        NULL, NULL,
+                        NULL, NULL,
+                        NULL, NULL);
+        }
+
       return FALSE;
     }
 

Modified: xfce4-session/trunk/xfce4-session/xfsm-startup.c
===================================================================
--- xfce4-session/trunk/xfce4-session/xfsm-startup.c    2008-10-17 08:02:28 UTC 
(rev 28273)
+++ xfce4-session/trunk/xfce4-session/xfsm-startup.c    2008-10-17 08:26:18 UTC 
(rev 28274)
@@ -491,7 +491,11 @@
   gchar          **argv;
   gint             argc;
   gint             n;
+  GPid             pid;
 
+  /* release any possible old resources related to a previous startup */
+  xfsm_properties_set_default_child_watch (properties);
+
   /* generate the argument vector for the application (expanding variables) */
   argc = g_strv_length (properties->restart_command);
   argv = g_new (gchar *, argc + 1);
@@ -501,13 +505,13 @@
 
   /* fork a new process for the application */
 #ifdef HAVE_VFORK
-  properties->pid = vfork ();
+  pid = vfork ();
 #else
-  properties->pid = fork ();
+  pid = fork ();
 #endif
 
   /* handle the child process */
-  if (properties->pid == 0)
+  if (pid == 0)
     {
       /* execute the application here */
       execvp (argv[0], argv);
@@ -518,13 +522,15 @@
   g_strfreev (argv);
 
   /* check if we failed to fork */
-  if (G_UNLIKELY (properties->pid < 0))
+  if (G_UNLIKELY (pid < 0))
     {
       /* tell the user that we failed to fork */
       perror ("Failed to fork new process");
       return FALSE;
     }
 
+  properties->pid = pid;
+
   /* set a watch to make sure the child doesn't quit before registering */
   child_watch_data = g_new (XfsmStartupData, 1);
   child_watch_data->manager = g_object_ref (manager);

_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to