tags 387001 patch
thanks

On Mon, 2006-09-11 at 17:53 +0200, Tilman Koschnick wrote:
> Now, I always get the "logged out" syslog entry, but every now and then,
> check_ups fails to parse the response. I guess there is a race condition
> between check_ups parsing the answer to the GET VAR query and upsd
> answering the LOGOUT query.

The attached patch should do away with this problem; check_ups works now
fine in my installation.
=== plugins/check_ups.c
==================================================================
--- plugins/check_ups.c	(revision 2)
+++ plugins/check_ups.c	(revision 4)
@@ -393,13 +393,13 @@
 	/*  char command[MAX_INPUT_BUFFER]; */
 	char temp_buffer[MAX_INPUT_BUFFER];
 	char send_buffer[MAX_INPUT_BUFFER];
-	char *ptr;
+	char *ptr, *end = NULL;
 	int len;
 
 	*buf=0;
 	
 	/* create the command string to send to the UPS daemon */
-	sprintf (send_buffer, "GET VAR %s %s\n", ups_name, varname);
+	sprintf (send_buffer, "GET VAR %s %s\nLOGOUT\n", ups_name, varname);
 
 	/* send the command to the daemon and get a response back */
 	if (process_tcp_request
@@ -433,6 +433,9 @@
 	}
 
 	ptr = temp_buffer + strlen (varname) + strlen (ups_name) + 6;
+	end = strchr(ptr, '\n');
+	if (end)
+		*end = 0;
 	len = strlen(ptr);
 	if (len < 2 || ptr[0] != '"' || ptr[len-1] != '"') {
 		printf ("%s\n", _("Error: unable to parse variable"));

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to