diff options
Diffstat (limited to 'src/session-initialize-bincimapd.cc')
-rw-r--r-- | src/session-initialize-bincimapd.cc | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/src/session-initialize-bincimapd.cc b/src/session-initialize-bincimapd.cc index 2590403..60543b5 100644 --- a/src/session-initialize-bincimapd.cc +++ b/src/session-initialize-bincimapd.cc @@ -14,20 +14,16 @@ #include "iofactory.h" #include "maildir.h" #include "multilogdevice.h" +#include "operators.h" #include "session.h" #include "stdiodevice.h" #include "syslogdevice.h" #include "tools.h" +#include <charconv> #include <map> #include <string> -#include <errno.h> -#include <signal.h> - -#include <syslog.h> -#include <unistd.h> - using namespace Binc; using std::endl; using std::string; @@ -75,32 +71,33 @@ bool Session::initialize(int argc, char *argv[]) } else if (logtype == "syslog") { const string f = session.getEnv("SYSLOG_FACILITY"); - int facility; - - if (isdigit(f[0])) - facility = atoi(f); - else if (f == "LOG_USER") - facility = LOG_USER; - else if (f == "LOG_LOCAL0") - facility = LOG_LOCAL0; - else if (f == "LOG_LOCAL1") - facility = LOG_LOCAL1; - else if (f == "LOG_LOCAL2") - facility = LOG_LOCAL2; - else if (f == "LOG_LOCAL3") - facility = LOG_LOCAL3; - else if (f == "LOG_LOCAL4") - facility = LOG_LOCAL4; - else if (f == "LOG_LOCAL5") - facility = LOG_LOCAL5; - else if (f == "LOG_LOCAL6") - facility = LOG_LOCAL6; - else if (f == "LOG_LOCAL7") - facility = LOG_LOCAL7; - else - facility = LOG_DAEMON; - - session.setEnv("SYSLOG_FACILITY", toString(facility)); + int facility = 0; + auto fcr = std::from_chars(f.c_str(), f.c_str() + f.size(), facility); + + if (fcr.ec != std::errc{}) { + if (f == "LOG_USER") + facility = LOG_USER; + else if (f == "LOG_LOCAL0") + facility = LOG_LOCAL0; + else if (f == "LOG_LOCAL1") + facility = LOG_LOCAL1; + else if (f == "LOG_LOCAL2") + facility = LOG_LOCAL2; + else if (f == "LOG_LOCAL3") + facility = LOG_LOCAL3; + else if (f == "LOG_LOCAL4") + facility = LOG_LOCAL4; + else if (f == "LOG_LOCAL5") + facility = LOG_LOCAL5; + else if (f == "LOG_LOCAL6") + facility = LOG_LOCAL6; + else if (f == "LOG_LOCAL7") + facility = LOG_LOCAL7; + else + facility = LOG_DAEMON; + } + + session.setEnv("SYSLOG_FACILITY", std::to_string(facility)); ioFactory.addDevice( new SyslogDevice(IODevice::IsEnabled, "bincimapd", LOG_NDELAY | LOG_PID, facility)); @@ -114,7 +111,7 @@ bool Session::initialize(int argc, char *argv[]) string pid = std::to_string(session.getPid()); auto logindetails = Tools::getenv("BINCIMAP_LOGIN"); - if (!logindetails) { + if (!logindetails || logindetails->empty()) { bincLog << "bincimapd: pid " << pid << " BINCIMAP_LOGIN missing from environment (are you sure you invoked " << argv[0] << " properly?)\n"; |