Navigation Menu

Skip to content

Commit

Permalink
core: make sure to close connection fd when we fail to activate a per…
Browse files Browse the repository at this point in the history
…-connection service

Fixes: systemd#2993 systemd#2691
  • Loading branch information
poettering committed Apr 29, 2016
1 parent 7f2fbbf commit 3e7a1f5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/service.c
Expand Up @@ -180,7 +180,7 @@ static int service_set_main_pid(Service *s, pid_t pid) {
return 0;
}

static void service_close_socket_fd(Service *s) {
void service_close_socket_fd(Service *s) {
assert(s);

s->socket_fd = asynchronous_close(s->socket_fd);
Expand Down
1 change: 1 addition & 0 deletions src/core/service.h
Expand Up @@ -198,6 +198,7 @@ struct Service {
extern const UnitVTable service_vtable;

int service_set_socket_fd(Service *s, int fd, struct Socket *socket, bool selinux_context_net);
void service_close_socket_fd(Service *s);

const char* service_restart_to_string(ServiceRestart i) _const_;
ServiceRestart service_restart_from_string(const char *s) _pure_;
Expand Down
6 changes: 5 additions & 1 deletion src/core/socket.c
Expand Up @@ -2010,8 +2010,12 @@ static void socket_enter_running(Socket *s, int cfd) {
s->n_connections++;

r = manager_add_job(UNIT(s)->manager, JOB_START, UNIT(service), JOB_REPLACE, &error, NULL);
if (r < 0)
if (r < 0) {
/* We failed to activate the new service, but it still exists. Let's make sure the service
* closes and forgets the connection fd again, immediately. */
service_close_socket_fd(service);
goto fail;
}

/* Notify clients about changed counters */
unit_add_to_dbus_queue(UNIT(s));
Expand Down

0 comments on commit 3e7a1f5

Please sign in to comment.