]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Move editor invocation to its own routine. NFC
authorMiod Vallat <miod.vallat@powerdns.com>
Thu, 22 May 2025 06:23:36 +0000 (08:23 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Wed, 28 May 2025 12:09:30 +0000 (14:09 +0200)
pdns/pdnsutil.cc

index 59bd7c371892aac706b834e502c0bc13985df67f..c437c1dee1f41bff83256867cd3770436103e2cb 100644 (file)
@@ -1246,6 +1246,18 @@ private:
   bool d_colors;
 };
 
+static int spawnEditor(const std::string& editor, const std::string& tmpfile, int gotoline)
+{
+  string cmdline;
+
+  cmdline=editor+" ";
+  if(gotoline > 0) {
+    cmdline+="+"+std::to_string(gotoline)+" ";
+  }
+  cmdline += tmpfile;
+  return system(cmdline.c_str());
+}
+
 static int editZone(const ZoneName &zone, const PDNSColors& col) {
   UtilBackend B; //NOLINT(readability-identifier-length)
   DomainInfo di;
@@ -1308,7 +1320,6 @@ static int editZone(const ZoneName &zone, const PDNSColors& col) {
   string editor="editor";
   if(auto e=getenv("EDITOR")) // <3
     editor=e;
-  string cmdline;
  editAgain:;
   di.backend->list(zone, di.id);
   pre.clear(); post.clear();
@@ -1338,15 +1349,9 @@ static int editZone(const ZoneName &zone, const PDNSColors& col) {
   }
  editMore:;
   post.clear();
-  cmdline=editor+" ";
-  if(gotoline > 0)
-    cmdline+="+"+std::to_string(gotoline)+" ";
-  cmdline += tmpnam;
-  int err=system(cmdline.c_str());
-  if(err != 0) {
-    unixDie("Editing file with: '"+cmdline+"', perhaps set EDITOR variable");
+  if (spawnEditor(editor, tmpnam, gotoline) != 0) {
+    unixDie("Editing file with: '"+editor+"', perhaps set EDITOR variable");
   }
-  cmdline.clear();
   ZoneParserTNG zpt(static_cast<const char *>(tmpnam), g_rootzonename);
   zpt.setMaxGenerateSteps(::arg().asNum("max-generate-steps"));
   zpt.setMaxIncludes(::arg().asNum("max-include-depth"));