Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make system errors on reading config files fatal (with useful message)

  • Loading branch information...
commit 9de2e74f64f7daf017ebf4c5220c797b380994b2 1 parent 4aff5a4
@bruceg authored
View
2  lib/Makefile.am
@@ -8,7 +8,7 @@ libmisc_a_SOURCES = \
address.h address.cc \
base64.h base64.cc \
canonicalize.h canonicalize.cc \
- configio.h config_read.cc config_readlist.cc config_readint.cc \
+ configio.h config_read.cc config_readlist.cc config_readint.cc config_syserr.cc \
connect.h tcpconnect.cc \
defines.h defines.cc \
errcodes.h errcodes.cc \
View
2  lib/config_read.cc
@@ -29,6 +29,8 @@ bool config_read(const char* filename, mystring& result)
mystring fullname = CONFIG_DIR;
fullname += filename;
fdibuf in(fullname.c_str());
+ if (!in)
+ return config_syserr(fullname.c_str());
if(!in.getline(result))
return false;
result = result.strip();
View
2  lib/config_readlist.cc
@@ -30,7 +30,7 @@ bool config_readlist(const char* filename, list<mystring>& result)
fullname += filename;
fdibuf in(fullname.c_str());
if(!in)
- return false;
+ return config_syserr(fullname.c_str());
mystring tmp;
bool nonempty = false;
while(in.getline(tmp)) {
View
33 lib/config_syserr.cc
@@ -0,0 +1,33 @@
+// nullmailer -- a simple relay-only MTA
+// Copyright (C) 2013 Bruce Guenter <bruce@untroubled.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// You can contact me at <bruce@untroubled.org>. There is also a mailing list
+// available to discuss this package. To subscribe, send an email to
+// <nullmailer-subscribe@lists.untroubled.org>.
+
+#include <errno.h>
+#include "config.h"
+#include "errcodes.h"
+#include "configio.h"
+#include "cli++/cli++.h"
+
+bool config_syserr(const char* filename)
+{
+ if (errno != ENOENT)
+ cli_syserror(ERR_CONFIG, "Could not read config file \"", filename, "\"");
+ return false;
+}
View
1  lib/configio.h
@@ -7,5 +7,6 @@
bool config_read(const char* filename, mystring& result);
bool config_readlist(const char* filename, list<mystring>& result);
bool config_readint(const char* filename, int& result);
+bool config_syserr(const char* filename);
#endif // NULLMAILER__CONFIGIO__H__
View
6 src/Makefile.am
@@ -15,13 +15,13 @@ mailq_SOURCES = mailq.cc
mailq_LDADD = ../lib/libnullmailer.a
nullmailer_inject_SOURCES = inject.cc
-nullmailer_inject_LDADD = ../lib/cli++/libcli++.a ../lib/libnullmailer.a
+nullmailer_inject_LDADD = ../lib/libnullmailer.a ../lib/cli++/libcli++.a
nullmailer_queue_SOURCES = queue.cc
-nullmailer_queue_LDADD = ../lib/libnullmailer.a
+nullmailer_queue_LDADD = ../lib/libnullmailer.a ../lib/cli++/libcli++.a
nullmailer_send_SOURCES = send.cc
-nullmailer_send_LDADD = ../lib/libnullmailer.a
+nullmailer_send_LDADD = ../lib/libnullmailer.a ../lib/cli++/libcli++.a
nullmailer_smtpd_SOURCES = smtpd.cc
nullmailer_smtpd_LDADD = ../lib/libnullmailer.a
View
2  src/queue.cc
@@ -33,6 +33,8 @@
#include "configio.h"
#include "hostname.h"
+const char* cli_program = "nullmailer-queue";
+
#define fail(MSG) do{ fout << "nullmailer-queue: " << MSG << endl; return false; }while(0)
pid_t pid = getpid();
View
2  src/send.cc
@@ -41,6 +41,8 @@
#include "selfpipe.h"
#include "setenv.h"
+const char* cli_program = "nullmailer-send";
+
selfpipe selfpipe;
typedef list<mystring> slist;
Please sign in to comment.
Something went wrong with that request. Please try again.