summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Harris <jgh146exb@wizmail.org>2020-07-05 13:15:00 +0100
committerJeremy Harris <jgh146exb@wizmail.org>2020-07-05 13:15:00 +0100
commit89b1a5980cf39a0f34186a4c91c3b316c7b2f831 (patch)
tree5ed9c135b1761537b86eda2ef9bea0711d68eac5 /src
parent87359fb001c9fb4d450a35a0b5f6642c16c78c34 (diff)
Move errno-protection into string_open_failed()
Diffstat (limited to 'src')
-rw-r--r--src/src/daemon.c6
-rw-r--r--src/src/dbfn.c7
-rw-r--r--src/src/exim.c2
-rw-r--r--src/src/expand.c2
-rw-r--r--src/src/filter.c9
-rw-r--r--src/src/functions.h8
-rw-r--r--src/src/lookups/cdb.c18
-rw-r--r--src/src/lookups/dbmdb.c6
-rw-r--r--src/src/lookups/dsearch.c4
-rw-r--r--src/src/lookups/json.c7
-rw-r--r--src/src/lookups/lsearch.c11
-rw-r--r--src/src/match.c2
-rw-r--r--src/src/parse.c2
-rw-r--r--src/src/rda.c2
-rw-r--r--src/src/readconf.c6
-rw-r--r--src/src/spool_mbox.c12
-rw-r--r--src/src/string.c23
-rw-r--r--src/src/tls-gnu.c2
18 files changed, 52 insertions, 77 deletions
diff --git a/src/src/daemon.c b/src/src/daemon.c
index 09cb1a7f1..c376f27c7 100644
--- a/src/src/daemon.c
+++ b/src/src/daemon.c
@@ -950,8 +950,7 @@ if ((f = Ufopen(pid_file_path, "rb")))
}
else
DEBUG(D_any)
- debug_printf("%s\n", string_open_failed(errno, "pid file %s",
- pid_file_path));
+ debug_printf("%s\n", string_open_failed("pid file %s", pid_file_path));
exim_exit(EXIT_SUCCESS);
}
@@ -1822,8 +1821,7 @@ if (f.running_in_test_harness || write_pid)
}
else
DEBUG(D_any)
- debug_printf("%s\n", string_open_failed(errno, "pid file %s",
- pid_file_path));
+ debug_printf("%s\n", string_open_failed("pid file %s", pid_file_path));
}
/* Set up the handler for SIGHUP, which causes a restart of the daemon. */
diff --git a/src/src/dbfn.c b/src/src/dbfn.c
index aa083200a..a37271f36 100644
--- a/src/src/dbfn.c
+++ b/src/src/dbfn.c
@@ -123,7 +123,7 @@ if ((dbblock->lockfd = Uopen(filename, O_RDWR, EXIMDB_LOCKFILE_MODE)) < 0)
if (dbblock->lockfd < 0)
{
log_write(0, LOG_MAIN, "%s",
- string_open_failed(errno, "database lock file %s", filename));
+ string_open_failed("database lock file %s", filename));
errno = 0; /* Indicates locking failure */
DEBUG(D_hints_lookup) acl_level--;
return NULL;
@@ -228,12 +228,13 @@ exist. */
if (!dbblock->dbptr)
{
+ errno = save_errno;
if (lof && save_errno != ENOENT)
- log_write(0, LOG_MAIN, "%s", string_open_failed(save_errno, "DB file %s",
+ log_write(0, LOG_MAIN, "%s", string_open_failed("DB file %s",
filename));
else
DEBUG(D_hints_lookup)
- debug_printf_indent("%s\n", CS string_open_failed(save_errno, "DB file %s",
+ debug_printf_indent("%s\n", CS string_open_failed("DB file %s",
filename));
(void)close(dbblock->lockfd);
errno = save_errno;
diff --git a/src/src/exim.c b/src/src/exim.c
index dd3a17f14..3edbc29d3 100644
--- a/src/src/exim.c
+++ b/src/src/exim.c
@@ -564,7 +564,7 @@ for (int i = 0; i <= 2; i++)
{
if (devnull < 0) devnull = open("/dev/null", O_RDWR);
if (devnull < 0) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s",
- string_open_failed(errno, "/dev/null", NULL));
+ string_open_failed("/dev/null", NULL));
if (devnull != i) (void)dup2(devnull, i);
}
}
diff --git a/src/src/expand.c b/src/src/expand.c
index 291db426a..41860d93b 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -5261,7 +5261,7 @@ while (*s)
if (!(f = Ufopen(sub_arg[0], "rb")))
{
- expand_string_message = string_open_failed(errno, "%s", sub_arg[0]);
+ expand_string_message = string_open_failed("%s", sub_arg[0]);
goto EXPAND_FAILED;
}
diff --git a/src/src/filter.c b/src/src/filter.c
index 402ad6ae5..59c08f882 100644
--- a/src/src/filter.c
+++ b/src/src/filter.c
@@ -1952,7 +1952,7 @@ while (commands)
(long int)geteuid());
if (log_fd < 0)
{
- if (log_filename == NULL)
+ if (!log_filename)
{
*error_pointer = US"attempt to obey \"logwrite\" command "
"without a previous \"logfile\"";
@@ -1961,7 +1961,7 @@ while (commands)
log_fd = Uopen(log_filename, O_CREAT|O_APPEND|O_WRONLY, log_mode);
if (log_fd < 0)
{
- *error_pointer = string_open_failed(errno, "filter log file \"%s\"",
+ *error_pointer = string_open_failed("filter log file \"%s\"",
log_filename);
return FF_ERROR;
}
@@ -1975,9 +1975,8 @@ while (commands)
}
}
else
- {
- DEBUG(D_filter) debug_printf_indent("skipping logwrite (verifying or testing)\n");
- }
+ DEBUG(D_filter)
+ debug_printf_indent("skipping logwrite (verifying or testing)\n");
break;
/* Header addition and removal is available only in the system filter. The
diff --git a/src/src/functions.h b/src/src/functions.h
index 1dc64cea0..69bdaa5ed 100644
--- a/src/src/functions.h
+++ b/src/src/functions.h
@@ -554,10 +554,10 @@ extern BOOL string_format_trc(uschar *, int, const uschar *, unsigned,
extern gstring *string_vformat_trc(gstring *, const uschar *, unsigned,
unsigned, unsigned, const char *, va_list);
-#define string_open_failed(eno, fmt, ...) \
- string_open_failed_trc(eno, US __FUNCTION__, __LINE__, fmt, __VA_ARGS__)
-extern uschar *string_open_failed_trc(int, const uschar *, unsigned,
- const char *, ...) PRINTF_FUNCTION(4,5);
+#define string_open_failed(fmt, ...) \
+ string_open_failed_trc(US __FUNCTION__, __LINE__, fmt, __VA_ARGS__)
+extern uschar *string_open_failed_trc(const uschar *, unsigned,
+ const char *, ...) PRINTF_FUNCTION(3,4);
#define string_nextinlist(lp, sp, b, l) \
string_nextinlist_trc((lp), (sp), (b), (l), US __FUNCTION__, __LINE__)
diff --git a/src/src/lookups/cdb.c b/src/src/lookups/cdb.c
index e0faa905d..c0ac2cbe4 100644
--- a/src/src/lookups/cdb.c
+++ b/src/src/lookups/cdb.c
@@ -157,19 +157,14 @@ void * mapbuf;
if ((fileno = Uopen(filename, O_RDONLY, 0)) < 0)
{
- int save_errno = errno;
- *errmsg = string_open_failed(errno, "%s for cdb lookup", filename);
- errno = save_errno;
+ *errmsg = string_open_failed("%s for cdb lookup", filename);
return NULL;
}
if (fstat(fileno, &statbuf) != 0)
{
- int save_errno = errno;
- *errmsg = string_open_failed(errno,
- "fstat(%s) failed - cannot do cdb lookup",
+ *errmsg = string_open_failed("fstat(%s) failed - cannot do cdb lookup",
filename);
- errno = save_errno;
return NULL;
}
@@ -178,11 +173,7 @@ CDB_HASH_TABLE bytes long */
if (statbuf.st_size < CDB_HASH_TABLE)
{
- int save_errno = errno;
- *errmsg = string_open_failed(errno,
- "%s too short for cdb lookup",
- filename);
- errno = save_errno;
+ *errmsg = string_open_failed("%s too short for cdb lookup", filename);
return NULL;
}
@@ -231,8 +222,7 @@ if (cdb_bread(fileno, cdbp->cdb_offsets, CDB_HASH_TABLE) == -1)
/* read of hash table failed, oh dear, oh..... time to give up I think....
call the close routine (deallocs the memory), and return NULL */
- *errmsg = string_open_failed(errno,
- "cannot read header from %s for cdb lookup",
+ *errmsg = string_open_failed("cannot read header from %s for cdb lookup",
filename);
cdb_close(cdbp);
return NULL;
diff --git a/src/src/lookups/dbmdb.c b/src/src/lookups/dbmdb.c
index 0cec73273..f5614fdac 100644
--- a/src/src/lookups/dbmdb.c
+++ b/src/src/lookups/dbmdb.c
@@ -26,11 +26,7 @@ EXIM_DB *yield = NULL;
if ((s = Ustrrchr(dirname, '/'))) *s = '\0';
EXIM_DBOPEN(filename, dirname, O_RDONLY, 0, &yield);
if (!yield)
- {
- int save_errno = errno;
- *errmsg = string_open_failed(errno, "%s as a %s file", filename, EXIM_DBTYPE);
- errno = save_errno;
- }
+ *errmsg = string_open_failed("%s as a %s file", filename, EXIM_DBTYPE);
return yield;
}
diff --git a/src/src/lookups/dsearch.c b/src/src/lookups/dsearch.c
index 76f52774b..a6b331edb 100644
--- a/src/src/lookups/dsearch.c
+++ b/src/src/lookups/dsearch.c
@@ -31,9 +31,7 @@ dsearch_open(const uschar * dirname, uschar ** errmsg)
DIR * dp = exim_opendir(dirname);
if (!dp)
{
- int save_errno = errno;
- *errmsg = string_open_failed(errno, "%s for directory search", dirname);
- errno = save_errno;
+ *errmsg = string_open_failed("%s for directory search", dirname);
return NULL;
}
closedir(dp);
diff --git a/src/src/lookups/json.c b/src/src/lookups/json.c
index 1a2ca0449..9b1fe78ed 100644
--- a/src/src/lookups/json.c
+++ b/src/src/lookups/json.c
@@ -47,12 +47,7 @@ FILE * f;
json_set_alloc_funcs(json_malloc, json_free);
if (!(f = Ufopen(filename, "rb")))
- {
- int save_errno = errno;
- *errmsg = string_open_failed(errno, "%s for json search", filename);
- errno = save_errno;
- return NULL;
- }
+ *errmsg = string_open_failed("%s for json search", filename);
return f;
}
diff --git a/src/src/lookups/lsearch.c b/src/src/lookups/lsearch.c
index b78e858c3..9df7a167f 100644
--- a/src/src/lookups/lsearch.c
+++ b/src/src/lookups/lsearch.c
@@ -29,14 +29,9 @@ enum {
static void *
lsearch_open(const uschar * filename, uschar ** errmsg)
{
-FILE *f = Ufopen(filename, "rb");
-if (f == NULL)
- {
- int save_errno = errno;
- *errmsg = string_open_failed(errno, "%s for linear search", filename);
- errno = save_errno;
- return NULL;
- }
+FILE * f = Ufopen(filename, "rb");
+if (!f)
+ *errmsg = string_open_failed("%s for linear search", filename);
return f;
}
diff --git a/src/src/match.c b/src/src/match.c
index 18de97796..6a3314194 100644
--- a/src/src/match.c
+++ b/src/src/match.c
@@ -786,7 +786,7 @@ while ((sss = string_nextinlist(&list, &sep, NULL, 0)))
if (listname[0] == 0)
listname = string_sprintf("\"%s\"", *listptr);
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s",
- string_open_failed(errno, "%s when checking %s", sss, listname));
+ string_open_failed("%s when checking %s", sss, listname));
}
/* Trailing comments are introduced by #, but in an address list or local
diff --git a/src/src/parse.c b/src/src/parse.c
index e3b471f1a..0ce36a345 100644
--- a/src/src/parse.c
+++ b/src/src/parse.c
@@ -1525,7 +1525,7 @@ for (;;)
if (!f)
{
- *error = string_open_failed(errno, "included file %s", filename);
+ *error = string_open_failed("included file %s", filename);
return FF_INCLUDEFAIL;
}
diff --git a/src/src/rda.c b/src/src/rda.c
index aed8abc24..5615b64d5 100644
--- a/src/src/rda.c
+++ b/src/src/rda.c
@@ -222,7 +222,7 @@ if (!(fwd = Ufopen(filename, "rb"))) switch(errno)
DEFAULT_ERROR:
default:
- *error = string_open_failed(errno, "%s", filename);
+ *error = string_open_failed("%s", filename);
*yield = FF_ERROR;
return NULL;
}
diff --git a/src/src/readconf.c b/src/src/readconf.c
index a8f13350a..e3c9ed72d 100644
--- a/src/src/readconf.c
+++ b/src/src/readconf.c
@@ -3214,12 +3214,12 @@ if (config_file)
}
else
{
- if (filename == NULL)
+ if (!filename)
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "non-existent configuration file(s): "
"%s", config_main_filelist);
else
- log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s", string_open_failed(errno,
- "configuration file %s", filename));
+ log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s",
+ string_open_failed("configuration file %s", filename));
}
/* Now, once we found and opened our configuration file, we change the directory
diff --git a/src/src/spool_mbox.c b/src/src/spool_mbox.c
index 9f1efbf59..cf7909fbe 100644
--- a/src/src/spool_mbox.c
+++ b/src/src/spool_mbox.c
@@ -53,8 +53,8 @@ if (!spool_mbox_ok)
temp_string = string_sprintf("scan/%s", message_id);
if (!directory_make(spool_directory, temp_string, 0750, FALSE))
{
- log_write(0, LOG_MAIN|LOG_PANIC, "%s", string_open_failed(errno,
- "scan directory %s/scan/%s", spool_directory, temp_string));
+ log_write(0, LOG_MAIN|LOG_PANIC, "%s",
+ string_open_failed("scan directory %s/scan/%s", spool_directory, temp_string));
goto OUT;
}
@@ -62,8 +62,8 @@ if (!spool_mbox_ok)
if (!(mbox_file = modefopen(mbox_path, "wb", SPOOL_MODE)))
{
- log_write(0, LOG_MAIN|LOG_PANIC, "%s", string_open_failed(errno,
- "scan file %s", mbox_path));
+ log_write(0, LOG_MAIN|LOG_PANIC, "%s",
+ string_open_failed("scan file %s", mbox_path));
goto OUT;
}
@@ -185,8 +185,8 @@ if (!spool_mbox_ok)
if ( !(yield = Ufopen(mbox_path,"rb"))
|| fstat(fileno(yield), &statbuf) != 0
)
- log_write(0, LOG_MAIN|LOG_PANIC, "%s", string_open_failed(errno,
- "scan file %s", mbox_path));
+ log_write(0, LOG_MAIN|LOG_PANIC, "%s",
+ string_open_failed( "scan file %s", mbox_path));
else
*mbox_file_size = statbuf.st_size;
diff --git a/src/src/string.c b/src/src/string.c
index 3cacccce9..1b08e7fb8 100644
--- a/src/src/string.c
+++ b/src/src/string.c
@@ -1612,7 +1612,6 @@ string supplied as data, adds the strerror() text, and if the failure was
"Permission denied", reads and includes the euid and egid.
Arguments:
- eno the value of errno after the failure
format a text format string - deliberately not uschar *
... arguments for the format string
@@ -1620,7 +1619,7 @@ Returns: a message, in dynamic store
*/
uschar *
-string_open_failed_trc(int eno, const uschar * func, unsigned line,
+string_open_failed_trc(const uschar * func, unsigned line,
const char *format, ...)
{
va_list ap;
@@ -1636,22 +1635,26 @@ doesn't seem much we can do about that. */
va_start(ap, format);
(void) string_vformat_trc(g, func, line, STRING_SPRINTF_BUFFER_SIZE,
SVFMT_REBUFFER, format, ap);
-string_from_gstring(g);
-gstring_release_unused(g);
va_end(ap);
-return eno == EACCES
- ? string_sprintf("%s: %s (euid=%ld egid=%ld)", g->s, strerror(eno),
- (long int)geteuid(), (long int)getegid())
- : string_sprintf("%s: %s", g->s, strerror(eno));
+g = string_catn(g, US": ", 2);
+g = string_cat(g, US strerror(errno));
+
+if (errno == EACCES)
+ {
+ int save_errno = errno;
+ g = string_fmt_append(g, " (euid=%ld egid=%ld)",
+ (long int)geteuid(), (long int)getegid());
+ errno = save_errno;
+ }
+gstring_release_unused(g);
+return string_from_gstring(g);
}
-#endif /* COMPILE_UTILITY */
-#ifndef COMPILE_UTILITY
/* qsort(3), currently used to sort the environment variables
for -bP environment output, needs a function to compare two pointers to string
pointers. Here it is. */
diff --git a/src/src/tls-gnu.c b/src/src/tls-gnu.c
index df520e8d7..6308f10df 100644
--- a/src/src/tls-gnu.c
+++ b/src/src/tls-gnu.c
@@ -728,7 +728,7 @@ else if (errno == ENOENT)
debug_printf("D-H parameter cache file \"%s\" does not exist\n", filename);
}
else
- return tls_error(string_open_failed(errno, "\"%s\" for reading", filename),
+ return tls_error(string_open_failed("\"%s\" for reading", filename),
NULL, NULL, errstr);
/* If ret < 0, either the cache file does not exist, or the data it contains