46
46
/* Prototypes for static functions */
47
static int control_open_sock (void)
48
__attribute__ ((warn_unused_result));
49
static void control_reopen (void);
50
static void control_close_handler (void *data, NihIo *io);
51
static void control_error_handler (void *data, NihIo *io);
47
static void control_error_handler (void *data, NihIo *io);
52
48
static int control_job_start (void *data, pid_t pid,
53
49
UpstartMessageType type, const char *name);
54
50
static int control_job_stop (void *data, pid_t pid,
116
* Opens an upstart control socket for the current process (which should be
117
* pid #1), and marks it to be closed when exec() is called so that it isn't
118
* leaked to child processes.
120
* Returns: newly opened socket, or -1 on raised error;
123
control_open_sock (void)
127
sock = upstart_open ();
131
if (nih_io_set_cloexec (sock) < 0) {
142
112
* Opens the control socket and associates it with an NihIo structure
153
sock = control_open_sock ();
123
sock = upstart_open ();
127
if (nih_io_set_cloexec (sock) < 0) {
157
132
while (! (control_io = nih_io_reopen (NULL, sock, NIH_IO_MESSAGE,
158
133
(NihIoReader)upstart_message_reader,
159
control_close_handler,
160
control_error_handler,
134
NULL, control_error_handler,
161
135
message_handlers))) {
195
* This function is used to reopen a control socket that has been closed,
196
* or on which an error has occurred. The error is hopefully cleared, and
197
* we can again continue receiving messages.
199
* This is all done without losing the state or queues in the NihIo
200
* structure, so if there's no error, the send queue is not lost
202
* If we fail to reopen the socket, an error is logged and we're left with
206
control_reopen (void)
210
nih_assert (control_io != NULL);
212
close (control_io->watch->fd);
214
sock = control_open_sock ();
218
err = nih_error_get ();
219
nih_error ("%s: %s: %s", _("Unable to re-open control socket"),
220
err->message, _("you may need to re-exec init"));
223
nih_free (control_io);
229
control_io->watch->fd = sock;
234
* control_close_handler:
236
* @io: NihIo structure closed.
238
* This function is called should the control socket be unexpectedly closed;
239
* we log the problem and attempt to re-open the control socket.
242
control_close_handler (void *data,
245
nih_assert (io != NULL);
246
nih_assert (io == control_io);
248
nih_warn (_("Control socket closed unexpectedly"));
253
167
* control_error_handler:
254
168
* @data: ignored,
255
169
* @io: NihIo structure on which an error occurred.
257
171
* This function is called should an error occur while reading from or
258
172
* writing to a descriptor. We handle errors that we recognise, otherwise
259
* we log them and attempt to re-open the control socket.
173
* we log them and carry on.
262
176
control_error_handler (void *data,