chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
dbus: properly encode job type
[elogind.git]
/
socket.c
diff --git
a/socket.c
b/socket.c
index 1954259b508308b8f8c6dd32eee0c03708e2412a..dd5076552020e9a79918e06f2afcd2873fed2a78 100644
(file)
--- a/
socket.c
+++ b/
socket.c
@@
-5,7
+5,7
@@
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
-#include <sys/poll.h>
+#include <sys/
e
poll.h>
#include <signal.h>
#include "unit.h"
#include <signal.h>
#include "unit.h"
@@
-88,8
+88,11
@@
static int socket_init(Unit *u) {
s->timeout_usec = DEFAULT_TIMEOUT_USEC;
exec_context_init(&s->exec_context);
s->timeout_usec = DEFAULT_TIMEOUT_USEC;
exec_context_init(&s->exec_context);
- if ((r = unit_load_fragment_and_dropin(u)) < 0)
+ if ((r = unit_load_fragment_and_dropin(u)) <= 0) {
+ if (r == 0)
+ r = -ENOENT;
goto fail;
goto fail;
+ }
if (!(t = unit_name_change_suffix(unit_id(u), ".service"))) {
r = -ENOMEM;
if (!(t = unit_name_change_suffix(unit_id(u), ".service"))) {
r = -ENOMEM;
@@
-140,6
+143,7
@@
static void socket_dump(Unit *u, FILE *f, const char *prefix) {
char *prefix2;
assert(s);
char *prefix2;
assert(s);
+ assert(f);
prefix2 = strappend(prefix, "\t");
if (!prefix2)
prefix2 = strappend(prefix, "\t");
if (!prefix2)
@@
-281,7
+285,7
@@
static int socket_watch_fds(Socket *s) {
if (p->fd < 0)
continue;
if (p->fd < 0)
continue;
- if ((r = unit_watch_fd(UNIT(s), p->fd, POLLIN, &p->fd_watch)) < 0)
+ if ((r = unit_watch_fd(UNIT(s), p->fd,
E
POLLIN, &p->fd_watch)) < 0)
goto fail;
}
goto fail;
}
@@
-339,7
+343,7
@@
static void socket_set_state(Socket *s, SocketState state) {
if (state != SOCKET_LISTENING)
socket_unwatch_fds(s);
if (state != SOCKET_LISTENING)
socket_unwatch_fds(s);
- log_debug("%s chang
ing
%s → %s", unit_id(UNIT(s)), state_string_table[old_state], state_string_table[state]);
+ log_debug("%s chang
ed
%s → %s", unit_id(UNIT(s)), state_string_table[old_state], state_string_table[state]);
unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state]);
}
unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state]);
}
@@
-392,13
+396,13
@@
static void socket_enter_stop_post(Socket *s, bool success) {
if (!success)
s->failure = true;
if (!success)
s->failure = true;
- if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_POST])) {
-
+ if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_POST]))
if ((r = socket_spawn(s, s->control_command, true, &s->control_pid)) < 0)
goto fail;
if ((r = socket_spawn(s, s->control_command, true, &s->control_pid)) < 0)
goto fail;
- socket_set_state(s, SOCKET_STOP_POST);
- } else
+ socket_set_state(s, SOCKET_STOP_POST);
+
+ if (!s->control_command)
socket_enter_dead(s, true);
return;
socket_enter_dead(s, true);
return;
@@
-425,9
+429,11
@@
static void socket_enter_signal(Socket *s, SocketState state, bool success) {
r = -errno;
goto fail;
}
r = -errno;
goto fail;
}
+ }
- socket_set_state(s, state);
- } else
+ socket_set_state(s, state);
+
+ if (s->control_pid <= 0)
socket_enter_dead(s, true);
return;
socket_enter_dead(s, true);
return;
@@
-448,13
+454,13
@@
static void socket_enter_stop_pre(Socket *s, bool success) {
if (!success)
s->failure = true;
if (!success)
s->failure = true;
- if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_PRE])) {
-
+ if ((s->control_command = s->exec_command[SOCKET_EXEC_STOP_PRE]))
if ((r = socket_spawn(s, s->control_command, true, &s->control_pid)) < 0)
goto fail;
if ((r = socket_spawn(s, s->control_command, true, &s->control_pid)) < 0)
goto fail;
- socket_set_state(s, SOCKET_STOP_PRE);
- } else
+ socket_set_state(s, SOCKET_STOP_PRE);
+
+ if (!s->control_command)
socket_enter_stop_post(s, true);
return;
socket_enter_stop_post(s, true);
return;
@@
-489,15
+495,15
@@
static void socket_enter_start_post(Socket *s) {
goto fail;
}
goto fail;
}
- if ((s->control_command = s->exec_command[SOCKET_EXEC_START_POST])) {
-
+ if ((s->control_command = s->exec_command[SOCKET_EXEC_START_POST]))
if ((r = socket_spawn(s, s->control_command, true, &s->control_pid)) < 0) {
log_warning("%s failed to run start-post executable: %s", unit_id(UNIT(s)), strerror(-r));
goto fail;
}
if ((r = socket_spawn(s, s->control_command, true, &s->control_pid)) < 0) {
log_warning("%s failed to run start-post executable: %s", unit_id(UNIT(s)), strerror(-r));
goto fail;
}
- socket_set_state(s, SOCKET_START_POST);
- } else
+ socket_set_state(s, SOCKET_START_POST);
+
+ if (!s->control_command)
socket_enter_listening(s);
return;
socket_enter_listening(s);
return;
@@
-510,13
+516,13
@@
static void socket_enter_start_pre(Socket *s) {
int r;
assert(s);
int r;
assert(s);
- if ((s->control_command = s->exec_command[SOCKET_EXEC_START_PRE])) {
-
+ if ((s->control_command = s->exec_command[SOCKET_EXEC_START_PRE]))
if ((r = socket_spawn(s, s->control_command, true, &s->control_pid)) < 0)
goto fail;
if ((r = socket_spawn(s, s->control_command, true, &s->control_pid)) < 0)
goto fail;
- socket_set_state(s, SOCKET_START_PRE);
- } else
+ socket_set_state(s, SOCKET_START_PRE);
+
+ if (!s->control_command)
socket_enter_start_post(s);
return;
socket_enter_start_post(s);
return;
@@
-628,7
+634,7
@@
static void socket_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
log_debug("Incoming traffic on %s", unit_id(u));
log_debug("Incoming traffic on %s", unit_id(u));
- if (events != POLLIN)
+ if (events !=
E
POLLIN)
socket_enter_stop_pre(s, false);
socket_enter_running(s);
socket_enter_stop_pre(s, false);
socket_enter_running(s);
@@
-650,7
+656,7
@@
static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
exec_status_fill(&s->control_command->exec_status, pid, code, status);
s->control_pid = 0;
exec_status_fill(&s->control_command->exec_status, pid, code, status);
s->control_pid = 0;
- log_debug("%s control process exited, code=%s status=%i", unit_id(u), sigchld_code(code), status);
+ log_debug("%s control process exited, code=%s status=%i", unit_id(u), sigchld_code
_to_string
(code), status);
if (s->control_command->command_next &&
(success || (s->state == SOCKET_EXEC_STOP_PRE || s->state == SOCKET_EXEC_STOP_POST))) {
if (s->control_command->command_next &&
(success || (s->state == SOCKET_EXEC_STOP_PRE || s->state == SOCKET_EXEC_STOP_POST))) {
@@
-779,6
+785,17
@@
int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds) {
return 0;
}
return 0;
}
+void socket_notify_service_dead(Socket *s) {
+ assert(s);
+
+ /* The service is dead. Dang. */
+
+ if (s->state == SOCKET_RUNNING) {
+ log_debug("%s got notified about service death.", unit_id(UNIT(s)));
+ socket_enter_listening(s);
+ }
+}
+
const UnitVTable socket_vtable = {
.suffix = ".socket",
const UnitVTable socket_vtable = {
.suffix = ".socket",