38
38
#include <nih/logging.h>
39
39
#include <nih/error.h>
41
#include <nih-dbus/dbus_error.h>
42
#include <nih-dbus/dbus_proxy.h>
43
#include <nih-dbus/errors.h>
44
#include <nih-dbus/dbus_connection.h>
46
#include "dbus/upstart.h"
48
#include "com.ubuntu.Upstart.h"
44
53
/* Prototypes for option functions */
45
54
int env_option (NihOption *option, const char *arg);
56
NihDBusProxy * upstart_open (const void *parent)
57
__attribute__ ((warn_unused_result));
59
int restart_upstart (void)
60
__attribute__ ((warn_unused_result));
103
* @parent: parent object for new proxy.
105
* Opens a connection to the Upstart init daemon and returns a proxy
106
* to the manager object. If @dest_name is not NULL, a connection is
107
* instead opened to the system bus and the proxy linked to the
108
* well-known name given.
110
* If @parent is not NULL, it should be a pointer to another object
111
* which will be used as a parent for the returned proxy. When all
112
* parents of the returned proxy are freed, the returned proxy will
115
* Returns: newly allocated D-Bus proxy or NULL on raised error.
118
upstart_open (const void *parent)
120
DBusError dbus_error;
121
DBusConnection *connection;
122
NihDBusProxy * upstart;
124
dbus_error_init (&dbus_error);
126
connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
128
nih_dbus_error_raise (dbus_error.name, dbus_error.message);
129
dbus_error_free (&dbus_error);
133
dbus_connection_set_exit_on_disconnect (connection, FALSE);
134
dbus_error_free (&dbus_error);
136
upstart = nih_dbus_proxy_new (parent, connection,
137
DBUS_SERVICE_UPSTART,
141
dbus_connection_unref (connection);
145
upstart->auto_start = FALSE;
147
/* Drop initial reference now the proxy holds one */
148
dbus_connection_unref (connection);
156
* Request Upstart restart itself.
158
* Returns: 0 on SUCCESS, -1 on raised error.
161
restart_upstart (void)
163
nih_local NihDBusProxy *upstart = NULL;
164
DBusPendingCall *ret;
166
upstart = upstart_open (NULL);
172
* Ask Upstart to restart itself using the async interface to
173
* avoid the client-side complaining if and when it detects that
174
* Upstart has severed all connections to perform the re-exec.
176
ret = upstart_restart (upstart, NULL, NULL, NULL, 0);
178
/* We don't care about the return code, but we have to keep
179
* the compiler happy.
181
if (ret != (DBusPendingCall *)TRUE)
177
ret = kill (1, SIGTERM);
179
nih_error_raise_system ();
277
/* If /sbin/init is not Upstart, just exit non-zero */
278
ret = restart_upstart ();
182
281
nih_assert_not_reached ();