[Pkg-wmaker-commits] [wmbiff] 24/32: debug messages cleanup; start handling pclose errors; remove open() function pointer assignment; #include fix

Doug Torrance dtorrance-guest at moszumanska.debian.org
Thu Aug 20 03:00:38 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to tag wmbiff_0_3_8
in repository wmbiff.

commit 3848fc3f5876e1d3bad127cb5d2367ad2e4f7dc2
Author: bluehal <bluehal>
Date:   Sat Mar 9 08:50:49 2002 +0000

    debug messages cleanup; start handling pclose errors; remove open() function pointer assignment; #include fix
---
 wmbiff/ShellClient.c | 66 ++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 49 insertions(+), 17 deletions(-)

diff --git a/wmbiff/ShellClient.c b/wmbiff/ShellClient.c
index 6b2774a..b3698d5 100644
--- a/wmbiff/ShellClient.c
+++ b/wmbiff/ShellClient.c
@@ -11,39 +11,70 @@
 #include "Client.h"
 #include <errno.h>
 #include <string.h>
+#include <stdio.h>
 #ifdef USE_DMALLOC
 #include <dmalloc.h>
 #endif
 
+#define SH_DM(pc, lvl, args...) DM(pc, lvl, "shell: " ##args)
+
+/* kind_pclose checks the return value from pclose and prints
+   some nice error messages about it.  ordinarily, this would be 
+   a good idea, but wmbiff has a sigchld handler that reaps 
+   children immediately (needed when spawning other child processes),
+   so no error checking can be done here until that's disabled */
+
+/* TODO: block or unbind sigchld before popen, and reenable on pclose */
+static void kind_pclose(FILE * F, const char *command, Pop3 pc)
+{
+	int exit_status = pclose(F);
+	if (exit_status != 0) {
+		if (exit_status == -1) {
+			/* wmbiff has a sigchld handler already, so wait is likely 
+			   to fail */
+			if (errno != ECHILD) {
+				SH_DM(pc, DEBUG_ERROR, "pclose '%s' failed: %s\n",
+					  command, strerror(errno));
+			}
+		} else {
+			SH_DM(pc, DEBUG_ERROR,
+				  "'%s' exited with non-zero status %d\n", command,
+				  exit_status);
+		}
+	}
+}
+
 int shellCmdCheck(Pop3 pc)
 {
 	FILE *F;
 	int count_status = 0;
 
-	DM(pc, DEBUG_INFO, ">Mailbox: '%s'\n", pc->path);
+	if (pc == NULL)
+		return -1;
+	SH_DM(pc, DEBUG_INFO, ">Mailbox: '%s'\n", pc->path);
 
 	if ((F = popen(pc->path, "r")) == NULL) {
-		DM(pc, DEBUG_ERROR, "popen: error while reading '%s': %s\n",
-		   pc->path, strerror(errno));
+		SH_DM(pc, DEBUG_ERROR, "popen: error while reading '%s': %s\n",
+			  pc->path, strerror(errno));
 		return -1;
 	}
 
 	/* doesn't really need to be handled separately, but it
 	   seems worth an error message */
 	if (fscanf(F, "%d\n", &(count_status)) != 1) {
-		DM(pc, DEBUG_ERROR,
-		   "'%s' returned something other than an integer message count.\n",
-		   pc->path);
-		pclose(F);
+		SH_DM(pc, DEBUG_ERROR,
+			  "'%s' returned something other than an integer message count.\n",
+			  pc->path);
+		kind_pclose(F, pc->path, pc);
 		return -1;
 	}
 
 	pc->TotalMsgs = pc->UnreadMsgs + count_status;
 	pc->UnreadMsgs = count_status;
-	DM(pc, DEBUG_INFO, "from: %d status: %d\n", pc->TotalMsgs,
-	   pc->UnreadMsgs);
+	SH_DM(pc, DEBUG_INFO, "from: %d status: %d\n", pc->TotalMsgs,
+		  pc->UnreadMsgs);
 
-	pclose(F);
+	kind_pclose(F, pc->path, pc);
 	return 0;
 }
 
@@ -56,26 +87,27 @@ int shellCreate(Pop3 pc, const char *str)
 	pc->UnreadMsgs = 0;
 	pc->OldMsgs = -1;
 	pc->OldUnreadMsgs = -1;
-	pc->open = openMailbox;
 	pc->checkMail = shellCmdCheck;
 	reserved1 = str + 6;		/* shell:>:: */
+
 	reserved2 = index(reserved1, ':');
 	if (reserved2 == NULL) {
-		DM(pc, DEBUG_ERROR,
-		   "shell method, unable to parse '%s', expecting ':'", str);
+		SH_DM(pc, DEBUG_ERROR, "unable to parse '%s', expecting ':'", str);
 		return 0;
 	}
 	reserved2++;				/* shell::>: */
+
 	commandline = index(reserved2, ':');
 	if (commandline == NULL) {
-		DM(pc, DEBUG_ERROR,
-		   "shell method, unable to parse '%s', expecting another ':'",
-		   str);
+		SH_DM(pc, DEBUG_ERROR,
+			  "unable to parse '%s', expecting another ':'", str);
 		return 0;
 	}
 	commandline++;				/* shell:::> */
+
+	/* good thing strcpy handles overlapping regions */
 	strcpy(pc->path, commandline);
-	DM(pc, DEBUG_INFO, "shell: path= '%s'\n", commandline);
+	SH_DM(pc, DEBUG_INFO, "path= '%s'\n", commandline);
 	return 0;
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbiff.git



More information about the Pkg-wmaker-commits mailing list