~ubuntu-branches/ubuntu/raring/gnome-session/raring

« back to all changes in this revision

Viewing changes to gnome-session/gsm-manager.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-05-07 11:22:35 UTC
  • mfrom: (1.1.75) (2.2.14 sid)
  • Revision ID: package-import@ubuntu.com-20120507112235-z9pe25ur5d8zt4c6
Tags: 3.4.1-1ubuntu1
* Merge with Debian. Remaining changes:
 - debian/control.in:
   + gnome-session
     - Recommend nautilus and either unity, unity-2d or gnome-shell
     - Only suggest gnome-session-fallback (we don't want it to be installed
       by default)
     - Drop the Recommends on gnome-power-manager, the code gnome-session uses
       has moved to gnome-settings-daemon
   + gnome-session-fallback
     - Recommend cups-pk-helper for gnome-session-fallback so that
       System Settings>Printers works
 - debian/gnome-session-bin.postinst, debian/gnome-session-bin.prerm:
    Moved registering gnome-session binary as a session manager to 
    gnome-session-bin package
 - debian/postinst, postrm:
    set the default lightdm session as ubuntu if none already set
 - don't install defaults.list (installed by desktop-file-utils in ubuntu):
    debian/gnome-session-common.dirs and gnome-session-common.install
 - add debian/gnome-session-common.gsettings-override:
   set ubuntu as the default session if nothing is provided
 - debian/55gnome-session_gnomerc:
    Use POSIX string substitutions (shell internal) instead of external
    basename and cut for startup speed.
 - debian/patches/20_hide_nodisplay.patch:
    Don't show applications in the Sessions properties dialog that have
    NoDisplay=true.
 - debian/patches/21_up_start_on_demand.patch:
    Don't call dkp_client_new() until actually needed. This blocks
    for some time whilst DK-Power is started, if it wasn't running already
    (which is the case during auto-login). This can delay the whole
    session from starting.
 - debian/patches/22_support_autostart_delay.patch:
    Bugzilla patch to support adding a delay to autostart apps, using
    a "X-GNOME-Autostart-Delay" key in the desktop file
 - debian/patches/50_ubuntu_sessions.patch:
    + Add Ubuntu & Ubuntu 2D sessions
    + Add GNOME Classic (Without Effects session). Use notify-osd for
      notifications, but don't add it to RequiredComponents since notify-osd
      doesn't have an autostart .desktop file
    + gnome-shell.desktop adds --session=gnome now that the "ubuntu" session
      is the default. Use TryExec to test if gnome-shell is installed.
 - debian/patches/51_remove_session_saving_from_gui.patch:
    add GNOME_SESSION_SAVE environment variable for people wanting to
    use the save session still, knowing that it can break your system
    if used unwisely (LP: #771896)
 - debian/patches/52_xdg_current_desktop.patch:
    Set XDG_CURRENT_DESKTOP inside gnome-session based on a
    new key 'DesktopName' in gnome-session .desktop files.
 - debian/patches/80_new_upstream_session_dialog.patch:
    Bugzilla patch to change the session dialog. (Deactivated, see bug 807503)
 - debian/patches/95_dbus_request_shutdown.patch:
    Add "RequestShutdown" and "RequestReboot" DBus methods to allow other
    applications to shutdown or reboot the machine via the session manager.
 - debian/patches/96_no_catch_sigsegv.patch:
    Don't register a handler for SIGSEGV. We want Apport to catch these
    crashes so that users can submit useful crash reports.
 - debian/patches/101_screen_lock_on_suspend.patch:
    Use the same logic as gnome-power-manager for deciding the "screen
    lock on suspend" policy. This restores the Jaunty behaviour rather
    than just using the screensaver settings, which is surprising for
    users.
    This patch is deactivated for now, we'll see with the new screensaver and
    screen locking experience what to do (not rebased on gsettings as well)
  - debian/patches/103_kill_the_fail_whale.patch:
    seems that the fail whale try to come back and resist from his removal
    refreshed the patch to ensure it's killed and won't come back ever ever
    again.
  - 104_dont_show_fallback_warning.patch:
    Disable GNOME Fallback warning. It doesn't really explain anything
    and assumes that there aren't people that want to run Fallback.
  - debian/patches/105_hide_session_startup_help.patch:
    Hide Help button on Startup Applications dialog, as it is broken
    and the help documentation hasn't been written for 3.x yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
#include "gsm-fail-whale-dialog.h"
62
62
#include "gsm-icon-names.h"
63
63
#include "gsm-inhibit-dialog.h"
64
 
#include "gsm-consolekit.h"
 
64
#include "gsm-system.h"
65
65
#include "gsm-session-save.h"
 
66
#include "gsm-shell-extensions.h"
66
67
 
67
68
#define GSM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSM_TYPE_MANAGER, GsmManagerPrivate))
68
69
 
274
275
                         GsmApp      *app)
