Re: ldomctl: init-system: Add -n (noaction) switch for validation only

2020-01-04 Thread Klemens Nanni
On Sat, Jan 04, 2020 at 12:35:46PM -0600, Matthew Martin wrote:
> For what it's worth most daemons currently print "configuration OK":
> bgpd dvmrpd eigrpd httpd ifstated iked ldpd npppd ntpd ospf6d ospfd rad
> radiusd relayd ripd sasyncd smtpd switchd unwind vmd.
Yup, hence my addition.

> ldapd and snmpd print "configuration ok". dhcpd, doas, isakmpd, and
> nsd-checkconf are slient. unbound-checkconf uses the format string
> "unbound-checkconf: no errors in %s\n".
But as there are more inconsistencies as you noted and this is mark's
code afterall, I did not want to bike shed.

Personally, I'd appreciate seeing the same behaviour across all tools,
but that's a yak I don't want to shave (now).



Re: ldomctl: init-system: Add -n (noaction) switch for validation only

2020-01-04 Thread Matthew Martin
On Sat, Jan 04, 2020 at 04:08:47PM +0100, Mark Kettenis wrote:
> I don't think this should print "configuartion OK" when there are no
> errors.  The UNIX way is to just return 0 and be done.

For what it's worth most daemons currently print "configuration OK":
bgpd dvmrpd eigrpd httpd ifstated iked ldpd npppd ntpd ospf6d ospfd rad
radiusd relayd ripd sasyncd smtpd switchd unwind vmd.

ldapd and snmpd print "configuration ok". dhcpd, doas, isakmpd, and
nsd-checkconf are slient. unbound-checkconf uses the format string
"unbound-checkconf: no errors in %s\n".



Re: ldomctl: init-system: Add -n (noaction) switch for validation only

2020-01-04 Thread Mark Kettenis
> Date: Fri, 3 Jan 2020 21:46:29 +0100
> From: Klemens Nanni 
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
> 
> With the hv_config() now in, `ldomctl init-system -n ldom.conf' to only
> parse configuration is trivial.
> 
> It is usable as unprivileged user, no devices are touched.
> 
> If errors occur, errors will be generated and ldomctl exits;  if all is
> valid, this prints "configuration OK" just like vmd(8) does.
> 
> I have plans for additional ldom.conf(5) options and -n greatly aids
> development, but I also prefer to (double) check configs before loading
> them as root in general.
> 
> Feedback? OK?

I don't think this should print "configuartion OK" when there are no
errors.  The UNIX way is to just return 0 and be done.

Otherwise ok kettenis@

> Index: config.c
> ===
> RCS file: /cvs/src/usr.sbin/ldomctl/config.c,v
> retrieving revision 1.29
> diff -u -p -r1.29 config.c
> --- config.c  28 Nov 2019 18:40:42 -  1.29
> +++ config.c  3 Jan 2020 20:45:33 -
> @@ -2759,7 +2759,7 @@ primary_init(void)
>  }
>  
>  void
> -build_config(const char *filename)
> +build_config(const char *filename, int noaction)
>  {
>   struct guest *primary;
>   struct guest *guest;
> @@ -2781,6 +2781,10 @@ build_config(const char *filename)
>   SIMPLEQ_INIT(_list);
>   if (parse_config(filename, ) < 0)
>   exit(1);
> + if (noaction) {
> + fprintf(stderr, "configuration OK\n");
> + exit(0);
> + }
>  
>   pri = md_read("pri");
>   if (pri == NULL)
> Index: ldomctl.8
> ===
> RCS file: /cvs/src/usr.sbin/ldomctl/ldomctl.8,v
> retrieving revision 1.21
> diff -u -p -r1.21 ldomctl.8
> --- ldomctl.8 30 Dec 2019 20:10:48 -  1.21
> +++ ldomctl.8 3 Jan 2020 20:45:33 -
> @@ -63,12 +63,17 @@ The download is aborted if a configurati
>  .It Cm dump
>  Dump the current configuration from non-volatile storage into the current
>  working directory.
> -.It Cm init-system Ar file
> +.It Cm init-system Oo Fl n Oc Ar file
>  Generate files in the current working directory for a logical domain
>  configuration
>  .Ar file
>  as described in
>  .Xr ldom.conf 5 .
> +.Bl -tag -width Fl
> +.It Fl n
> +Configtest mode.
> +Only check the configuration file for validty.
> +.El
>  .It Cm list
>  List configurations stored in non-volatile storage.
>  Indicate the currently running configuration,
> Index: ldomctl.c
> ===
> RCS file: /cvs/src/usr.sbin/ldomctl/ldomctl.c,v
> retrieving revision 1.32
> diff -u -p -r1.32 ldomctl.c
> --- ldomctl.c 3 Jan 2020 19:45:51 -   1.32
> +++ ldomctl.c 3 Jan 2020 20:45:34 -
> @@ -129,7 +129,7 @@ usage(void)
>   fprintf(stderr, "usage:\t%1$s delete|select configuration\n"
>   "\t%1$s download directory\n"
>   "\t%1$s dump|list|list-io\n"
> - "\t%1$s init-system file\n"
> + "\t%1$s init-system [-n] file\n"
>   "\t%1$s create-vdisk -s size file\n"
>   "\t%1$s console|panic|start|status|stop [domain]\n", getprogname());
>   exit(EXIT_FAILURE);
> @@ -241,12 +241,27 @@ dump(int argc, char **argv)
>  void
>  init_system(int argc, char **argv)
>  {
> - if (argc != 2)
> + int ch, noaction = 0;
> +
> + while ((ch = getopt(argc, argv, "n")) != -1) {
> + switch (ch) {
> + case 'n':
> + noaction = 1;
> + break;
> + default:
> + usage();
> + }
> + }
> + argc -= optind;
> + argv += optind;
> +
> + if (argc != 1)
>   usage();
>  
> - hv_config();
> + if (!noaction)
> + hv_config();
>  
> - build_config(argv[1]);
> + build_config(argv[0], noaction);
>  }
>  
>  void
> Index: ldomctl.h
> ===
> RCS file: /cvs/src/usr.sbin/ldomctl/ldomctl.h,v
> retrieving revision 1.11
> diff -u -p -r1.11 ldomctl.h
> --- ldomctl.h 28 Nov 2019 18:03:33 -  1.11
> +++ ldomctl.h 3 Jan 2020 20:45:34 -
> @@ -193,5 +193,5 @@ struct ldom_config {
>  };
>  
>  int parse_config(const char *, struct ldom_config *);
> -void build_config(const char *);
> +void build_config(const char *, int);
>  void list_components(void);
> 
> 



Re: ldomctl: init-system: Add -n (noaction) switch for validation only

2020-01-03 Thread Klemens Nanni
On Fri, Jan 03, 2020 at 09:46:29PM +0100, Klemens Nanni wrote:

> +Only check the configuration file for validty.
"validity" fixed in my tree.



ldomctl: init-system: Add -n (noaction) switch for validation only

2020-01-03 Thread Klemens Nanni
With the hv_config() now in, `ldomctl init-system -n ldom.conf' to only
parse configuration is trivial.

