James Hunt has proposed merging lp:~jamesodhunt/upstart/bug-1083723 into 
lp:upstart.

Requested reviews:
  Upstart Reviewers (upstart-reviewers)

For more details, see:
https://code.launchpad.net/~jamesodhunt/upstart/bug-1083723/+merge/136959

Stop 'telinit u' causing problems for non-Upstart init (LP: #1083723).
-- 
https://code.launchpad.net/~jamesodhunt/upstart/bug-1083723/+merge/136959
Your team Upstart Reviewers is requested to review the proposed merge of 
lp:~jamesodhunt/upstart/bug-1083723 into lp:upstart.
=== modified file 'util/Makefile.am'
--- util/Makefile.am	2011-06-01 11:13:42 +0000
+++ util/Makefile.am	2012-11-29 15:21:25 +0000
@@ -71,7 +71,8 @@
 	utmp.c utmp.h \
 	sysv.c sysv.h
 nodist_telinit_SOURCES = \
-	$(com_ubuntu_Upstart_OUTPUTS)
+	$(com_ubuntu_Upstart_OUTPUTS) \
+	$(com_ubuntu_Upstart_Instance_OUTPUTS)
 telinit_LDADD = \
 	$(LTLIBINTL) \
 	$(NIH_LIBS) \

=== modified file 'util/man/telinit.8'
--- util/man/telinit.8	2012-11-07 14:28:34 +0000
+++ util/man/telinit.8	2012-11-29 15:21:25 +0000
@@ -71,10 +71,16 @@
 .BR U " or " u
 to request that the
 .BR init (8)
-daemon re-execute itself.  This is necessary when upgrading the
+daemon re-execute itself.  This is necessary when upgrading the Upstart
 .BR init (8)
 daemon itself or any of its dependent system libraries
 to ensure disks can be unmounted cleanly on shutdown.
+
+Note that if the init daemon is
+.I not
+Upstart, this option will have no effect on the running
+.BR init (8)
+daemon.
 .\"
 .SH OPTIONS
 .TP

=== modified file 'util/telinit.c'
--- util/telinit.c	2009-07-09 11:50:19 +0000
+++ util/telinit.c	2012-11-29 15:21:25 +0000
@@ -38,6 +38,15 @@
 #include <nih/logging.h>
 #include <nih/error.h>
 
+#include <nih-dbus/dbus_error.h>
+#include <nih-dbus/dbus_proxy.h>
+#include <nih-dbus/errors.h>
+#include <nih-dbus/dbus_connection.h>
+
+#include "dbus/upstart.h"
+
+#include "com.ubuntu.Upstart.h"
+
 #include "sysv.h"
 
 
@@ -83,6 +92,96 @@
 	return 0;
 }
 
+/**
+ * upstart_open:
+ * @parent: parent object for new proxy.
+ *
+ * Opens a connection to the Upstart init daemon and returns a proxy
+ * to the manager object. If @dest_name is not NULL, a connection is
+ * instead opened to the system bus and the proxy linked to the
+ * well-known name given.
+ *
+ * Error messages are output to standard error.
+ *
+ * If @parent is not NULL, it should be a pointer to another object
+ * which will be used as a parent for the returned proxy.  When all
+ * parents of the returned proxy are freed, the returned proxy will
+ * also be freed.
+ *
+ * Returns: newly allocated D-Bus proxy or NULL on error.
+ **/
+NihDBusProxy *
+upstart_open (const void *parent)
+{
+	DBusError       dbus_error;
+	DBusConnection *connection;
+	NihDBusProxy *  upstart;
+
+	dbus_error_init (&dbus_error);
+
+	connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
+	if (! connection) {
+		dbus_error_free (&dbus_error);
+		return NULL;
+	}
+
+	dbus_connection_set_exit_on_disconnect (connection, FALSE);
+	dbus_error_free (&dbus_error);
+
+	upstart = nih_dbus_proxy_new (parent, connection,
+				      DBUS_SERVICE_UPSTART,
+				      DBUS_PATH_UPSTART,
+				      NULL, NULL);
+	if (! upstart) {
+		NihError *err;
+
+		err = nih_error_get ();
+		nih_free (err);
+
+		dbus_connection_unref (connection);
+		return NULL;
+	}
+
+	upstart->auto_start = FALSE;
+
+	/* Drop initial reference now the proxy holds one */
+	dbus_connection_unref (connection);
+
+	return upstart;
+}
+
+/**
+ * init_is_upstart:
+ *
+ * Determine if PID 1 is actually Upstart. The strategy adopted is to
+ * attempt to connect to Upstart via D-Bus and query its version. If
+ * this is entirely successful, we must be using Upstart. If any step
+ * fails, assume we are not.
+ *
+ * Returns: TRUE if PID 1 is Upstart, else FALSE.
+ **/
+int
+init_is_upstart (void)
+{
+	nih_local NihDBusProxy *upstart = NULL;
+	nih_local char *        version = NULL;
+	NihError *              err;
+
+	upstart = upstart_open (NULL);
+	if (! upstart)
+		return FALSE;
+
+	if (upstart_get_version_sync (NULL, upstart, &version) < 0)
+		goto error;
+
+	return TRUE;
+
+error:
+	err = nih_error_get ();
+	nih_free (err);
+
+	return FALSE;
+}
 
 #ifndef TEST
 /**
@@ -107,7 +206,7 @@
 {
 	char **args;
 	int    runlevel;
-	int    ret;
+	int    ret = 0;
 
 	nih_main_init (argv[0]);
 
@@ -174,9 +273,11 @@
 		break;
 	case 'U':
 	case 'u':
-		ret = kill (1, SIGTERM);
-		if (ret < 0)
-			nih_error_raise_system ();
+		if (init_is_upstart ()) {
+			ret = kill (1, SIGTERM);
+			if (ret < 0)
+				nih_error_raise_system ();
+		}
 		break;
 	default:
 		nih_assert_not_reached ();

-- 
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel

Reply via email to