From: Miod Vallat Date: Thu, 22 May 2025 10:25:49 +0000 (+0200) Subject: appease clang-tidy X-Git-Tag: dnsdist-2.0.0-beta1~50^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a2b3288b1c288ec6cb89fa3114435ab20f918d0c;p=thirdparty%2Fpdns.git appease clang-tidy --- diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index fbffdc9e0f..41c6729df3 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -9,7 +9,7 @@ #endif #include -#include +#include #include #include "credentials.hh" @@ -1248,34 +1248,34 @@ private: bool d_colors; }; -static bool spawnEditor(const std::string& editor, const std::string& tmpfile, int gotoline, int &result) +static bool spawnEditor(const std::string& editor, std::string_view tmpfile, int gotoline, int &result) { - pid_t child; - sigset_t mask, omask; + sigset_t mask; + sigset_t omask; // Ignore INT, QUIT and CHLD signals while the editor process runs sigemptyset(&mask); sigaddset(&mask, SIGCHLD); sigaddset(&mask, SIGINT); sigaddset(&mask, SIGQUIT); - sigprocmask(SIG_BLOCK, &mask, &omask); + sigprocmask(SIG_BLOCK, &mask, &omask); // NOLINT(concurrency-mt-unsafe) - switch (child = fork()) { + switch (pid_t child = fork()) { case 0: { - std::array args; - size_t pos = 0; + std::array args{}; + size_t pos{0}; std::string gotolinestr; - args[pos++] = editor.c_str(); + args.at(pos++) = editor.c_str(); if (gotoline > 0) { // TODO: if editor is 'ed', skip this; if 'ex' or 'vi', use '-c number' gotolinestr = "+" + std::to_string(gotoline); - args[pos++] = gotolinestr.c_str(); + args.at(pos++) = gotolinestr.c_str(); } - args[pos++] = tmpfile.c_str(); - args[pos++] = nullptr; - if (::execvp(args.at(0), const_cast(args.data())) != 0) { - ::exit(errno); + args.at(pos++) = tmpfile.data(); + args.at(pos++) = nullptr; + if (::execvp(args.at(0), const_cast(args.data())) != 0) { // NOLINT(cppcoreguidelines-pro-type-const-cast) + ::exit(errno); // NOLINT(concurrency-mt-unsafe) } // std::unreachable(); } @@ -1285,12 +1285,12 @@ static bool spawnEditor(const std::string& editor, const std::string& tmpfile, i break; default: { - pid_t pid; - int status; + pid_t pid{-1}; + int status{0}; do { pid = waitpid(child, &status, 0); } while (pid == -1 && errno == EINTR); - sigprocmask(SIG_SETMASK, &omask, NULL); + sigprocmask(SIG_SETMASK, &omask, nullptr); // NOLINT(concurrency-mt-unsafe) if (pid == -1) { return false; } @@ -1400,7 +1400,7 @@ static int editZone(const ZoneName &zone, const PDNSColors& col) { editMore:; post.clear(); int result{0}; - if (!spawnEditor(editor, tmpnam, gotoline, result)) { + if (!spawnEditor(editor, tmpnam, gotoline, result)) { // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) unixDie("Editing file with: '"+editor+"', perhaps set EDITOR variable"); } if (result != 0) {