diff options
author | 2008-12-22 13:28:10 +0000 | |
---|---|---|
committer | 2008-12-22 13:28:10 +0000 | |
commit | a99923c7f57b4545a663b4df14ef8480c1eb47d3 (patch) | |
tree | 43d36b9c60994ae899dccca2d076c8bdb6bf27f1 | |
parent | cleanup (diff) | |
download | wireguard-openbsd-a99923c7f57b4545a663b4df14ef8480c1eb47d3.tar.xz wireguard-openbsd-a99923c7f57b4545a663b4df14ef8480c1eb47d3.zip |
Fix few cases where "smtpctl showqueue" could exit prematurely
if msg is delivered between readdir and opendir, or readdir and
fopen, etc. etc.
Be more unforgiving about errors other than ENOENT, and err()
if they happen, not just warn().
ok gilles@
-rw-r--r-- | usr.sbin/smtpd/showqueue.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/usr.sbin/smtpd/showqueue.c b/usr.sbin/smtpd/showqueue.c index 2b46b8248ef..fc8cbb27337 100644 --- a/usr.sbin/smtpd/showqueue.c +++ b/usr.sbin/smtpd/showqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: showqueue.c,v 1.2 2008/12/21 13:06:41 jacekm Exp $ */ +/* $OpenBSD: showqueue.c,v 1.3 2008/12/22 13:28:10 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -90,8 +90,11 @@ list_bucket(char *bucket, int flags) snprintf(pathname, MAXPATHLEN, "%s/%s", PATH_SPOOL PATH_QUEUE, bucket); dirp = opendir(pathname); - if (dirp == NULL) + if (dirp == NULL) { + if (errno == ENOENT) + return; err(1, "%s", pathname); + } while ((dp = readdir(dirp)) != NULL) { if (strcmp(dp->d_name, ".") == 0 || @@ -117,8 +120,11 @@ list_message(char *bucket, char *message, int flags) bucket, message, PATH_ENVELOPES); dirp = opendir(pathname); - if (dirp == NULL) + if (dirp == NULL) { + if (errno == ENOENT) + return; err(1, "%s", pathname); + } while ((dp = readdir(dirp)) != NULL) { if (strcmp(dp->d_name, ".") == 0 || @@ -130,15 +136,13 @@ list_message(char *bucket, char *message, int flags) fp = fopen(pathname, "r"); if (fp == NULL) { - warn("%s", pathname); - continue; + if (errno == ENOENT) + continue; + err(1, "%s", pathname); } - if (fread(&envelope, sizeof(struct message), 1, fp) != 1) { - warn("%s", pathname); - fclose(fp); - continue; - } + if (fread(&envelope, sizeof(struct message), 1, fp) != 1) + err(1, "%s", pathname); fclose(fp); @@ -171,15 +175,13 @@ show_runqueue(int flags) fp = fopen(pathname, "r"); if (fp == NULL) { - warn("%s", pathname); - continue; + if (errno == ENOENT) + continue; + err(1, "%s", pathname); } - if (fread(&envelope, sizeof(struct message), 1, fp) != 1) { - warn("%s", pathname); - fclose(fp); - continue; - } + if (fread(&envelope, sizeof(struct message), 1, fp) != 1) + err(1, "%s", pathname); fclose(fp); |