From: Otto Moerbeek Date: Wed, 10 Jun 2020 08:40:19 +0000 (+0200) Subject: Let the threads returns an error code if someting is wrong X-Git-Tag: rec-4.4.0-beta1~56^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bff61896d9c1777845d767f387d89296c4ed5854;p=thirdparty%2Fpdns.git Let the threads returns an error code if someting is wrong which is picked up by serviceMain as an exit status. There are a lot more places where the (fatal) error flow could be improved/made consistent. --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 0f78ead18a..551db20b76 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -179,6 +179,7 @@ struct RecThreadInfo bool isListener{false}; /* process queries */ bool isWorker{false}; + int exitCode{0}; }; /* first we have the handler thread, t_id == 0 (some other @@ -4128,6 +4129,8 @@ static void checkSocketDir(void) static int serviceMain(int argc, char*argv[]) { + int ret = EXIT_SUCCESS; + g_log.setName(s_programname); g_log.disableSyslog(::arg().mustDo("disable-syslog")); g_log.setTimestamps(::arg().mustDo("log-timestamp")); @@ -4644,6 +4647,9 @@ static int serviceMain(int argc, char*argv[]) recursorThread(currentThreadId++, "worker"); handlerInfos.thread.join(); + if (handlerInfos.exitCode != 0) { + ret = handlerInfos.exitCode; + } } else { @@ -4688,13 +4694,16 @@ static int serviceMain(int argc, char*argv[]) for (auto & ti : s_threadInfos) { ti.thread.join(); + if (ti.exitCode != 0) { + ret = ti.exitCode; + } } } #ifdef HAVE_PROTOBUF google::protobuf::ShutdownProtobufLibrary(); #endif /* HAVE_PROTOBUF */ - return 0; + return ret; } static void* recursorThread(unsigned int n, const string& threadName) @@ -4714,7 +4723,9 @@ try if (threadInfo.isHandler) { if (!primeHints()) { - throw PDNSException("Priming cache failed, stopping"); + threadInfo.exitCode = EXIT_FAILURE; + g_log<