[PATCH] mdevd: Add -t option to test the config file

From: <contact+skanet_at_hacktivis.me>
Date: Sun, 1 Jun 2025 11:10:11 +0200

From: "Haelwenn (lanodan) Monnier" <contact_at_hacktivis.me>

---
 doc/mdevd.html    | 3 ++-
 src/mdevd/mdevd.c | 9 ++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/doc/mdevd.html b/doc/mdevd.html
index 7c2a869..883be7b 100644
--- a/doc/mdevd.html
+++ b/doc/mdevd.html
_at__at_ -49,7 +49,7 _at__at_ <h1> The <tt>mdevd</tt> program </h1>
 <h2> Interface </h2>
 
 <pre>
-     mdevd [ -v <em>verbosity</em> ] [ -D <em>notif</em> ] [ -I <em>intake</em> ] [ -o <em>outputfd</em> ] [ -I <em>intake</em> ] [ -O <em>nlgroups</em> ] [ -b <em>kbufsz</em> ] [ -f <em>conffile</em> ] [ -n ] [ -s <em>slashsys</em> ] [ -d <em>slashdev</em> ] [ -F <em>fwbase</em> ] [ -C ]
+     mdevd [ -v <em>verbosity</em> ] [ -D <em>notif</em> ] [ -I <em>intake</em> ] [ -o <em>outputfd</em> ] [ -I <em>intake</em> ] [ -O <em>nlgroups</em> ] [ -b <em>kbufsz</em> ] [ -f <em>conffile</em> ] [ -n ] [ -s <em>slashsys</em> ] [ -d <em>slashdev</em> ] [ -F <em>fwbase</em> ] [ -C ] [ -t ]
 </pre>
 
 <ul>
_at__at_ -149,6 +149,7 _at__at_ <h2> Options </h2>
 at boot time, when mdevd is ready. The <tt>examples/s6-rc</tt> subdirectory of
 the mdevd package shows a way to do this with the
 <a href="//skarnet.org/software/s6-rc/">s6-rc</a> service manager. </li>
+ <li> <tt>-t</tt>&nbsp;: Do not run, just test the configuration file.</li>
 </ul>
 
 <h2> Configuration file </h2>
diff --git a/src/mdevd/mdevd.c b/src/mdevd/mdevd.c
index f5222f7..5c532db 100644
--- a/src/mdevd/mdevd.c
+++ b/src/mdevd/mdevd.c
_at__at_ -910,12 +910,13 _at__at_ int main (int argc, char const *const *argv)
   unsigned int intake = 1 ;
   unsigned int outputfd = 0 ;
   unsigned int rebc = 0 ;
+  unsigned int configtest = 0;
   PROG = "mdevd" ;
   {
     subgetopt l = SUBGETOPT_ZERO ;
     for (;;)
     {
-      int opt = subgetopt_r(argc, argv, "nv:D:I:o:O:b:f:s:d:F:C", &l) ;
+      int opt = subgetopt_r(argc, argv, "nv:D:I:o:O:b:f:s:d:F:Ct", &l) ;
       if (opt == -1) break ;
       switch (opt)
       {
_at__at_ -931,6 +932,7 _at__at_ int main (int argc, char const *const *argv)
         case 'd' : slashdev = l.arg ; break ;
         case 'F' : fwbase = l.arg ; break ;
         case 'C' : docoldplug = 1 ; break ;
+        case 't' : configtest = 1 ; break ;
         default : dieusage() ;
       }
     }
_at__at_ -1024,6 +1026,11 _at__at_ int main (int argc, char const *const *argv)
       script[scriptlen++] = scriptelem_catchall ;
       script_secondpass(storage, script, envmatch) ;
       cont = 2 ;
+      if (configtest)
+      {
+        script_free(script, scriptlen, envmatch, envmatchlen) ;
+        return 0;
+      }
       if (docoldplug)
       {
         char const *cargv[2] = { MDEVD_BINPREFIX "mdevd-coldplug", 0 } ;
base-commit: f2dfc6263ece1fc0f41e01adbb33350b7f024d89
-- 
2.49.0
Received on Sun Jun 01 2025 - 11:10:11 CEST

This archive was generated by hypermail 2.4.0 : Sun Jun 01 2025 - 11:10:52 CEST