$OpenBSD: patch-plugins_check_users_c,v 1.1 2012/06/28 23:10:48 sthen Exp $

we have no utmpx, so for now return to ugly 1.4.15 code to parse who(1) output

--- plugins/check_users.c.orig	Wed Jun 27 18:32:47 2012
+++ plugins/check_users.c	Thu Jun 28 22:49:10 2012
@@ -35,8 +35,8 @@ const char *copyright = "2000-2007";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
+#include "popen.h"
 #include "utils.h"
-#include <utmpx.h>
 
 #define possibly_set(a,b) ((a) == 0 ? (b) : 0)
 
@@ -52,8 +52,8 @@ main (int argc, char **argv)
 {
 	int users = -1;
 	int result = STATE_UNKNOWN;
+	char input_buffer[MAX_INPUT_BUFFER];
 	char *perf;
-	struct utmpx *putmpx;
 
 	setlocale (LC_ALL, "");
 	bindtextdomain (PACKAGE, LOCALEDIR);
@@ -67,18 +67,41 @@ main (int argc, char **argv)
 	if (process_arguments (argc, argv) == ERROR)
 		usage4 (_("Could not parse arguments"));
 
-	users = 0;
+	/* run the command */
+	child_process = spopen (WHO_COMMAND);
+	if (child_process == NULL) {
+		printf (_("Could not open pipe: %s\n"), WHO_COMMAND);
+		return STATE_UNKNOWN;
+}
 
-	/* get currently logged users from utmpx */
-	setutxent ();
+	child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
+	if (child_stderr == NULL)
+		printf (_("Could not open stderr for %s\n"), WHO_COMMAND);
 
-	while ((putmpx = getutxent ()) != NULL)
-		if (putmpx->ut_type == USER_PROCESS)
+	users = 0;
+
+	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
+		/* increment 'users' on all lines except total user count */
+		if (input_buffer[0] != '#') {
 			users++;
+			continue;
+		}
 
-	endutxent ();
+		/* get total logged in users */
+		if (sscanf (input_buffer, _("# users=%d"), &users) == 1)
+			break;
+	}
 
-	/* check the user count against warning and critical thresholds */
+	/* check STDERR */
+	if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
+		result = possibly_set (result, STATE_UNKNOWN);
+	(void) fclose (child_stderr);
+
+	/* close the pipe */
+	if (spclose (child_process))
+		result = possibly_set (result, STATE_UNKNOWN);
+
+	/* else check the user count against warning and critical thresholds */
 	if (users > cusers)
 		result = STATE_CRITICAL;
 	else if (users > wusers)
