changeset 18939:10df63e74ed6

lib-master: Code cleanup - split master_status_update() to two functions. No functional changes.
author Timo Sirainen <tss@iki.fi>
date Mon, 17 Aug 2015 12:51:43 +0300
parents 38c3d7b44dd5
children ec912a6039f5
files src/lib-master/master-service.c
diffstat 1 files changed, 41 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- 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,