~lightdm-team/lightdm/1.4

« back to all changes in this revision

Viewing changes to src/plymouth.c

  • Committer: Robert Ancell
  • Date: 2014-03-13 02:15:38 UTC
  • Revision ID: robert.ancell@canonical.com-20140313021538-u2mxfxrrfw5u58ic
Tags: 1.4.7
Releasing 1.4.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
    is_active = FALSE;
 
87
    plymouth_run_command ("deactivate", NULL);
 
88
}
 
89
 
 
90
void
 
91
plymouth_quit (gboolean retain_splash)
 
92
{
 
93
    have_pinged = TRUE;
 
94
    is_running = FALSE;
 
95
    if (retain_splash)
 
96
        plymouth_run_command ("quit --retain-splash", NULL);
 
97
    else
 
98
        plymouth_run_command ("quit", NULL);
 
99
}