gdm r6459 - in branches/gnome-2-20: . daemon gui/modules



Author: bcameron
Date: Wed Sep  3 18:21:17 2008
New Revision: 6459
URL: http://svn.gnome.org/viewvc/gdm?rev=6459&view=rev

Log:
2008-09-03  Brian Cameron  <brian cameron sun com>

        * acconfig.h, configure.ac: Rip out ctrun integration and instead
          manage SMF so that when the slave daemon is forked, it is spawned
          in a separate contract.  This ensures that the user session, all 
          GDM GUI programs, and the PAM interaction all happen in the user
          session contract.  This helps to ensure that if the Xserver crashes,
          it doesn't cause the GDM service to restart.  This only affects
          Solaris.
        * gui/modules/dwellmouselistener.c, gui/modules/keymouselistener.c,
          daemon/slave.c: Remove ctrun integration.
        * daemon/display.c: Add logic so slave daemon is forked in a separate
          SMF contract.


Modified:
   branches/gnome-2-20/ChangeLog
   branches/gnome-2-20/acconfig.h
   branches/gnome-2-20/configure.ac
   branches/gnome-2-20/daemon/display.c
   branches/gnome-2-20/daemon/slave.c
   branches/gnome-2-20/gui/modules/dwellmouselistener.c
   branches/gnome-2-20/gui/modules/keymouselistener.c

Modified: branches/gnome-2-20/acconfig.h
==============================================================================
--- branches/gnome-2-20/acconfig.h	(original)
+++ branches/gnome-2-20/acconfig.h	Wed Sep  3 18:21:17 2008
@@ -16,7 +16,6 @@
 #undef HAVE_CHPASS
 #undef HAVE_CLEARENV
 #undef HAVE_CRYPT
-#undef HAVE_CTRUN
 #undef HAVE_DEFOPEN
 #undef HAVE_FBCONSOLE
 #undef HAVE_GETTEXT
@@ -33,6 +32,7 @@
 #undef HAVE_SETENV
 #undef HAVE_SETRESUID
 #undef HAVE_SHADOW
+#undef HAVE_SMF_CONTRACTS
 #undef HAVE_SOLARIS_XINERAMA
 #undef HAVE_STPCPY
 #undef HAVE_SYS_SOCKIO_H

Modified: branches/gnome-2-20/configure.ac
==============================================================================
--- branches/gnome-2-20/configure.ac	(original)
+++ branches/gnome-2-20/configure.ac	Wed Sep  3 18:21:17 2008
@@ -1018,18 +1018,12 @@
 			    EXTRA_DAEMON_LIBS="$EXTRA_DAEMON_LIBS -lsecdb"
 			    EXTRA_GREETER_LIBS="$EXTRA_GREETER_LIBS -lsecdb"])
 
-# ctrun support for Solaris
+# Check for Solaris SMF contract support
 #
-AC_ARG_WITH(ctrun,
-  [  --with-ctrun=[yes/no]  Define to yes if GDM is started as a svcadm(1M) service,  [default=no]],,
-  with_ctrun=no)
-
-if test x$with_ctrun != xno ; then
-   AC_PATH_PROG(HAVE_CTRUN,ctrun,no,/usr/bin)
-   if test "x$HAVE_CTRUN" != "xno" ; then
-      AC_DEFINE(HAVE_CTRUN)
-   fi
-fi
+AC_MSG_CHECKING(for Solaris SMF contract support)
+AC_CHECK_LIB(contract, ct_tmpl_activate, [
+		     	AC_DEFINE(HAVE_SMF_CONTRACTS)
+			    EXTRA_DAEMON_LIBS="$EXTRA_DAEMON_LIBS -lcontract" ])
 
 # check for the nologin location
 AC_PATH_PROG(NOLOGIN, nologin, /sbin/nologin)

Modified: branches/gnome-2-20/daemon/display.c
==============================================================================
--- branches/gnome-2-20/daemon/display.c	(original)
+++ branches/gnome-2-20/daemon/display.c	Wed Sep  3 18:21:17 2008
@@ -28,6 +28,13 @@
 #include <fcntl.h>
 #include <errno.h>
 
+#ifdef HAVE_SMF_CONTRACTS
+#include <sys/ctfs.h>
+#include <sys/contract.h>
+#include <sys/contract/process.h>
+#include <libcontract.h>
+#endif
+
 #include <glib/gi18n.h>
 
 #include "gdm.h"
@@ -318,6 +325,140 @@
     d->slavepid = 0;
 }
 
