Skip to content

Commit

Permalink
clean up error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Feb 2, 2018
1 parent 3a75145 commit fcc0574
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/modules/proto_detail/proto_detail_file.c
Expand Up @@ -357,10 +357,14 @@ static int work_exists(proto_detail_file_t *inst, int fd)
if (fr_event_filter_insert(inst, inst->el, fd, FR_EVENT_FILTER_VNODE,
&funcs, NULL, inst) < 0) {
PERROR("Failed adding work socket to event loop");
close(fd);
goto detach;
}

/*
* Remember this for later.
*/
inst->vnode_fd = fd;

/*
* Yuck.
*/
Expand Down Expand Up @@ -407,18 +411,19 @@ static int work_exists(proto_detail_file_t *inst, int fd)

if (!fr_schedule_socket_add(inst->parent->sc, listen)) {
error:
if (fr_event_fd_delete(inst->el, fd, FR_EVENT_FILTER_VNODE) < 0) {
PERROR("Failed removing DELETE callback on add");
if ((inst->vnode_fd >= 0) &&
(fr_event_fd_delete(inst->el, inst->vnode_fd, FR_EVENT_FILTER_VNODE) < 0)) {
PERROR("Failed removing DELETE callback when opening work file");
}

if (opened) {
(void) listen->app_io->close(listen->app_io_instance);
listen = NULL;
} else {
close(fd);
}

detach:
close(fd); /* our FD for the work file */

if (listen) (void) listen->app_io->detach(listen->app_io_instance);
talloc_free(listen);
return -1;
Expand All @@ -429,8 +434,6 @@ static int work_exists(proto_detail_file_t *inst, int fd)
*/
work->free_on_close = true;

inst->vnode_fd = fd;

return 0;
}

Expand Down Expand Up @@ -490,6 +493,8 @@ static void work_init(proto_detail_file_t *inst)
goto delay;
}

rad_assert(inst->vnode_fd < 0);

/*
* See if there is a "detail.work" file. If not, try to
* rename an existing file to "detail.work".
Expand Down Expand Up @@ -697,6 +702,7 @@ static int mod_bootstrap(void *instance, CONF_SECTION *cs)
* We need this for the lock.
*/
inst->mode = O_RDWR;
inst->vnode_fd = -1;

if (inst->retransmit) {
FR_INTEGER_BOUND_CHECK("limit.initial_retransmission_time", inst->irt, >=, 1);
Expand Down

0 comments on commit fcc0574

Please sign in to comment.