275
276
{
276
277
        const gchar *app_id;
277
 
        gboolean want_extensions_ui;
278
278
        gboolean allow_logout;
 
279
        GsmSystem *system;
 
280
        GsmShellExtensions *extensions;
279
281
 
280
282
        app_id = gsm_app_peek_app_id (app);
281
 
        want_extensions_ui = g_str_equal (app_id, "gnome-shell.desktop");
282
 
 
283
 
        if (gsm_consolekit_is_current_session_login ()) {
 
283
 
 
284
        if (g_str_equal (app_id, "gnome-shell.desktop")) {
 
285
                extensions = g_object_new (GSM_TYPE_SHELL_EXTENSIONS, NULL);
 
286
                gsm_shell_extensions_disable_all (extensions);
 
287
        } else {
 
288
                extensions = NULL;
 
289
        }
 
290
 
 
291
        system = gsm_get_system ();
 
292
        if (gsm_system_is_login_session (system)) {
284
293
                allow_logout = FALSE;
285
294
        } else {
286
295
                allow_logout = !_log_out_is_locked_down (manager);
287
296
        }
 
297
        g_object_unref (system);
288
298
 
289
299
        gsm_fail_whale_dialog_we_failed (FALSE,
290
300
                                         allow_logout,
291
 
                                         want_extensions_ui);
 
301
                                         extensions);
292
302
}
293
303
 
294
304
static gboolean
342
352
}
343
353
 
344
354
static gboolean
345
 
_find_by_startup_id (const char *id,
346
 
                     GsmClient  *client,
347
 
                     const char *startup_id_a)
 
355
_client_has_startup_id (const char *id,
 
356
                        GsmClient  *client,
 
357
                        const char *startup_id_a)
348
358
{
349
359
        const char *startup_id_b;
350
360
 
368
378
                 condition);
369
379
 
370
380
        client = (GsmClient *)gsm_store_find (manager->priv->clients,
371
 
                                              (GsmStoreFunc)_find_by_startup_id,
 
381
                                              (GsmStoreFunc)_client_has_startup_id,
372
382
                                              (char *)gsm_app_peek_startup_id (app));
373
383
 