It is usable as unprivileged user, no devices are touched.

If errors occur, errors will be generated and ldomctl exits;  if all is
valid, this prints "configuration OK" just like vmd(8) does.

I have plans for additional ldom.conf(5) options and -n greatly aids
development, but I also prefer to (double) check configs before loading
them as root in general.

Feedback? OK?


? default.diff
? disk.diff
? download.diff
? msg
? n.diff
? owner.diff
? parse.y.new
Index: config.c
===
RCS file: /cvs/src/usr.sbin/ldomctl/config.c,v
retrieving revision 1.29
diff -u -p -r1.29 config.c
--- config.c28 Nov 2019 18:40:42 -  1.29
+++ config.c3 Jan 2020 20:45:33 -
@@ -2759,7 +2759,7 @@ primary_init(void)
 }
 
 void
-build_config(const char *filename)
+build_config(const char *filename, int noaction)
 {
struct guest *primary;
struct guest *guest;
@@ -2781,6 +2781,10 @@ build_config(const char *filename)
SIMPLEQ_INIT(_list);
if (parse_config(filename, ) < 0)
exit(1);
+   if (noaction) {
+   fprintf(stderr, "configuration OK\n");
+   exit(0);
+   }
 
pri = md_read("pri");
if (pri == NULL)
Index: ldomctl.8
===
RCS file: /cvs/src/usr.sbin/ldomctl/ldomctl.8,v
retrieving revision 1.21
diff -u -p -r1.21 ldomctl.8
--- ldomctl.8   30 Dec 2019 20:10:48 -  1.21
+++ ldomctl.8   3 Jan 2020 20:45:33 -
@@ -63,12 +63,17 @@ The download is aborted if a configurati
 .It Cm dump
 Dump the current configuration from non-volatile storage into the current
 working directory.
-.It Cm init-system Ar file
+.It Cm init-system Oo Fl n Oc Ar file
 Generate files in the current working directory for a logical domain
 configuration
 .Ar file
 as described in
 .Xr ldom.conf 5 .
+.Bl -tag -width Fl
+.It Fl n
+Configtest mode.
+Only check the configuration file for validty.
+.El
 .It Cm list
 List configurations stored in non-volatile storage.
 Indicate the currently running configuration,
Index: ldomctl.c
===
RCS file: /cvs/src/usr.sbin/ldomctl/ldomctl.c,v
retrieving revision 1.32
diff -u -p -r1.32 ldomctl.c
--- ldomctl.c   3 Jan 2020 19:45:51 -   1.32
+++ ldomctl.c   3 Jan 2020 20:45:34 -
@@ -129,7 +129,7 @@ usage(void)
fprintf(stderr, "usage:\t%1$s delete|select configuration\n"
"\t%1$s download directory\n"
"\t%1$s dump|list|list-io\n"
-   "\t%1$s init-system file\n"
+   "\t%1$s init-system [-n] file\n"
"\t%1$s create-vdisk -s size file\n"
"\t%1$s console|panic|start|status|stop [domain]\n", getprogname());
exit(EXIT_FAILURE);
@@ -241,12 +241,27 @@ dump(int argc, char **argv)
 void
 init_system(int argc, char **argv)
 {
-   if (argc != 2)
+   int ch, noaction = 0;
+
+   while ((ch = getopt(argc, argv, "n")) != -1) {
+   switch (ch) {
+   case 'n':
+   noaction = 1;
+   break;
+   default:
+   usage();
+   }
+   }
+   argc -= optind;
+   argv += optind;
+
+   if (argc != 1)
usage();
 
-   hv_config();
+   if (!noaction)
+   hv_config();
 
-   build_config(argv[1]);
+   build_config(argv[0], noaction);
 }
 
 void
Index: ldomctl.h
===
RCS file: /cvs/src/usr.sbin/ldomctl/ldomctl.h,v
retrieving revision 1.11
diff -u -p -r1.11 ldomctl.h
--- ldomctl.h   28 Nov 2019 18:03:33 -  1.11
+++ ldomctl.h   3 Jan 2020 20:45:34 -
@@ -193,5 +193,5 @@ struct ldom_config {
 };
 
 int parse_config(const char *, struct ldom_config *);
-void build_config(const char *);
+void build_config(const char *, int);
 void list_components(void);