]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/plymouth.c
Correctly free seat module data on exit
[sojka/lightdm.git] / src / plymouth.c
1 /*
2  * Copyright (C) 2010-2011 Robert Ancell.
3  * Author: Robert Ancell <robert.ancell@canonical.com>
4  *
5  * This program is free software: you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License as published by the Free Software
7  * Foundation, either version 3 of the License, or (at your option) any later
8  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9  * license.
10  */
11
12 #include <stdlib.h>
13 #include <sys/wait.h>
14
15 #include "plymouth.h"
16
17 static gboolean have_pinged = FALSE;
18 static gboolean have_checked_active_vt = FALSE;
19
20 static gboolean is_running = FALSE;
21 static gboolean is_active = FALSE;
22 static gboolean has_active_vt = FALSE;
23
24 static gboolean
25 plymouth_run_command (const gchar *command, gint *exit_status)
26 {
27     gchar *command_line;
28     gboolean result;
29     GError *error = NULL;
30
31     command_line = g_strdup_printf ("plymouth %s", command);
32     result = g_spawn_command_line_sync (command_line, NULL, NULL, exit_status, &error);
33
34     if (error)
35         g_debug ("Could not run %s: %s", command_line, error->message);
36     g_clear_error (&error);
37
38     g_free (command_line);
39
40     return result;
41 }
42
43 static gboolean
44 plymouth_command_returns_true (gchar *command)
45 {
46     gint exit_status;
47     if (!plymouth_run_command (command, &exit_status))
48         return FALSE;
49     return WIFEXITED (exit_status) && WEXITSTATUS (exit_status) == 0;
50 }
51
52 gboolean
53 plymouth_get_is_running (void)
54 {
55     if (!have_pinged)
56     {
57         have_pinged = TRUE;
58         is_running = plymouth_command_returns_true ("--ping");
59         is_active = is_running;
60     }
61
62     return is_running;
63 }
64
65 gboolean
66 plymouth_get_is_active (void)
67 {
68     return plymouth_get_is_running () && is_active;
69 }
70
71 gboolean
72 plymouth_has_active_vt (void)
73 {
74     if (!have_checked_active_vt)
75     {
76         have_checked_active_vt = TRUE;
77         has_active_vt = plymouth_command_returns_true ("--has-active-vt");
78     }
79
80     return has_active_vt;
81 }
82
83 void
84 plymouth_deactivate (void)
85 {
86     g_debug ("Deactivating Plymouth");
87     is_active = FALSE;
88     plymouth_run_command ("deactivate", NULL);
89 }
90
91 void
92 plymouth_quit (gboolean retain_splash)
93 {
94     if (retain_splash)
95         g_debug ("Quitting Plymouth; retaining splash");
96     else
97         g_debug ("Quitting Plymouth");
98
99     have_pinged = TRUE;
100     is_running = FALSE;
101     if (retain_splash)
102         plymouth_run_command ("quit --retain-splash", NULL);
103     else
104         plymouth_run_command ("quit", NULL);
105 }