aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1996-12-17 02:09:51 +0000
committerEric S. Raymond <esr@thyrsus.com>1996-12-17 02:09:51 +0000
commit0922eb1ccb33983bd4ad2d5c38475d56e2e60137 (patch)
tree5d4e126da335d88279e0447feb988a5816f29a63
parentd4009e757f45a4f09bd415cc032b079f316b4c46 (diff)
downloadfetchmail-0922eb1ccb33983bd4ad2d5c38475d56e2e60137.tar.gz
fetchmail-0922eb1ccb33983bd4ad2d5c38475d56e2e60137.tar.bz2
fetchmail-0922eb1ccb33983bd4ad2d5c38475d56e2e60137.zip
Use error() for messages almost everywhere.
svn path=/trunk/; revision=636
-rw-r--r--daemon.c14
-rw-r--r--driver.c70
-rw-r--r--fetchmail.c32
-rw-r--r--fetchmail.h2
-rw-r--r--getpass.c3
-rw-r--r--pop3.c8
-rw-r--r--rcfile_y.y4
-rw-r--r--xmalloc.c7
8 files changed, 76 insertions, 64 deletions
diff --git a/daemon.c b/daemon.c
index 0e48ffb1..036fb62f 100644
--- a/daemon.c
+++ b/daemon.c
@@ -7,6 +7,7 @@
#include <config.h>
#include <stdio.h>
+#include <errno.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -40,6 +41,7 @@
#endif
#include "fetchmail.h"
+#include "tunable.h"
RETSIGTYPE
sigchld_handler (int sig)
@@ -95,7 +97,7 @@ daemonize (const char *logfile, void (*termhook)(int))
group leader */
if ((childpid = fork()) < 0) {
- perror("fork");
+ error(0, errno, "fork");
return(PS_IOERR);
}
else if (childpid > 0)
@@ -108,7 +110,7 @@ daemonize (const char *logfile, void (*termhook)(int))
#if defined(HAVE_SETSID) /* POSIX */
/* POSIX makes this soooo easy to do */
if (setsid() < 0) {
- perror("setsid");
+ error(0, errno, "setsid");
return(PS_IOERR);
}
#elif defined(SIGTSTP) /* BSD */
@@ -127,7 +129,7 @@ daemonize (const char *logfile, void (*termhook)(int))
/* lose controlling tty */
signal(SIGHUP, SIG_IGN);
if ((childpid = fork) < 0) {
- perror("fork");
+ error(0, errno, "fork");
return(PS_IOERR);
}
else if (childpid > 0) {
@@ -151,7 +153,7 @@ nottyDetach:
/* Reopen stdin descriptor on /dev/null */
if ((fd = open("/dev/null", O_RDWR)) < 0) { /* stdin */
- perror("open: /dev/null");
+ error(0, errno, "open: /dev/null");
return(PS_IOERR);
}
@@ -159,11 +161,11 @@ nottyDetach:
fd = open(logfile, O_CREAT|O_WRONLY|O_APPEND, 0777); /* stdout */
else
if (dup(fd) < 0) { /* stdout */
- perror("dup");
+ error(0, errno, "dup");
return(PS_IOERR);
}
if (dup(fd) < 0) { /* stderr */
- perror("dup");
+ error(0, errno, "dup");
return(PS_IOERR);
}
diff --git a/driver.c b/driver.c
index ea9ea8a0..97d6a46e 100644
--- a/driver.c
+++ b/driver.c
@@ -9,6 +9,7 @@
#include <config.h>
#include <stdio.h>
#include <setjmp.h>
+#include <errno.h>
#include <ctype.h>
#include <string.h>
#if defined(STDC_HEADERS)
@@ -157,8 +158,8 @@ static int is_host_alias(const char *name, struct query *ctl)
default:
if (outlevel != O_SILENT)
putchar('\n'); /* terminate the progress message */
- fprintf(stderr,
- "fetchmail: nameserver failure while looking for `%s' during poll of %s.\n",
+ error(0, 0,
+ "nameserver failure while looking for `%s' during poll of %s.",
name, ctl->servernames->id);
ctl->errcount++;
longjmp(restart, 2); /* try again next poll cycle */
@@ -188,8 +189,8 @@ static int is_host_alias(const char *name, struct query *ctl)
case NO_RECOVERY: /* non-recoverable name server error */
case TRY_AGAIN: /* temporary error on authoritative server */
default:
- fprintf(stderr,
- "fetchmail: nameserver failure while looking for `%s' during poll of %s.\n",
+ error(0, 0,
+ "nameserver failure while looking for `%s' during poll of %s.",
name, ctl->servernames->id);
ctl->errcount++;
longjmp(restart, 2); /* try again next poll cycle */
@@ -535,7 +536,7 @@ struct query *ctl; /* query control record */
if (mboxfd < 0)
{
- fprintf(stderr, "fetchmail: MDA open failed\n");
+ error(0, 0, "MDA open failed");
return(PS_IOERR);
}
@@ -549,7 +550,7 @@ struct query *ctl; /* query control record */
if (ctl->mda[0] == '\0' && ((sinkfp = smtp_open(ctl)) == NULL))
{
free_str_list(&xmit_names);
- fprintf(stderr, "fetchmail: SMTP connect failed\n");
+ error(0, 0, "SMTP connect failed");
return(PS_SMTP);
}
@@ -588,13 +589,13 @@ struct query *ctl; /* query control record */
{
bad_addresses++;
idp->val.num = 0;
- fprintf(stderr,
- "fetchmail: SMTP listener doesn't like recipient address `%s'\n", idp->id);
+ error(0, 0,
+ "SMTP listener doesn't like recipient address `%s'", idp->id);
}
if (!good_addresses && SMTP_rcpt(sinkfp, user) != SM_OK)
{
- fprintf(stderr,
- "fetchmail: can't even send to calling user!\n");
+ error(0, 0,
+ "can't even send to calling user!");
return(PS_SMTP);
}
@@ -631,7 +632,7 @@ struct query *ctl; /* query control record */
{
free(headers);
headers = NULL;
- perror("fetchmail: writing RFC822 headers");
+ error(0, errno, "writing RFC822 headers");
if (ctl->mda[0])
{
closemailpipe(mboxfd);
@@ -719,7 +720,7 @@ struct query *ctl; /* query control record */
free(bufp);
if (n < 0)
{
- perror("fetchmail: writing message text");
+ error(0, errno, "writing message text");
if (ctl->mda[0])
{
closemailpipe(mboxfd);
@@ -749,7 +750,7 @@ struct query *ctl; /* query control record */
/* write message terminator */
if (SMTP_eom(sinkfp) != SM_OK)
{
- fputs("fetchmail: SMTP listener refused delivery\n", stderr);
+ error(0, 0, "SMTP listener refused delivery");
return(PS_SMTP);
}
}
@@ -785,7 +786,7 @@ const char *canonical; /* server name */
free (ticket);
if (rem != KSUCCESS)
{
- fprintf (stderr, "fetchmail: kerberos error %s\n", (krb_get_err_text (rem)));
+ error(0, 0, "kerberos error %s", (krb_get_err_text (rem)));
return (PS_ERROR);
}
return (0);
@@ -798,6 +799,7 @@ struct query *ctl; /* parsed options with merged-in defaults */
const struct method *proto; /* protocol method table */
{
int ok, js;
+ char *msg;
void (*sigsave)();
#ifndef KERBEROS_V4
@@ -844,8 +846,8 @@ const struct method *proto; /* protocol method table */
if ((js = setjmp(restart)) == 1)
{
- fprintf(stderr,
- "fetchmail: timeout after %d seconds waiting for %s.\n",
+ error(0, 0,
+ "timeout after %d seconds waiting for %s.",
ctl->timeout, ctl->servernames->id);
ok = PS_ERROR;
}
@@ -864,7 +866,7 @@ const struct method *proto; /* protocol method table */
if ((sockfp = Socket(ctl->servernames->id,
ctl->port ? ctl->port : protocol->port)) == NULL)
{
- perror("fetchmail, connecting to host");
+ error(0, errno, "connecting to host");
ok = PS_SOCKET;
goto closeUp;
}
@@ -904,18 +906,20 @@ const struct method *proto; /* protocol method table */
/* show user how many messages we downloaded */
if (outlevel > O_SILENT)
if (count == 0)
- fprintf(stderr, "No mail from %s@%s\n",
+ error(0, 0, "No mail from %s@%s",
ctl->remotename,
ctl->servernames->id);
else
{
- fprintf(stderr, "%d message%s", count, count > 1 ? "s" : "");
if (new != -1 && (count - new) > 0)
- fprintf(stderr, " (%d seen)", count-new);
- fprintf(stderr,
- " from %s@%s.\n",
- ctl->remotename,
- ctl->servernames->id);
+ error(0, 0, "%d message%s (%d seen) from %s@%s.",
+ count, count > 1 ? "s" : "", count-new,
+ ctl->remotename,
+ ctl->servernames->id);
+ else
+ error(0, 0, "%d message%s from %s@%s.", count, count > 1 ? "s" : "",
+ ctl->remotename,
+ ctl->servernames->id);
}
/* we may need to get sizes in order to check message limits */
@@ -1083,33 +1087,33 @@ const struct method *proto; /* protocol method table */
switch (ok)
{
case PS_SOCKET:
- fputs("fetchmail: socket", stderr);
+ msg = "socket";
break;
case PS_AUTHFAIL:
- fputs("fetchmail: authorization", stderr);
+ msg = "authorization";
break;
case PS_SYNTAX:
- fputs("fetchmail: missing or bad RFC822 header", stderr);
+ msg = "missing or bad RFC822 header";
break;
case PS_IOERR:
- fputs("fetchmail: MDA", stderr);
+ msg = "MDA";
break;
case PS_ERROR:
- fputs("fetchmail: client/server synchronization", stderr);
+ msg = "client/server synchronization";
break;
case PS_PROTOCOL:
- fputs("fetchmail: client/server protocol", stderr);
+ msg = "client/server protocol";
break;
case PS_SMTP:
- fputs("fetchmail: SMTP transaction", stderr);
+ msg = "SMTP transaction";
break;
case PS_UNDEFINED:
- fputs("fetchmail: undefined", stderr);
+ error(0, 0, "undefined");
break;
}
if (ok==PS_SOCKET || ok==PS_AUTHFAIL || ok==PS_SYNTAX || ok==PS_IOERR
|| ok==PS_ERROR || ok==PS_PROTOCOL || ok==PS_SMTP)
- fprintf(stderr, " error while talking to %s\n", ctl->servernames->id);
+ error(0, 0, "%s error while talking to %s", msg, ctl->servernames->id);
closeUp:
signal(SIGVTALRM, sigsave);
diff --git a/fetchmail.c b/fetchmail.c
index 882c7e44..08b9b4cf 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -35,6 +35,7 @@
#endif /* HAVE_GETHOSTBYNAME */
#include "fetchmail.h"
+#include "tunable.h"
#include "smtp.h"
#include "getopt.h"
@@ -64,6 +65,7 @@ char *rcfile; /* path name of rc file */
char *idfile; /* UID list file */
int versioninfo; /* emit only version info */
char *user; /* the name of the invoking user */
+char *program_name; /* the name to prefix error messages with */
static char *lockfile; /* name of lockfile */
static int querystatus; /* status of query */
@@ -89,6 +91,11 @@ int main (int argc, char **argv)
FILE *lockfp;
pid_t pid;
+ if ((program_name = strrchr(argv[0], '/')) != NULL)
+ ++program_name;
+ else
+ program_name = argv[0];
+
if ((user = getenv("USER")) == (char *)NULL)
user = getenv("LOGNAME");
@@ -345,12 +352,11 @@ int main (int argc, char **argv)
namerec = gethostbyname(ctl->servernames->id);
if (namerec == (struct hostent *)NULL)
{
- fprintf(stderr,
- "fetchmail: skipping %s poll, ",
+ error(0, errno,
+ "skipping %s poll, ",
ctl->servernames->id);
if (errno)
{
- perror("general error");
if (errno == ENETUNREACH)
break; /* go to sleep */
}
@@ -421,7 +427,7 @@ int main (int argc, char **argv)
signal(SIGALRM, donothing);
pause();
if (lastsig == SIGHUP)
- (void) fputs("fetchmail: awakened by SIGHUP\n", stderr);
+ (void) error(0, 0, "awakened by SIGHUP");
}
if (outlevel == O_VERBOSE)
@@ -639,7 +645,7 @@ void termhook(int sig)
*/
if (sig != 0)
- fprintf(stderr, "terminated with signal %d\n", sig);
+ error(0, 0, "terminated with signal %d\n", sig);
else
/* terminate all SMTP connections cleanly */
for (ctl = querylist; ctl; ctl = ctl->next)
@@ -706,7 +712,7 @@ static int query_host(struct query *ctl)
return(doIMAP(ctl));
break;
default:
- fprintf(stderr,"fetchmail: unsupported protocol selected.\n");
+ error(0, 0, "unsupported protocol selected.");
return(PS_PROTOCOL);
}
}
@@ -852,11 +858,11 @@ int openmailpipe (char **argv)
}
if (pipe(pipefd) < 0) {
- perror("fetchmail: openmailpipe: pipe");
+ error(0, errno, "openmailpipe: pipe");
return(-1);
}
if ((childpid = fork()) < 0) {
- perror("fetchmail: openmailpipe: fork");
+ error(0, errno, "openmailpipe: fork");
return(-1);
}
else if (childpid == 0) {
@@ -865,14 +871,14 @@ int openmailpipe (char **argv)
close(pipefd[1]); /* close the 'write' end of the pipe */
close(0); /* get rid of inherited stdin */
if (dup(pipefd[0]) != 0) {
- fputs("fetchmail: openmailpipe: dup() failed\n",stderr);
- exit(1);
+ error(0, errno, "openmailpipe: dup");
+ _exit(1);
}
execv(argv[0], argv + 1);
/* if we got here, an error occurred */
- perror("fetchmail: openmailpipe: exec");
+ error(0, errno, "openmailpipe: exec");
_exit(PS_SYNTAX);
}
@@ -890,7 +896,7 @@ int fd;
int childpid;
if ((err = close(fd)) != 0)
- perror("fetchmail: closemailpipe: close failed");
+ error(0, errno, "closemailpipe: close");
childpid = wait(&status);
@@ -901,7 +907,7 @@ int fd;
*/
if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0)
{
- perror("fetchmail: MDA exited abnormally or returned nonzero status");
+ error(0, errno, "MDA exited abnormally or returned nonzero status");
err = -1;
}
#endif
diff --git a/fetchmail.h b/fetchmail.h
index 9e10cd0d..e2d65be6 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -162,9 +162,11 @@ extern int smtp_response; /* numeric value of SMTP response code */
/* prototypes for globally callable functions */
#if defined(HAVE_STDARG_H)
+void error (int status, int errnum, const char *format, ...);
void gen_send (FILE *sockfp, char *, ... );
int gen_transact (FILE *sockfp, char *, ... );
#else
+void error ();
void gen_send ();
int gen_transact ();
#endif
diff --git a/getpass.c b/getpass.c
index d0606e45..447a8f0c 100644
--- a/getpass.c
+++ b/getpass.c
@@ -186,6 +186,5 @@ restore_tty_state()
RETSIGTYPE sigint_handler ()
{
restore_tty_state();
- fputs("\nCaught signal... bailing out.\n", stderr);
- exit(1);
+ error(1, 0, "\nCaught signal... bailing out.");
}
diff --git a/pop3.c b/pop3.c
index 1e429d30..5eb1741d 100644
--- a/pop3.c
+++ b/pop3.c
@@ -19,7 +19,7 @@
#include "socket.h"
#include "fetchmail.h"
-#define PROTOCOL_ERROR {fputs("fetchmail: protocol error\n", stderr); return(PS_ERROR);}
+#define PROTOCOL_ERROR {error(0, 0, "protocol error"); return(PS_ERROR);}
static int last;
@@ -73,7 +73,7 @@ int pop3_getauth(FILE *sockfp, struct query *ctl, char *greeting)
for (start = greeting; *start != 0 && *start != '<'; start++)
continue;
if (*start == 0) {
- fprintf(stderr,"Required APOP timestamp not found in greeting\n");
+ error(0, 0, "Required APOP timestamp not found in greeting");
return(PS_AUTHFAIL);
}
@@ -81,7 +81,7 @@ int pop3_getauth(FILE *sockfp, struct query *ctl, char *greeting)
for (end = start; *end != 0 && *end != '>'; end++)
continue;
if (*end == 0 || end == start + 1) {
- fprintf(stderr,"Timestamp syntax error in greeting\n");
+ error(0, 0, "Timestamp syntax error in greeting");
return(PS_AUTHFAIL);
}
else
@@ -112,7 +112,7 @@ int pop3_getauth(FILE *sockfp, struct query *ctl, char *greeting)
break;
default:
- fprintf(stderr,"Undefined protocol request in POP3_auth\n");
+ error(0, 0, "Undefined protocol request in POP3_auth");
}
/* we're approved */
diff --git a/rcfile_y.y b/rcfile_y.y
index ed9e9223..b9a97435 100644
--- a/rcfile_y.y
+++ b/rcfile_y.y
@@ -204,7 +204,7 @@ const char *pathname; /* pathname for the configuration file */
if (errno == ENOENT)
return(0);
else {
- perror(pathname);
+ error(0, errno, "lstat: %s", pathname);
return(PS_IOERR);
}
}
@@ -245,7 +245,7 @@ const char *pathname; /* pathname for the configuration file */
/* Open the configuration and feed it to the lexer. */
if ((yyin = fopen(pathname,"r")) == (FILE *)NULL) {
- perror(pathname);
+ error(0, errno, "open: %s", pathname);
return(PS_IOERR);
}
diff --git a/xmalloc.c b/xmalloc.c
index d9726618..3c231294 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -6,6 +6,7 @@
#include <config.h>
#include <stdio.h>
+#include <errno.h>
#include <string.h>
#if defined(STDC_HEADERS)
#include <stdlib.h>
@@ -24,10 +25,8 @@ xmalloc (int n)
XMALLOCTYPE *p;
p = (XMALLOCTYPE *) malloc(n);
- if (p == (XMALLOCTYPE *) 0) {
- fputs("fetchmail: malloc failed\n",stderr);
- exit(PS_UNDEFINED);
- }
+ if (p == (XMALLOCTYPE *) 0)
+ error(PS_UNDEFINED, errno, "malloc failed");
return(p);
}