Back to index

lightdm  1.3.2
plymouth.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010-2011 Robert Ancell.
00003  * Author: Robert Ancell <robert.ancell@canonical.com>
00004  * 
00005  * This program is free software: you can redistribute it and/or modify it under
00006  * the terms of the GNU General Public License as published by the Free Software
00007  * Foundation, either version 3 of the License, or (at your option) any later
00008  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
00009  * license.
00010  */
00011 
00012 #include <stdlib.h>
00013 #include <sys/wait.h>
00014 
00015 #include "plymouth.h"
00016 
00017 static gboolean have_pinged = FALSE;
00018 static gboolean have_checked_active_vt = FALSE;
00019 
00020 static gboolean is_running = FALSE;
00021 static gboolean is_active = FALSE;
00022 static gboolean has_active_vt = FALSE;
00023 
00024 static gboolean
00025 plymouth_run_command (const gchar *command, gint *exit_status)
00026 {
00027     gchar *command_line;
00028     gboolean result;
00029     GError *error = NULL;
00030 
00031     command_line = g_strdup_printf ("plymouth %s", command);
00032     result = g_spawn_command_line_sync (command_line, NULL, NULL, exit_status, &error);
00033 
00034     if (error)
00035         g_debug ("Could not run %s: %s", command_line, error->message);
00036     g_clear_error (&error);
00037 
00038     g_free (command_line);
00039 
00040     return result;
00041 }
00042 
00043 static gboolean
00044 plymouth_command_returns_true (gchar *command)
00045 {
00046     gint exit_status;
00047     if (!plymouth_run_command (command, &exit_status))
00048         return FALSE;
00049     return WIFEXITED (exit_status) && WEXITSTATUS (exit_status) == 0;
00050 }
00051 
00052 gboolean
00053 plymouth_get_is_running (void)
00054 {
00055     if (!have_pinged)
00056     {
00057         have_pinged = TRUE;
00058         is_running = plymouth_command_returns_true ("--ping");
00059         is_active = is_running;
00060     }
00061 
00062     return is_running;
00063 }
00064 
00065 gboolean
00066 plymouth_get_is_active (void)
00067 {
00068     return plymouth_get_is_running () && is_active;
00069 }
00070 
00071 gboolean
00072 plymouth_has_active_vt (void)
00073 {
00074     if (!have_checked_active_vt)
00075     {
00076         have_checked_active_vt = TRUE;
00077         has_active_vt = plymouth_command_returns_true ("--has-active-vt");
00078     }
00079 
00080     return has_active_vt;
00081 }
00082 
00083 void
00084 plymouth_deactivate (void)
00085 {
00086     is_active = FALSE;
00087     plymouth_run_command ("deactivate", NULL);
00088 }
00089 
00090 void
00091 plymouth_quit (gboolean retain_splash)
00092 {
00093     have_pinged = TRUE;
00094     is_running = FALSE;
00095     if (retain_splash)
00096         plymouth_run_command ("quit --retain-splash", NULL);
00097     else
00098         plymouth_run_command ("quit", NULL);
00099 }