20788N/Acommit c7791f293660c22fd699020ff1ec1ac83ad94afa
20788N/AAuthor: Halton Huo <halton.huo@sun.com>
20788N/ADate: Fri Nov 27 21:30:58 2009 +0800
20788N/A
20788N/A gdm-08-fbconsole.diff (rework)
20788N/A
20788N/Adiff --git a/acconfig.h b/acconfig.h
20788N/Aindex 7a625d2..db32ec0 100644
20788N/A--- a/acconfig.h
20788N/A+++ b/acconfig.h
20788N/A@@ -14,6 +14,8 @@
20788N/A #undef HAVE_CHPASS
20788N/A #undef HAVE_CLEARENV
20788N/A #undef HAVE_CRYPT
20788N/A+#undef FBCONSOLE
20788N/A+#undef HAVE_FBCONSOLE
20788N/A #undef HAVE_GETTEXT
20788N/A #undef HAVE_LC_MESSAGES
20788N/A #undef HAVE_LIBSM
20788N/Adiff --git a/configure.ac b/configure.ac
20788N/Aindex 76b88a0..e6d0e6a 100644
20788N/A--- a/configure.ac
20788N/A+++ b/configure.ac
20788N/A@@ -1025,6 +1025,16 @@ fi
20788N/A AC_SUBST(XEVIE_OPTION)
20788N/A AC_DEFINE_UNQUOTED(XEVIE_OPTION,"$XEVIE_OPTION",[Define xevie option])
20788N/A
20788N/A+# Check for Solaris VT and fbconsole support
20788N/A+#
20788N/A+AC_CHECK_HEADERS(sys/vt.h)
20788N/A+
20788N/A+AC_PATH_PROG([FBCONSOLE], [fbconsole], no, [$PATH:/usr/X11/bin:/usr/bin])
20788N/A+if test x$FBCONSOLE != xno ; then
20788N/A+ AC_DEFINE(HAVE_FBCONSOLE)
20788N/A+ AC_DEFINE_UNQUOTED([FBCONSOLE], "$FBCONSOLE", [fbconsole program])
20788N/A+fi
20788N/A+
20788N/A dnl ---------------------------------------------------------------------------
20788N/A dnl - Check for audit framework
20788N/A dnl ---------------------------------------------------------------------------
20788N/Adiff --git a/daemon/gdm-server.c b/daemon/gdm-server.c
20788N/Aindex 6408d04..c4e3f93 100644
20788N/A--- a/daemon/gdm-server.c
20788N/A+++ b/daemon/gdm-server.c
20788N/A@@ -39,6 +39,12 @@
20788N/A #include <glib/gstdio.h>
20788N/A #include <glib-object.h>
20788N/A
20788N/A+#ifdef HAVE_FBCONSOLE
20788N/A+#ifdef HAVE_SYS_VT_H
20788N/A+#include <sys/vt.h>
20788N/A+#endif
20788N/A+#endif
20788N/A+
20788N/A #include <dbus/dbus-glib.h>
20788N/A
20788N/A #include <X11/Xlib.h> /* for Display */
20788N/A@@ -69,6 +75,7 @@ struct GdmServerPrivate
20788N/A {
20788N/A char *command;
20788N/A GPid pid;
20788N/A+ GPid fbconsolepid;
20788N/A
20788N/A int priority;
20788N/A char *user_name;
20788N/A@@ -120,6 +127,128 @@ static void gdm_server_finalize (GObject *object);
20788N/A
20788N/A G_DEFINE_TYPE (GdmServer, gdm_server, G_TYPE_OBJECT)
20788N/A
20788N/A+#ifdef HAVE_FBCONSOLE
20788N/A+static void
20788N/A+gdm_exec_fbconsole (GdmServer *server)
20788N/A+{
20788N/A+ gboolean run_fbconsole;
20788N/A+ char *argv[6];
20788N/A+
20788N/A+ run_fbconsole = FALSE;
20788N/A+
20788N/A+ if (server->priv->fbconsolepid == 0) {
20788N/A+
20788N/A+ g_debug ("Checking if fbconsole should be started");
20788N/A+
20788N/A+ if (strcmp (server->priv->display_device, "/dev/console") == 0) {
20788N/A+ int fd;
20788N/A+#ifdef HAVE_SYS_VT_H
20788N/A+ int vtstat;
20788N/A+#endif
20788N/A+
20788N/A+ g_debug ("Running on console");
20788N/A+
20788N/A+ /* If no VT, then run fbconsole */
20788N/A+ run_fbconsole = TRUE;
20788N/A+
20788N/A+ /* Set run_fbconsole as TRUE since Xsun
20788N/A+ does not support VT at all */
20788N/A+ char *x_server;
20788N/A+ char *out;
20788N/A+ char *command;
20788N/A+ char **arr;
20788N/A+ char **arr1;
20788N/A+ int status;
20788N/A+ int i;
20788N/A+ gboolean res;
20788N/A+ GError *error;
20788N/A+
20788N/A+ error = NULL;
20788N/A+ out = NULL;
20788N/A+ command = g_strdup ("svcprop svc:/application/x11/x11-server");
20788N/A+
20788N/A+ res = g_spawn_command_line_sync (command,
20788N/A+ &out,
20788N/A+ NULL,
20788N/A+ &status,
20788N/A+ &error);
20788N/A+ g_free (command);
20788N/A+
20788N/A+ if (! res) {
20788N/A+ g_warning ("Could not get options/server of FMRI x11-server: %s", error->message);
20788N/A+ g_error_free (error);
20788N/A+ g_free (out);
20788N/A+ }
20788N/A+
20788N/A+ x_server = NULL;
20788N/A+ arr = g_strsplit (out,"\n", -1);
20788N/A+ i = 0;
20788N/A+ while (arr [i++] != NULL) {
20788N/A+ if (g_str_has_prefix (arr[i], "options/server")) {
20788N/A+ arr1 = g_strsplit (arr[i], " ", -1);
20788N/A+ x_server = g_strdup (arr1[2]);
20788N/A+ g_strfreev (arr1);
20788N/A+ break;
20788N/A+ }
20788N/A+ }
20788N/A+ g_strfreev (arr);
20788N/A+
20788N/A+ if (g_str_has_suffix (x_server, "Xsun")) {
20788N/A+ run_fbconsole = TRUE;
20788N/A+ } else {
20788N/A+
20788N/A+#ifdef HAVE_SYS_VT_H
20788N/A+ fd = open ("/dev/vt/0", O_WRONLY);
20788N/A+ if (fd > 0) {
20788N/A+ if (ioctl (fd, VT_ENABLED, &vtstat) == 0) {
20788N/A+ if (vtstat == 1) {
20788N/A+ g_debug ("VT is enabled, so not forking fbconsole");
20788N/A+ run_fbconsole = FALSE;
20788N/A+ }
20788N/A+ }
20788N/A+ }
20788N/A+
20788N/A+#endif
20788N/A+ }
20788N/A+
20788N/A+ g_free (x_server);
20788N/A+
20788N/A+ if (run_fbconsole == TRUE) {
20788N/A+ g_debug ("VT is not enabled, so fork fbconsole");
20788N/A+ }
20788N/A+
20788N/A+ } else {
20788N/A+ g_debug ("Using %s and not on console, so not forking fbconsole",
20788N/A+ server->priv->display_device ? server->priv->display_device : "(null)");
20788N/A+ }
20788N/A+ }
20788N/A+
20788N/A+ if (run_fbconsole == FALSE) {
20788N/A+ return;
20788N/A+ }
20788N/A+
20788N/A+ argv[0] = FBCONSOLE;
20788N/A+ argv[1] = "-n";
20788N/A+ argv[2] = "-d";
20788N/A+ argv[3] = server->priv->display_name;
20788N/A+ argv[4] = NULL;
20788N/A+
20788N/A+ g_debug ("Forking fbconsole");
20788N/A+
20788N/A+ server->priv->fbconsolepid = fork ();
20788N/A+ if (server->priv->fbconsolepid == 0) {
20788N/A+ execv (argv[0], argv);
20788N/A+
20788N/A+ g_debug ("Can not start fallback console: %s",
20788N/A+ strerror (errno));
20788N/A+ _exit (0);
20788N/A+ }
20788N/A+ if (server->priv->fbconsolepid == -1) {
20788N/A+ g_debug ("Can not start fallback console");
20788N/A+ }
20788N/A+}
20788N/A+#endif
20788N/A+
20788N/A static char *
20788N/A _gdm_server_query_ck_for_display_device (GdmServer *server)
20788N/A {
20788N/A@@ -165,6 +294,10 @@ gdm_server_get_display_device (GdmServer *server)
20788N/A g_object_notify (G_OBJECT (server), "display-device");
20788N/A }
20788N/A
20788N/A+#ifdef HAVE_FBCONSOLE
20788N/A+ gdm_exec_fbconsole (server);
20788N/A+#endif
20788N/A+
20788N/A return g_strdup (server->priv->display_device);
20788N/A }
20788N/A
20788N/A@@ -733,6 +866,15 @@ gdm_server_stop (GdmServer *server)
20788N/A {
20788N/A int res;
20788N/A
20788N/A+#ifdef HAVE_FBCONSOLE
20788N/A+ /* Kill fbconsole if it is running */
20788N/A+ if (server->priv->fbconsolepid > 0) {
20788N/A+ g_debug ("Killing fbconsole");
20788N/A+ kill (server->priv->fbconsolepid, SIGTERM);
20788N/A+ }
20788N/A+ server->priv->fbconsolepid = 0;
20788N/A+#endif
20788N/A+
20788N/A if (server->priv->pid <= 1) {
20788N/A return TRUE;
20788N/A }
20788N/A@@ -933,6 +1075,7 @@ gdm_server_init (GdmServer *server)
20788N/A server->priv->pid = -1;
20788N/A server->priv->command = NULL;
20788N/A server->priv->log_dir = g_strdup (LOGDIR);
20788N/A+ server->priv->fbconsolepid = 0;
20788N/A
20788N/A add_ready_handler (server);
20788N/A }