From: Dave Reisner <d@falconindy.com>
To: Tom Gundersen <teg@jklm.no>
Cc: linux-modules@vger.kernel.org
Subject: Re: [PATCH 1/2] static-nodes: don't fail if modules.devname not found
Date: Sun, 14 Jul 2013 08:29:45 -0400 [thread overview]
Message-ID: <20130714122945.GB558@rampage> (raw)
In-Reply-To: <1373802978-12456-1-git-send-email-teg@jklm.no>
On Sun, Jul 14, 2013 at 01:56:17PM +0200, Tom Gundersen wrote:
> In containers/VM's/initrd one might not have installed any modules and accompanying modules.devname
> Don't fail if this is the case, just warn.
>
> When used in systemd this means we don't get a failing unit on booting containers.
> ---
> tools/static-nodes.c | 32 ++++++++++++++++++++++----------
> 1 file changed, 22 insertions(+), 10 deletions(-)
>
> diff --git a/tools/static-nodes.c b/tools/static-nodes.c
> index 96bb71e..b4a3c08 100644
> --- a/tools/static-nodes.c
> +++ b/tools/static-nodes.c
> @@ -155,6 +155,7 @@ static int do_static_nodes(int argc, char *argv[])
> {
> struct utsname kernel;
> char modules[PATH_MAX];
> + char output[PATH_MAX];
> FILE *in = NULL, *out = stdout;
> const struct static_nodes_format *format = &static_nodes_format_human;
> char buf[4096];
> @@ -170,13 +171,8 @@ static int do_static_nodes(int argc, char *argv[])
> }
> switch (c) {
> case 'o':
> - out = fopen(optarg, "we");
> - if (out == NULL) {
> - fprintf(stderr, "Error: could not create %s!\n",
> - optarg);
> - ret = EXIT_FAILURE;
> - goto finish;
> - }
> + strncpy(output, optarg, PATH_MAX);
No need to copy anything here, just retain a pointer to this optarg.
> + out = NULL;
> break;
> case 'f':
> valid = 0;
> @@ -221,12 +217,28 @@ static int do_static_nodes(int argc, char *argv[])
> kernel.release);
> in = fopen(modules, "re");
> if (in == NULL) {
> - fprintf(stderr, "Error: could not open /lib/modules/%s/modules.devname - %m\n",
> - kernel.release);
> - ret = EXIT_FAILURE;
> + if (errno == ENOENT) {
> + fprintf(stderr, "Warning: /lib/modules/%s/modules.devname not found - ignoring\n",
> + kernel.release);
> + ret = EXIT_SUCCESS;
> + } else {
> + fprintf(stderr, "Error: could not open /lib/modules/%s/modules.devname - %m\n",
> + kernel.release);
> + ret = EXIT_FAILURE;
> + }
> goto finish;
> }
>
> + if (out == NULL) {
It took me a minute to realize why this was the correct comparison.
Maybe it's just me, but I think this would be more readable if we did
something like the below psuedocode
const char* output = "/dev/stderr";
/* do option parsing, maybe reassigning 'output' */
/* now open the file, regardless of what it is */
FILE* out = fopen(output, "we");
if (out == NULL)
...
Seems a bit cleaner to me, even if it duplicates a file descriptor (but
we'll open a new FILE regardless in the common use case).
> + out = fopen(output, "we");
> + if (out == NULL) {
> + fprintf(stderr, "Error: could not create %s!\n",
> + output);
I realize this is copied from the old code, but there's no explanation
as to why this failed. Add an %m token to the format string?
> + ret = EXIT_FAILURE;
> + goto finish;
> + }
> + }
> +
> while (fgets(buf, sizeof(buf), in) != NULL) {
> char modname[PATH_MAX];
> char devname[PATH_MAX];
> --
> 1.8.3.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-modules" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2013-07-14 12:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-14 11:56 [PATCH 1/2] static-nodes: don't fail if modules.devname not found Tom Gundersen
2013-07-14 11:56 ` [PATCH 2/2] static-nodes: create parent directories of output file Tom Gundersen
2013-07-14 12:29 ` Dave Reisner [this message]
2013-07-14 13:02 ` [PATCH 1/2] static-nodes: don't fail if modules.devname not found Tom Gundersen
2013-07-14 19:57 ` Kay Sievers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130714122945.GB558@rampage \
--to=d@falconindy.com \
--cc=linux-modules@vger.kernel.org \
--cc=teg@jklm.no \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).