After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 588119 - Should set RestartStyleHint to RestartIfRunning when replaced
Should set RestartStyleHint to RestartIfRunning when replaced
Status: RESOLVED FIXED
Product: metacity
Classification: Other
Component: general
2.27.x
Other All
: Normal critical
: ---
Assigned To: Metacity maintainers list
Metacity maintainers list
: 591642 597654 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-07-08 21:22 UTC by Chris Coulson
Modified: 2011-01-25 14:27 UTC
See Also:
GNOME target: ---
GNOME version: 2.27/2.28


Attachments
Ubuntu patch (1.05 KB, patch)
2009-07-08 21:27 UTC, Chris Coulson
reviewed Details | Review
Should set RestartStyleHint to RestartIfRunning when replaced (4.60 KB, patch)
2009-08-22 19:53 UTC, Owen Taylor
committed Details | Review

Description Chris Coulson 2009-07-08 21:22:16 UTC
Please describe the problem:
Some Ubuntu users are reporting with 2.27.0 that when they run "compiz --replace" after starting their session with Metacity as the window manager (/desktop/gnome/session/required_components/windowmanager = "metacity"), gnome-session continually tries to respawn Metacity once Compiz is running. Gnome-session will then use 100% CPU for the remainder of the session when doing this.

The reason for this is Metacity sets the RestartStyleHint to RestartImmediately when it first runs If another window manager replaces it later on, it exits without changing it back to RestartIfRunning. gnome-session will then immediately respawn Metacity, which will connect to the session manager, set the RestartStyleHint to RestartImmediately, try to control the display, then exit again when it realises it can't (because Compiz is running by now). This cycle then continues indefinately for the remainder of the session.

This used to work in 2.26 (I checked the debug output from gnome-session, which showed that Metacity always sets the RestartStyleHint back to RestartIfRunning when replaced with another WM).

The bug is introduced by this change:

--- metacity-2.25.144/src/core/session.c 2009-02-01 20:33:15.000000000 +0000
+++ metacity-2.27.0/src/core/session.c 2009-02-20 15:26:32.000000000 +0000
@@ -376,6 +376,14 @@ meta_session_shutdown (void)
   SmProp *props[1];
   char hint = SmRestartIfRunning;

+ if (!meta_get_display ())
+ {
+ meta_verbose ("Cannot close session because there is no display");
+ return;
+ }
+
+ warn_about_lame_clients_and_finish_interact (FALSE);
+
   if (session_connection == NULL)
     return;

What is happening is meta_session_shutdown() is being called after meta_display_close(). Because the display is already closed at this point, meta_session_shutdown() returns without setting the RestartStyleHint.

Steps to reproduce:
1. Log in with metacity as the default WM (/desktop/gnome/session/required_components/windowmanager = "metacity")
2. Run "compiz --replace"


Actual results:
Metacity exits and then gnome-session respawns a new one, which exits immediately. This cycle repeats for the remainder of the session.

Expected results:
Metacity should exit and not be respawned

Does this happen every time?
Yes - but you must have Metacity autostarted at the start of the session by setting /desktop/gnome/session/required_components/windowmanager = "metacity", otherwise there is no restart command and gnome-session won't try to restart it.

Other information:
Comment 1 Chris Coulson 2009-07-08 21:27:22 UTC
Created attachment 138075 [details] [review]
Ubuntu patch

This is the patch I proposed in Ubuntu. It moves the check for the display and displaying the warning dialog until after the RestartStyleHint is changed.
Comment 2 Chris Coulson 2009-07-08 21:29:15 UTC
Here's the Ubuntu bug for reference: https://bugs.launchpad.net/metacity/+bug/389686
Comment 3 Ray Strode [halfline] 2009-08-13 02:12:24 UTC
*** Bug 591642 has been marked as a duplicate of this bug. ***
Comment 4 Ray Strode [halfline] 2009-08-13 02:14:43 UTC
I don't think attachment 138075 [details] [review] is quite right.  I think the original commit introducing the problem should just get reverted.  See 591642 comment 0 for my rationale.
Comment 5 Owen Taylor 2009-08-22 19:51:01 UTC
I don't think entirely reverting abbd057 is right; as I read the code, there is an access to freed memory in the old code, since we g_free() the MetaDisplay structure but don't null out the global 'the_display'. Then when we call meta_display_close() we access display->closing.

But I otherwise agree with Ray. I'll attach a patch that implements how I think makes sense.
Comment 6 Owen Taylor 2009-08-22 19:53:47 UTC
Created attachment 141446 [details] [review]
Should set RestartStyleHint to RestartIfRunning when replaced

This reverts most of commit abbd057eb967e6ab462ffe305f41b2b04d417b25;

 - It's fine to call meta_session_shutdown() after the display
   is closed, since it's talking over the ICE connection
 - We should not call warn_about_lame_clients_and_finish_interact()
   unless we are interacting with the window manager in a session
   save.

However, the part of abbd057 that fixed accessing freed memory was
fixing a real problem; this patches does the same thing in a simpler
way by fixing an obvious type in meta_display_close() where it was
NULL'ing out the local variable 'display' rather than the global
variable 'the_display' and adding keeping the check in meta_finalize()
that was added in abbd057.

The order of calling meta_session_shutdown() and
calling meta_display_close() is reverted back to the old order to
make it clear that it's OK if the display way already closed previously.
Comment 7 Owen Taylor 2009-10-07 14:30:03 UTC
*** Bug 597654 has been marked as a duplicate of this bug. ***
Comment 8 Thomas Thurman 2011-01-25 14:27:33 UTC
Review of attachment 141446 [details] [review]:

Looks like a very good idea to me. Committed.
Comment 9 Thomas Thurman 2011-01-25 14:27:56 UTC
-> FIXED