~ubuntu-branches/ubuntu/vivid/unity-greeter/vivid

« back to all changes in this revision

Viewing changes to src/unity-greeter.vala

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2014-04-08 15:57:59 UTC
  • Revision ID: package-import@ubuntu.com-20140408155759-iu1m8ejagfxk5zud
Tags: 14.04.9-0ubuntu1
* New upstream release:
  - Correctly handle SIGTERM and quit cleanly. We were previously not stopping
    the signal and so not cleaning up on exit. This left an upstart process
    for each greeter remaining.
  - If a user has an invalid session, then use the system default session
    (LP: #1303725)
  - Correctly handle sessions not starting

Show diffs side-by-side

added added

removed removed

Lines of Context:
181
181
        ctx.add_class ("lightdm");
182
182
    }
183
183
 
184
 
    public void start_session (string? session, Background bg)
 
184
    public bool start_session (string? session, Background bg)
185
185
    {
186
186
        /* Paint our background onto the root window before we close our own window */
187
187
        var c = new Cairo.Context (background_surface);
191
191
 
192
192
        if (test_mode)
193
193
        {
194
 
                debug ("Successfully logged in!  Quitting...");
195
 
                Gtk.main_quit ();
196
 
        }
197
 
        else
198
 
        {
 
194
            debug ("Successfully logged in! Quitting...");
 
195
            Gtk.main_quit ();
 
196
            return true;
 
197
        }
 
198
 
 
199
        if (!session_is_valid (session))
 
200
        {
 
201
            debug ("Session %s is not available, using system default %s instead", session, greeter.default_session_hint);
 
202
            session = greeter.default_session_hint;
 
203
        }
 
204
 
 
205
        var result = false;
 
206
        try
 
207
        {
 
208
            result = LightDM.greeter_start_session_sync (greeter, session);
 
209
        }
 
210
        catch (Error e)
 
211
        {
 
212
            warning ("Failed to start session: %s", e.message);
 
213
        }
 
214
 
 
215
        if (result)
199
216
            starting_session ();
200
 
            try
201
 
            {
202
 
                greeter.start_session_sync (session);
203
 
            }
204
 
            catch (Error e)
205
 
            {
206
 
                warning ("Failed to start session: %s", e.message);
207
 
            }
208
 
        }
 
217
 
 
218
        return result;
 
219
    }
 
220
 
 
221
    private bool session_is_valid (string? session)
 
222
    {
 
223
        if (session == null)
 
224
            return true;
 
225
 
 
226
        foreach (var s in LightDM.get_sessions ())
 
227
            if (s.key == session)
 
228
                return true;
 
229
 
 
230
        return false;
209
231
    }
210
232
 
211
233
    private bool ready_cb ()
446
468
        Environment.set_variable ("GTK_MODULES", "atk-bridge", false);
447
469
 
448
470
        Pid atspi_pid = 0;
449
 
        Pid indicator_pid = 0;
 
471
        Pid upstart_pid = 0;
450
472
 
451
473
        try
452
474
        {
558
580
                                     null,
559
581
                                     SpawnFlags.SEARCH_PATH,
560
582
                                     null,
561
 
                                     out indicator_pid);
 
583
                                     out upstart_pid);
562
584
            }
563
585
            catch (Error e)
564
586
            {
582
604
        GLib.Unix.signal_add(GLib.ProcessSignal.TERM, () => {
583
605
            debug("Got a SIGTERM");
584
606
            Gtk.main_quit();
585
 
            return false;
 
607
            return true;
586
608
        });
587
609
 
588
610
        debug ("Starting main loop");
589
611
        Gtk.main ();
590
612
 
591
 
        if (indicator_pid != 0)
 
613
        debug ("Cleaning up");
 
614
 
 
615
        if (upstart_pid != 0)
592
616
        {
593
 
            Posix.kill (indicator_pid, Posix.SIGTERM);
 
617
            Posix.kill (upstart_pid, Posix.SIGTERM);
594
618
            int status;
595
 
            Posix.waitpid (indicator_pid, out status, 0);
596
 
            indicator_pid = 0;
 
619
            Posix.waitpid (upstart_pid, out status, 0);
 
620
            if (Process.if_exited (status))
 
621
                debug ("Upstart exited with return value %d", Process.exit_status (status));
 
622
            else
 
623
                debug ("Upstart terminated with signal %d", Process.term_sig (status));
 
624
            upstart_pid = 0;
597
625
        }
598
626
 
599
627
        if (atspi_pid != 0)
601
629
            Posix.kill (atspi_pid, Posix.SIGKILL);
602
630
            int status;
603
631
            Posix.waitpid (atspi_pid, out status, 0);
 
632
            if (Process.if_exited (status))
 
633
                debug ("AT-SPI exited with return value %d", Process.exit_status (status));
 
634
            else
 
635
                debug ("AT-SPI terminated with signal %d", Process.term_sig (status));
604
636
            atspi_pid = 0;
605
637
        }
606
638
 
 
639
        debug ("Exiting");
 
640
 
607
641
        return Posix.EXIT_SUCCESS;
608
642
    }
609
643
}