+#ifdef HAVE_SMF_CONTRACTS
+static int contracts_fd = -1;
+
+void
+contracts_pre_fork ()
+{
+   const char *errmsg = "opening process contract template";
+
+	/*
+	 * On failure, just continue since it is better to start with
+	 * children in the same contract than to not start them at all.
+	 */
+	if (contracts_fd == -1) {
+		if ((contracts_fd = open64 (CTFS_ROOT "/process/template",
+					    O_RDWR)) == -1)
+			goto exit;
+
+		errmsg = "setting contract terms";
+		if ((errno = ct_pr_tmpl_set_param (contracts_fd, CT_PR_PGRPONLY)))
+			goto exit;
+
+		if ((errno = ct_tmpl_set_informative (contracts_fd, CT_PR_EV_HWERR)))
+			goto exit;
+
+		if ((errno = ct_pr_tmpl_set_fatal (contracts_fd, CT_PR_EV_HWERR)))
+			goto exit;
+
+		if ((errno = ct_tmpl_set_critical (contracts_fd, 0)))
+			goto exit;
+	}
+
+	errmsg = "setting active template";
+	if ((errno = ct_tmpl_activate (contracts_fd)))
+		goto exit;
+
+	gdm_debug ("Set active contract");
+	return;
+
+exit:
+	if (contracts_fd != -1)
+		(void) close (contracts_fd);
+
+	contracts_fd = -1;
+
+	if (errno) {
+		gdm_debug (
+			"Error setting up active contract template: %s while %s",
+			strerror (errno), errmsg);
+	}
+}
+
+void
+contracts_post_fork_child ()
+{
+	/* Clear active template so no new contracts are created on fork */
+	if (contracts_fd == -1)
+		return;
+
+	if ((errno = (ct_tmpl_clear (contracts_fd)))) {
+		gdm_debug (
+			"Error clearing active contract template (child): %s",
+			strerror (errno));
+	} else {
+		gdm_debug ("Cleared active contract template (child)");
+	}
+
+	(void) close (contracts_fd);
+
+	contracts_fd = -1;
+}
+
+void
+contracts_post_fork_parent (int fork_succeeded)
+{
+	char path[PATH_MAX];
+	int cfd;
+	ct_stathdl_t status;
+	ctid_t latest;
+
+	/* Clear active template, abandon latest contract. */
+	if (contracts_fd == -1)
+		return;
+
+	if ((errno = ct_tmpl_clear (contracts_fd)))
+		gdm_debug ("Error while clearing active contract template: %s",
+			   strerror (errno));
+	else
+		gdm_debug ("Cleared active contract template (parent)");
+
+	if (!fork_succeeded)
+		return;
+
+	if ((cfd = open64 (CTFS_ROOT "/process/latest", O_RDONLY)) == -1) {
+		gdm_debug ("Error getting latest contract: %s",
+			   strerror(errno));
+		return;
+	}
+
+	if ((errno = ct_status_read (cfd, CTD_COMMON, &status)) != 0) {
+		gdm_debug ("Error getting latest contract ID: %s",
+			   strerror(errno));
+		(void) close (cfd);
+		return;
+	}
+
+	latest = ct_status_get_id (status);
+	ct_status_free (status);
+	(void) close (cfd);
+
+
+	if ((snprintf (path, PATH_MAX, CTFS_ROOT "/all/%ld/ctl", latest)) >=
+	     PATH_MAX) {
+		gdm_debug ("Error opening the latest contract ctl file: %s",
+			   strerror (ENAMETOOLONG));
+		return;
+	}
+
+	cfd = open64 (path, O_WRONLY);
+	if (cfd == -1) {
+		gdm_debug ("Error opening the latest contract ctl file: %s",
+			   strerror (errno));
+		return;
+	}
+ 
+	if ((errno = ct_ctl_abandon (cfd)))
+		gdm_debug ("Error abandoning latest contract: %s",
+			   strerror (errno));
+	else
+		gdm_debug ("Abandoned latest contract");
+
+	(void) close (cfd);
+}
+#endif HAVE_SMF_CONTRACTS
+
 /**
  * gdm_display_manage:
  * @d: Pointer to a GdmDisplay struct
@@ -359,12 +500,20 @@
 
     gdm_debug ("Forking slave process");
 
+#ifdef HAVE_SMF_CONTRACTS
+    contracts_pre_fork ();
+#endif
+
     /* Fork slave process */
     pid = d->slavepid = fork ();
 
     switch (pid) {
 
     case 0:
+#ifdef HAVE_SMF_CONTRACTS
+        contracts_post_fork_child ();
+#endif
+
 	setpgid (0, 0);
 
 	/* Make the slave it's own leader.  This 1) makes killing -pid of
@@ -427,13 +576,17 @@
 	break;
     }
 
+#ifdef HAVE_SMF_CONTRACTS
+    contracts_post_fork_parent ((pid > 0));
+#endif
+
     /* invalidate chosen hostname */
     g_free (d->chosen_hostname);
     d->chosen_hostname = NULL;
 
-    /* use_chooser can only be temporary, if you want it permanent you set it up
-       in the server definition with "chooser=true" and it will get set up during
-       server command line resolution */
+    /* use_chooser can only be temporary, if you want it permanent you set it
+       up in the server definition with "chooser=true" and it will get set up
+       during server command line resolution */
     d->use_chooser = FALSE;
 
     if (SERVER_IS_LOCAL (d)) {

Modified: branches/gnome-2-20/daemon/slave.c
==============================================================================
--- branches/gnome-2-20/daemon/slave.c	(original)
+++ branches/gnome-2-20/daemon/slave.c	Wed Sep  3 18:21:17 2008
@@ -3851,10 +3851,6 @@
 
 	fullexec = g_string_new (NULL);
 
-#ifdef HAVE_CTRUN
-	g_string_append (fullexec, "/usr/bin/ctrun -l child -i none ");
-#endif
-
 	if (sessionexec != NULL) {
 		const char *basexsession = gdm_daemon_config_get_value_string (GDM_KEY_BASE_XSESSION);
 		char **bxvec = g_strsplit (basexsession, " ", -1);
@@ -5791,9 +5787,6 @@
 	gchar **argv = NULL;
 	gint status;
 	char *x_servers_file;
-#ifdef HAVE_CTRUN
-	char *ctrun;
-#endif
 
 	if G_UNLIKELY (!d || ve_string_empty (dir))
 		return EXIT_SUCCESS;
@@ -5920,15 +5913,7 @@
 		if ( ! ve_string_empty (d->theme_name))
 			g_setenv ("GDM_GTK_THEME", d->theme_name, TRUE);
 
-#ifdef HAVE_CTRUN
-		ctrun = g_strdup_printf (
-			"/bin/sh -c \"/usr/bin/ctrun -l child -i none %s\"",
-			script);
-		g_shell_parse_argv (ctrun, NULL, &argv, NULL);
-		g_free (ctrun);
-#else
 		g_shell_parse_argv (script, NULL, &argv, NULL);
-#endif
 
 		VE_IGNORE_EINTR (execv (argv[0], argv));
 		g_strfreev (argv);

Modified: branches/gnome-2-20/gui/modules/dwellmouselistener.c
==============================================================================
--- branches/gnome-2-20/gui/modules/dwellmouselistener.c	(original)
+++ branches/gnome-2-20/gui/modules/dwellmouselistener.c	Wed Sep  3 18:21:17 2008
@@ -554,26 +554,11 @@
 
 		for (act_li=curr_binding->actions; act_li != NULL; act_li=act_li->next) {
 			gchar *action = (gchar *)act_li->data;
-#ifdef HAVE_CTRUN
-			gchar *ctrun;
-#endif
 
 			g_return_val_if_fail (action != NULL, TRUE);
 
-#ifdef HAVE_CTRUN
-			ctrun = g_strdup_printf (
-				"/bin/sh -c \"/usr/bin/ctrun -l child -i none %s\"",
-				action);
-			if (!g_shell_parse_argv (ctrun, NULL, &argv, NULL)) {
-				g_free (ctrun);
-				continue;
-			}
-				
-			g_free (ctrun);
-#else
 			if (!g_shell_parse_argv (action, NULL, &argv, NULL))
 				continue;
-#endif
 
 			envp = get_exec_environment (gtk_window_get_screen
 						     (GTK_WINDOW(widget)));

Modified: branches/gnome-2-20/gui/modules/keymouselistener.c
==============================================================================
--- branches/gnome-2-20/gui/modules/keymouselistener.c	(original)
+++ branches/gnome-2-20/gui/modules/keymouselistener.c	Wed Sep  3 18:21:17 2008
@@ -901,26 +901,11 @@
 			for (act_li = curr_gesture->actions;
 			     act_li != NULL; act_li = act_li->next) {
 				gchar *action = (gchar *)act_li->data;
-#ifdef HAVE_CTRUN
-				gchar *ctrun;
-#endif
 
 				g_return_val_if_fail (action != NULL, GDK_FILTER_CONTINUE);
 
-#ifdef HAVE_CTRUN
-				ctrun = g_strdup_printf (
-					"/bin/sh -c \"/usr/bin/ctrun -l child -i none %s\"",
-					action);
-				if (!g_shell_parse_argv (ctrun, NULL, &argv, NULL)) {
-					g_free (ctrun);
-					continue;
-				}
-
-				g_free (ctrun);
-#else
 				if (!g_shell_parse_argv (action, NULL, &argv, NULL))
 					continue;
-#endif
 
 				envp = get_exec_environment (xevent);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]