[hobbit] darwin "ps" display parsing in OS-X Tiger causes all procs to vanish in display

Henrik Stoerner henrik at hswn.dk
Tue Jul 25 23:57:00 CEST 2006


On Tue, Jul 25, 2006 at 04:24:36PM -0500, Brodie, Kent wrote:
> Um, ok, so the parsing works, but that breaks a browser by attempting to
> do the <....

This patch should make it show up correctly.


Regards,
Henrik

-------------- next part --------------
--- hobbitd/hobbitd_client.c	2006/07/20 16:06:41	1.94
+++ hobbitd/hobbitd_client.c	2006/07/25 21:42:46
@@ -720,7 +720,41 @@
 	}
 
 	/* And the full ps output for those who want it */
-	if (pslistinprocs) addtostatus(psstr);
+	if (pslistinprocs) {
+		/*
+		 * NB: Process listings may contain HTML special characters.
+		 *     We must encode these for HTML, cf.
+		 *     http://www.w3.org/TR/html4/charset.html#h-5.3.2
+		 */
+		char *inp, *tagpos;
+
+		inp = psstr;
+		do {
+			tagpos = inp + strcspn(inp, "<>&\"");
+			switch (*tagpos) {
+			  case '<':
+				*tagpos = '\0'; addtostatus(inp); addtostatus("<"); *tagpos = '<';
+				inp = tagpos + 1;
+				break;
+			  case '>':
+				*tagpos = '\0'; addtostatus(inp); addtostatus(">"); *tagpos = '>';
+				inp = tagpos + 1;
+				break;
+			  case '&':
+				*tagpos = '\0'; addtostatus(inp); addtostatus("&"); *tagpos = '&';
+				inp = tagpos + 1;
+				break;
+			  case '\"':
+				*tagpos = '\0'; addtostatus(inp); addtostatus("""); *tagpos = '\"';
+				inp = tagpos + 1;
+				break;
+			  default:
+				/* We're done */
+				addtostatus(inp); inp = NULL;
+				break;
+			}
+		} while (inp && *inp);
+	}
 
 	if (fromline && !localmode) addtostatus(fromline);
 	finish_status();


More information about the Xymon mailing list