374
384
        if (condition) {
462
472
static void start_phase (GsmManager *manager);
463
473
 
464
474
static void
465
 
quit_request_completed (GsmConsolekit *consolekit,
466
 
                        GError        *error,
467
 
                        gpointer       user_data)
 
475
quit_request_completed (GsmSystem *system,
 
476
                        GError    *error,
 
477
                        gpointer   user_data)
468
478
{
469
479
        GdmLogoutAction fallback_action = GPOINTER_TO_INT (user_data);
470
480
 
472
482
                gdm_set_logout_action (fallback_action);
473
483
        }
474
484
 
475
 
        g_object_unref (consolekit);
 
485
        g_object_unref (system);
476
486
 
477
487
        gtk_main_quit ();
478
488
}
480
490
static void
481
491
gsm_manager_quit (GsmManager *manager)
482
492
{
483
 
        GsmConsolekit *consolekit;
 
493
        GsmSystem *system;
484
494
 
485
495
        /* See the comment in request_reboot() for some more details about how
486
496
         * this works. */
493
503
        case GSM_MANAGER_LOGOUT_REBOOT_INTERACT:
494
504
                gdm_set_logout_action (GDM_LOGOUT_ACTION_NONE);
495
505
 
496
 
                consolekit = gsm_get_consolekit ();
497
 
                g_signal_connect (consolekit,
 
506
                system = gsm_get_system ();
 
507
                g_signal_connect (system,
498
508
                                  "request-completed",
499
509
                                  G_CALLBACK (quit_request_completed),
500
510
                                  GINT_TO_POINTER (GDM_LOGOUT_ACTION_NONE));
501
 
                gsm_consolekit_attempt_restart (consolekit);
 
511
                gsm_system_attempt_restart (system);
502
512
                break;
503
513
        case GSM_MANAGER_LOGOUT_REBOOT_GDM:
504
514
                gdm_set_logout_action (GDM_LOGOUT_ACTION_REBOOT);
508
518
        case GSM_MANAGER_LOGOUT_SHUTDOWN_INTERACT:
509
519
                gdm_set_logout_action (GDM_LOGOUT_ACTION_NONE);
510
520
 
511
 
                consolekit = gsm_get_consolekit ();
512
 
                g_signal_connect (consolekit,
 
521
                system = gsm_get_system ();
 
522
                g_signal_connect (system,
513
523
                                  "request-completed",
514
524
                                  G_CALLBACK (quit_request_completed),
515
525
                                  GINT_TO_POINTER (GDM_LOGOUT_ACTION_NONE));
516
 
                gsm_consolekit_attempt_stop (consolekit);
 
526
                gsm_system_attempt_stop (system);
517
527
                break;
518
528
        case GSM_MANAGER_LOGOUT_SHUTDOWN_GDM:
519
529
                gdm_set_logout_action (GDM_LOGOUT_ACTION_SHUTDOWN);
586
596
}
587
597
 
588
598
static void
 
599
app_event_during_startup (GsmManager *manager,
 
600
                          GsmApp     *app)
 
601
{
 
602
        if (!(manager->priv->phase < GSM_MANAGER_PHASE_APPLICATION))
 
603
                return;
 
604
 
 
605
        manager->priv->pending_apps = g_slist_remove (manager->priv->pending_apps, app);
 
606
 
 
607
        if (manager->priv->pending_apps == NULL) {
 
608
                if (manager->priv->phase_timeout_id > 0) {
 
609
                        g_source_remove (manager->priv->phase_timeout_id);
 
610
                        manager->priv->phase_timeout_id = 0;
 
611
                }
 
612
 
 
613
                end_phase (manager);
 
614
        }
 
615
}
 
616
 
 
617
static void
 
618
_restart_app (GsmManager *manager,
 
619
              GsmApp     *app)
 
620
{
 
621
        GError *error = NULL;
 
622
 
 
623
        if (!gsm_app_restart (app, &error)) {
 
624
                if (is_app_required (manager, app)) {
 
625
                        on_required_app_failure (manager, app);
 
626
                } else {
 
627
                        g_warning ("Error on restarting session managed app: %s", error->message);
 
628
                }
 
629
                g_clear_error (&error);
 
630
 
 
631
                app_event_during_startup (manager, app);
 
632
        }
 
633
}
 
634
 
 
635
static void
589
636
app_died (GsmApp     *app,
 
637
          int         signal,
590
638
          GsmManager *manager)
591
639
{
592
 
        GError *error = NULL;
593
 
 
594
 
        manager->priv->pending_apps = g_slist_remove (manager->priv->pending_apps, app);
595
 
        g_signal_handlers_disconnect_by_func (app, app_registered, manager);
596
 
 
597
 
        g_warning ("Application '%s' killed by signal", gsm_app_peek_app_id (app));
 
640
        g_warning ("Application '%s' killed by signal %d", gsm_app_peek_app_id (app), signal);
598
641
 
599
642
        if (gsm_app_peek_autorestart (app)) {
600
643
                g_debug ("Component '%s' is autorestart, ignoring died signal",
602
645
                return;
603
646
        }
604
647
 
605
 
        if (!gsm_app_restart (app, &error)) {
606
 
                if (is_app_required (manager, app)) {
607
 
                        on_required_app_failure (manager, app);
608
 
                } else {
609
 
                        g_warning ("Error on restarting session managed app: %s", error->message);
610
 
                }
611
 
                g_clear_error (&error);
612
 
        }
 
648
        _restart_app (manager, app);
613
649
 
614
650
        /* For now, we don't do anything with crashes from
615
651
         * non-required apps after they hit the restart limit.
622
658
}
623
659
 
624
660
static void
 
661
app_exited (GsmApp     *app,
 
662
            guchar      exit_code,
 
663
            GsmManager *manager)
 
664
{
 
665
        g_debug ("App %s exited with %d", gsm_app_peek_app_id (app), exit_code);
 
666
 
 
667
        app_event_during_startup (manager, app);
 
668
}
 
669
 
 
670
static void
625
671
app_registered (GsmApp     *app,
626
672
                GsmManager *manager)
627
673
{
628
674
        g_debug ("App %s registered", gsm_app_peek_app_id (app));
629
675
 
630
 
        manager->priv->pending_apps = g_slist_remove (manager->priv->pending_apps, app);
631
 
        g_signal_handlers_disconnect_by_func (app, app_registered, manager);
632
 
 
633
 
        if (manager->priv->pending_apps == NULL) {
634
 
                if (manager->priv->phase_timeout_id > 0) {
635
 
                        g_source_remove (manager->priv->phase_timeout_id);
636
 
                        manager->priv->phase_timeout_id = 0;
637
 
                }
638
 
 
639
 
                end_phase (manager);
640
 
        }
 
676
        app_event_during_startup (manager, app);
641
677
}
642
678
 
643
679
static gboolean
667
703
                        GsmApp *app = a->data;
668
704
                        g_warning ("Application '%s' failed to register before timeout",
669
705
                                   gsm_app_peek_app_id (app));
670
 
                        g_signal_handlers_disconnect_by_func (app, app_registered, manager);
671
706
                        if (is_app_required (manager, app))
672
707
                                on_required_app_failure (manager, app);
673
708
                }
764
799
                 */
765
800
                g_signal_connect (app,
766
801
                                  "exited",
767
 
                                  G_CALLBACK (app_registered),
 
802
                                  G_CALLBACK (app_exited),
768
803
                                  manager);
769
804
                g_signal_connect (app,
770
805
                                  "registered",
1806
1841
{
1807
1842
        gboolean              is_condition_client;
1808
1843
        GsmApp               *app;
1809
 
        GError               *error;
1810
 
        gboolean              res;
1811
1844
        const char           *app_id;
1812
1845
        const char           *startup_id;
1813
1846
        gboolean              app_restart;
1900
1933
 
1901
1934
        g_debug ("GsmManager: restarting app");
1902
1935
 
1903
 
        error = NULL;
1904
 
        res = gsm_app_restart (app, &error);
1905
 
        if (! res) {
1906
 
                if (is_app_required (manager, app)) {
1907
 
                        on_required_app_failure (manager, app);
1908
 
                } else {
1909
 
                        g_warning ("Error on restarting session managed app: %s", error->message);
1910
 
                }
1911
 
                g_clear_error (&error);
1912
 
        }
 
1936
        _restart_app (manager, app);
1913
1937
 
1914
1938
 out:
1915
1939
        g_object_unref (client);
2008
2032
remove_inhibitors_for_connection (GsmManager *manager,
2009
2033
                                  const char *service_name)
2010
2034
{
2011
 
        guint            n_removed;
2012
2035
        RemoveClientData data;
2013
2036
 
2014
2037
        data.service_name = service_name;
2016
2039
 
2017
2040
        debug_inhibitors (manager);
2018
2041
 
2019
 
        n_removed = gsm_store_foreach_remove (manager->priv->inhibitors,
2020
 
                                              (GsmStoreFunc)inhibitor_has_bus_name,
2021
 
                                              &data);
 
2042
        gsm_store_foreach_remove (manager->priv->inhibitors,
 
2043
                                  (GsmStoreFunc)inhibitor_has_bus_name,
 
2044
                                  &data);
2022
2045
}
2023
2046
 
2024
2047
static void
2123
2146
        return manager->priv->failsafe;
2124
2147
}
2125
2148
 
2126
 
static gboolean
2127
 
_client_has_startup_id (const char *id,
2128
 
                        GsmClient  *client,
2129
 
                        const char *startup_id_a)
2130
 
{
2131
 
        const char *startup_id_b;
2132
 
 
2133
 
        startup_id_b = gsm_client_peek_startup_id (client);
2134
 
 
2135
 
        if (IS_STRING_EMPTY (startup_id_b)) {
2136
 
                return FALSE;
2137
 
        }
2138
 
 
2139
 
        return (strcmp (startup_id_a, startup_id_b) == 0);
2140
 
}
2141
 
 
2142
2149
static void
2143
2150
on_client_disconnected (GsmClient  *client,
2144
2151
                        GsmManager *manager)
2225
2232
static void
2226
2233
maybe_save_session (GsmManager *manager)
2227
2234
{
 
2235
        GsmSystem *system;
2228
2236
        GError *error;
 
2237
        gboolean is_login;
2229
2238
 
2230
 
        if (gsm_consolekit_is_current_session_login ())
 
2239
        system = gsm_get_system ();
 
2240
        is_login = gsm_system_is_login_session (system);
 
2241
        g_object_unref (system);
 
2242
        if (is_login)
2231
2243
                return;
2232
2244
 
2233
2245
        /* We only allow session saving when session is running or when
2769
2781
                            guint         status,
2770
2782
                            GsmManager   *manager)
2771
2783
{
2772
 
        GsmConsolekit *consolekit;
 
2784
        GsmSystem *system;
2773
2785
 
2774
 
        consolekit = gsm_get_consolekit ();
2775
 
        gsm_consolekit_set_session_idle (consolekit,
2776
 
                                         (status == GSM_PRESENCE_STATUS_IDLE));
 
2786
        system = gsm_get_system ();
 
2787
        gsm_system_set_session_idle (system,
 
2788
                                     (status == GSM_PRESENCE_STATUS_IDLE));
 
2789
        g_object_unref (system);
2777
2790
}
2778
2791
 
2779
2792
static gboolean
3469
3482
                          gboolean   *shutdown_available,
3470
3483
                          GError    **error)
3471
3484
{
3472
 
        GsmConsolekit *consolekit;
 
3485
        GsmSystem *system;
3473
3486
        gboolean can_suspend;
3474
3487
        gboolean can_hibernate;
3475
3488
 
3483
3496
 
3484
3497
        g_return_val_if_fail (GSM_IS_MANAGER (manager), FALSE);
3485
3498
 
3486
 
        consolekit = gsm_get_consolekit ();
 
3499
        system = gsm_get_system ();
3487
3500
        *shutdown_available = !_log_out_is_locked_down (manager) &&
3488
 
                              (gsm_consolekit_can_stop (consolekit)
3489
 
                               || gsm_consolekit_can_restart (consolekit)
 
3501
                              (gsm_system_can_stop (system)
 
3502
                               || gsm_system_can_restart (system)
3490
3503
                               || can_suspend
3491
3504
                               || can_hibernate);
3492
 
        g_object_unref (consolekit);
 
3505
        g_object_unref (system);
3493
3506
 
3494
3507
        return TRUE;
3495
3508
}