aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--fetchmail.c10
-rw-r--r--socket.c40
3 files changed, 36 insertions, 15 deletions
diff --git a/NEWS b/NEWS
index b6e3052e..b111e727 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ fetchmail-4.7.4 ():
* HTML cleanup in design notes and FAQ, thanks to Byrial Jensen.
* Don't get message sizes when --check is on.
* Supply our own strerror() if system doesn't have one.
+* Gunther Leber's cleanup for the plugin/plugout code/
There are 248 people on fetchmail-friends and 336 on fetchmail-announce.
diff --git a/fetchmail.c b/fetchmail.c
index 88e1a311..79edffe5 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -217,12 +217,12 @@ int main (int argc, char **argv)
/* set up to do lock protocol */
#define FETCHMAIL_PIDFILE "fetchmail.pid"
- xalloca(tmpbuf, char *, !getuid?
- (strlen(PID_DIR) + strlen(FETCHMAIL_PIDFILE) + 2):
- (strlen(home) + strlen(FETCHMAIL_PIDFILE) + 3));
- if (!getuid())
+ if (!getuid()) {
+ xalloca(tmpbuf, char *,
+ strlen(PID_DIR) + strlen(FETCHMAIL_PIDFILE) + 2);
sprintf(tmpbuf, "%s/%s", PID_DIR, FETCHMAIL_PIDFILE);
- else {
+ } else {
+ xalloca(tmpbuf, char *, strlen(home) + strlen(FETCHMAIL_PIDFILE) + 3);
strcpy(tmpbuf, home);
strcat(tmpbuf, "/.");
strcat(tmpbuf, FETCHMAIL_PIDFILE);
diff --git a/socket.c b/socket.c
index 9af6b7cf..5e9602cf 100644
--- a/socket.c
+++ b/socket.c
@@ -55,17 +55,37 @@ static int handle_plugin(const char *host,
error(0, 0, _("fetchmail: socketpair failed: %s(%d)"),strerror(errno),errno);
return -1;
}
- if (!fork())
- {
- dup2(fds[0],0);
- dup2(fds[0],1);
- if (outlevel >= O_VERBOSE)
- error(0, 0, _("running %s %s %s"), plugin, host, service);
- execlp(plugin,plugin,host,service,0);
- error(0, 0, _("execl(%s) failed: %s (%d)"),
- plugin, strerror(errno), errno);
- exit(0);
+ switch (fork()) {
+ case -1:
+ /* error */
+ error(0, 0, _("fetchmail: fork failed: %s(%d)"),
+ strerror(errno), errno);
+ return -1;
+ break;
+ case 0: /* child */
+ /* fds[1] is the parent's end; close it for proper EOF
+ ** detection */
+ (void) close(fds[1]);
+ if ( (dup2(fds[0],0) == -1) || (dup2(fds[0],1) == -1) ) {
+ error(0, 0, _("fetchmail: dup2 failed: %s(%d)"),
+ strerror(errno), errno);
+ exit(1);
+ }
+ /* fds[0] is now connected to 0 and 1; close it */
+ (void) close(fds[0]);
+ if (outlevel >= O_VERBOSE)
+ error(0, 0, _("running %s %s %s"), plugin, host, service);
+ execlp(plugin,plugin,host,service,0);
+ error(0, 0, _("execl(%s) failed: %s (%d)"),
+ plugin, strerror(errno), errno);
+ exit(0);
+ break;
+ default: /* parent */
+ /* NOP */
+ break;
}
+ /* fds[0] is the child's end; close it for proper EOF detection */
+ (void) close(fds[0]);
return fds[1];
}
#endif /* HAVE_SOCKETPAIR */