[Nagios-checkins] SF.net SVN: nagios:[2039] nagioscore/trunk/lib

ageric at users.sourceforge.net ageric at users.sourceforge.net
Thu Aug 2 00:46:06 UTC 2012


Revision: 2039
          http://nagios.svn.sourceforge.net/nagios/?rev=2039&view=rev
Author:   ageric
Date:     2012-08-02 00:46:06 +0000 (Thu, 02 Aug 2012)
Log Message:
-----------
lib/worker: Make send_kvvec() return what send() returned

Doing so makes it possible to keep track of and report write errors,
which is naturally crucial, but also helps us keep track of how much
data we've sent, which is really nifty to know when debugging.

Signed-off-by: Andreas Ericsson <ae at op5.se>

Modified Paths:
--------------
    nagioscore/trunk/lib/worker.c
    nagioscore/trunk/lib/worker.h

Modified: nagioscore/trunk/lib/worker.c
===================================================================
--- nagioscore/trunk/lib/worker.c	2012-08-02 00:45:47 UTC (rev 2038)
+++ nagioscore/trunk/lib/worker.c	2012-08-02 00:46:06 UTC (rev 2039)
@@ -96,6 +96,7 @@
 	char msg[4096];
 	int len;
 	va_list ap;
+	int ret;
 
 	va_start(ap, fmt);
 	len = vsnprintf(msg, sizeof(msg) - 1, fmt, ap);
@@ -104,7 +105,9 @@
 		kvvec_addkv(kvv, "job_id", (char *)mkstr("%d", cp->id));
 	}
 	kvvec_addkv_wlen(kvv, "error_msg", 5, msg, len);
-	send_kvvec(master_sd, kvv);
+	ret = send_kvvec(master_sd, kvv);
+	if (ret < 0 && errno == EPIPE)
+		exit_worker();
 	kvvec_destroy(kvv, 0);
 }
 
@@ -157,7 +160,7 @@
 	return ret;
 }
 
-void send_kvvec(int sd, struct kvvec *kvv)
+int send_kvvec(int sd, struct kvvec *kvv)
 {
 	int ret;
 	struct kvvec_buf *kvvb;
@@ -178,22 +181,14 @@
 		 * reason is OOM, in which case the OOM-slayer will
 		 * probably kill us sooner or later.
 		 */
-		return;
+		return 0;
 	}
 
 	/* use bufsize here, as it gets us the nul string delimiter */
 	ret = write(sd, kvvb->buf, kvvb->bufsize);
-	if (ret < 0) {
-		if (errno == EPIPE) {
-			/*
-			 * master has crashed or abandoned us, so we die
-			 * with what grace we can.
-			 */
-			exit_worker();
-		}
-	}
 	free(kvvb->buf);
 	free(kvvb);
+	return ret;
 }
 
 #define kvvec_add_long(kvv, key, value) \
@@ -212,7 +207,7 @@
 {
 	struct kvvec *resp;
 	struct rusage *ru = &cp->rusage;
-	int i;
+	int i, ret;
 
 	resp = kvvec_init(12 + cp->request->kv_pairs); /* how many key/value pairs do we need? */
 
@@ -274,7 +269,9 @@
 		kvvec_addkv(resp, "exited_ok", "0");
 		kvvec_addkv(resp, "error_code", (char *)mkstr("%d", reason));
 	}
-	send_kvvec(master_sd, resp);
+	ret = send_kvvec(master_sd, resp);
+	if (ret < 0 && errno == EPIPE)
+		exit_worker();
 
 	/*
 	 * we mustn't free() the key/value pairs here, as they're all

Modified: nagioscore/trunk/lib/worker.h
===================================================================
--- nagioscore/trunk/lib/worker.h	2012-08-02 00:45:47 UTC (rev 2038)
+++ nagioscore/trunk/lib/worker.h	2012-08-02 00:46:06 UTC (rev 2039)
@@ -66,8 +66,9 @@
  * Send a key/value vector as a bytestream through a socket
  * @param[in] sd The socket descriptor to send to
  * @param kvv The key/value vector to send
+ * @return The number of bytes sent, or -1 on errors
  */
-extern void send_kvvec(int sd, struct kvvec *kvv);
+extern int send_kvvec(int sd, struct kvvec *kvv);
 
 /**
  * Create a short-lived string in stack-allocated memory

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Nagios-commits mailing list