# HG changeset patch # User Timo Sirainen # Date 1439805103 -10800 # Node ID 10df63e74ed629a78ca29174e2954623dc580f41 # Parent 38c3d7b44dd5b263336ea102ed9e1318366cddf6 lib-master: Code cleanup - split master_status_update() to two functions. No functional changes. diff -r 38c3d7b44dd5 -r 10df63e74ed6 src/lib-master/master-service.c --- a/src/lib-master/master-service.c Sun Aug 16 13:22:14 2015 +0200 +++ b/src/lib-master/master-service.c Mon Aug 17 12:51:43 2015 +0300 @@ -991,9 +991,48 @@ return FALSE; } +static void +master_status_send(struct master_service *service, bool important_update) +{ + ssize_t ret; + + if (service->to_status != NULL) + timeout_remove(&service->to_status); + + ret = write(MASTER_STATUS_FD, &service->master_status, + sizeof(service->master_status)); + if (ret == sizeof(service->master_status)) { + /* success */ + if (service->io_status_write != NULL) { + /* delayed important update sent successfully */ + io_remove(&service->io_status_write); + } + service->last_sent_status_time = ioloop_time; + service->last_sent_status_avail_count = + service->master_status.available_count; + service->initial_status_sent = TRUE; + } else if (ret >= 0) { + /* shouldn't happen? */ + i_error("write(master_status_fd) returned %d", (int)ret); + service->master_status.pid = 0; + } else if (errno != EAGAIN) { + /* failure */ + if (errno != EPIPE) + i_error("write(master_status_fd) failed: %m"); + service->master_status.pid = 0; + } else if (important_update) { + /* reader is busy, but it's important to get this notification + through. send it when possible. */ + if (service->io_status_write == NULL) { + service->io_status_write = + io_add(MASTER_STATUS_FD, IO_WRITE, + master_status_update, service); + } + } +} + void master_status_update(struct master_service *service) { - ssize_t ret; bool important_update; if ((service->flags & MASTER_SERVICE_FLAG_UPDATE_PROCTITLE) != 0 && @@ -1030,40 +1069,7 @@ io_remove(&service->io_status_write); return; } - - if (service->to_status != NULL) - timeout_remove(&service->to_status); - - ret = write(MASTER_STATUS_FD, &service->master_status, - sizeof(service->master_status)); - if (ret == sizeof(service->master_status)) { - /* success */ - if (service->io_status_write != NULL) { - /* delayed important update sent successfully */ - io_remove(&service->io_status_write); - } - service->last_sent_status_time = ioloop_time; - service->last_sent_status_avail_count = - service->master_status.available_count; - service->initial_status_sent = TRUE; - } else if (ret >= 0) { - /* shouldn't happen? */ - i_error("write(master_status_fd) returned %d", (int)ret); - service->master_status.pid = 0; - } else if (errno != EAGAIN) { - /* failure */ - if (errno != EPIPE) - i_error("write(master_status_fd) failed: %m"); - service->master_status.pid = 0; - } else if (important_update) { - /* reader is busy, but it's important to get this notification - through. send it when possible. */ - if (service->io_status_write == NULL) { - service->io_status_write = - io_add(MASTER_STATUS_FD, IO_WRITE, - master_status_update, service); - } - } + master_status_send(service, important_update); } bool version_string_verify(const char *line, const char *service_name,