~xnox/ubuntu/raring/upstart/autopkgtest2

« back to all changes in this revision

Viewing changes to util/telinit.c

  • Committer: Steve Langasek
  • Date: 2012-12-10 09:23:29 UTC
  • mfrom: (0.8.52 debian)
  • Revision ID: steve.langasek@canonical.com-20121210092329-87pwlsh7zvv8zkd0
Merge packaging fixes from Debian, along with the new upstream version 1.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <nih/logging.h>
39
39
#include <nih/error.h>
40
40
 
 
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>
 
45
 
 
46
#include "dbus/upstart.h"
 
47
 
 
48
#include "com.ubuntu.Upstart.h"
 
49
 
41
50
#include "sysv.h"
42
51
 
43
52
 
44
53
/* Prototypes for option functions */
45
54
int env_option (NihOption *option, const char *arg);
46
55
 
 
56
NihDBusProxy * upstart_open (const void *parent)
 
57
        __attribute__ ((warn_unused_result));
 
58
 
 
59
int restart_upstart (void)
 
60
        __attribute__ ((warn_unused_result));
 
61
 
47
62
 
48
63
/**
49
64
 * extra_env:
83
98
        return 0;
84
99
}
85
100
 
 
101
/**
 
102
 * upstart_open:
 
103
 * @parent: parent object for new proxy.
 
104
 *
 
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.
 
109
 *
 
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
 
113
 * also be freed.
 
114
 *
 
115
 * Returns: newly allocated D-Bus proxy or NULL on raised error.
 
116
 **/
 
117
NihDBusProxy *
 
118
upstart_open (const void *parent)
 
119
{
 
120
        DBusError       dbus_error;
 
121
        DBusConnection *connection;
 
122
        NihDBusProxy *  upstart;
 
123
 
 
124
        dbus_error_init (&dbus_error);
 
125
 
 
126
        connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
 
127
        if (! connection) {
 
128
                nih_dbus_error_raise (dbus_error.name, dbus_error.message);
 
129
                dbus_error_free (&dbus_error);
 
130
                return NULL;
 
131
        }
 
132
 
 
133
        dbus_connection_set_exit_on_disconnect (connection, FALSE);
 
134
        dbus_error_free (&dbus_error);
 
135
 
 
136
        upstart = nih_dbus_proxy_new (parent, connection,
 
137
                                      DBUS_SERVICE_UPSTART,
 
138
                                      DBUS_PATH_UPSTART,
 
139
                                      NULL, NULL);
 
140
        if (! upstart) {
 
141
                dbus_connection_unref (connection);
 
142
                return NULL;
 
143
        }
 
144
 
 
145
        upstart->auto_start = FALSE;
 
146
 
 
147
        /* Drop initial reference now the proxy holds one */
 
148
        dbus_connection_unref (connection);
 
149
 
 
150
        return upstart;
 
151
}
 
152
 
 
153
/**
 
154
 * restart_upstart:
 
155
 *
 
156
 * Request Upstart restart itself.
 
157
 *
 
158
 * Returns: 0 on SUCCESS, -1 on raised error.
 
159
 **/
 
160
int
 
161
restart_upstart (void)
 
162
{
 
163
        nih_local NihDBusProxy *upstart = NULL;
 
164
        DBusPendingCall        *ret;
 
165
 
 
166
        upstart = upstart_open (NULL);
 
167
        if (! upstart)
 
168
                return -1;
 
169
 
 
170
        /* Fire and forget:
 
171
         *
 
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.
 
175
         */
 
176
        ret = upstart_restart (upstart, NULL, NULL, NULL, 0);
 
177
 
 
178
        /* We don't care about the return code, but we have to keep
 
179
         * the compiler happy.
 
180
         */
 
181
        if (ret != (DBusPendingCall *)TRUE)
 
182
                return 0;
 
183
 
 
184
        return 0;
 
185
}
86
186
 
87
187
#ifndef TEST
88
188
/**
107
207
{
108
208
        char **args;
109
209
        int    runlevel;
110
 
        int    ret;
 
210
        int    ret = 0;
111
211
 
112
212
        nih_main_init (argv[0]);
113
213
 
174
274
                break;
175
275
        case 'U':
176
276
        case 'u':
177
 
                ret = kill (1, SIGTERM);
178
 
                if (ret < 0)
179
 
                        nih_error_raise_system ();
 
277
                /* If /sbin/init is not Upstart, just exit non-zero */
 
278
                ret = restart_upstart ();
180
279
                break;
181
280
        default:
182
281
                nih_assert_not_reached ();