Re: [PATCH v3] tools: add static-nodes tool
Thomas Bächler <thomas-fd97jBR+K/[email protected]>
| Newsgroups | gmane.linux.kernel.modules,gmane.linux.hotplug.devel,gmane.comp.sysutils.systemd.devel |
|---|---|
| Message-ID | <[email protected]> |
Am 16.04.2013 15:12, schrieb Tom Gundersen:
> +static void write_human(FILE *out, char module[], char devname[], char type, unsigned int maj, unsigned int min)
[...]
> +static void write_tmpfile(FILE *out, char devname[], char type, unsigned int maj, unsigned int min)
[...]
> +static int do_static_nodes(int argc, char *argv[])
> +{
> + struct utsname kernel;
> + char modules[PATH_MAX];
> + FILE *in = NULL, *out = stdout;
> + bool human_readable = 1;
This code emphasizes that there is actually only one format available
and needs to be changed again when another one is added. Why not
void (*write_output)((FILE *, char[], char[], char, unsigned int,
unsigned int) = write_human;
? Then ...
> + case 'f':
> + if (!streq(optarg, "tmpfiles")) {
> + fprintf(stderr, "Unknown format: '%s'.\n", argv[1]);
> + help();
> + ret = EXIT_FAILURE;
> + goto finish;
> + }
> + human_readable = 0;
> + break;
case 'f':
if (streq(optarg, "tmpfiles")) {
write_output = write_tmpfiles;
}
else {
fprintf(stderr, "Unknown format: '%s'.\n", argv[1]);
[...]
}
break;
And in the end:
> + if (human_readable)
> + write_human(out, module, devname, type, maj, min);
> + else
> + write_tmpfile(out, devname, type, maj, min);
write_output(out, module, devname, type, maj, min);
Maybe even add an array with output name and function pointer pairs, so
that we could get a list of available formats using --format=?. For
consistency, --format=human should also work. Just seems nicer to me, in
case someone actually plans to extend this later.
signature.asc
(application/pgp-signature, 901 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJRbVbfAAoJEChPw0yOSxolIKcP/0aH6YYCyGQRQi28w4jMyp3/ 67Ah8hOd6ppEbFSFG9GHCNBkpa11SNsV7jYUkw1XLNipUiXrAgI6rF6t8/PxV62a CI49ShXSDZxH6iStKIJKw1B6fBMArva2htZzp1zDY4EmtxSiWoIn7ovQ+G5Gvua0 LWZQ/p3XfFFlfu4NtoIyFCHwWVu4Xw2c7iZCJNvegT038ETlpg2G2a9nUtoz0DrS iKhec7bP2AkZDYy1epOUYHOI4wHfo4GQ+i+tGlVtGpuglr+mc5UoFT8AV7qYa4Kj 7oaIm6Dh5j6pup7x3jTWqOS2MKgWxqRC0wfFRfcE4WEnJS9mPYG2ds1xBnaA+4QM EVw4IgRjL7yKwq2cHR19h6KoGMxpIoWKNbSgFEZCcm6ySQcEV3TOJ+EzyrMzZOu+ G77IL7rfAGv+8wh5x9Lp2pnEZazBE423ZVgVqPSGooax5bQJXvECNhnCvX6oyG6R 7npIk4o7qy/6zNtn7nAgL67AU62bR+fCQnjc9wi3l6kTR8aTdWshfV65t82H+D7+ 4HG4k7UUE5P8WuK/LO/1vkNEeGJNvzZSjVs1c1afc31AGTrb9WORAHdXSlPe6hk2 dTIaRdFSyK0HNPcAGVKzrrcTrTsuXL1LGqOtUvKnwkSz8Y66yVEoJt7eHOr/aPbF sYehngEcXEF3aa9rUw2r =xL2M -----END PGP SIGNATURE-----