diff options
author | Tom Gundersen <teg@jklm.no> | 2013-07-14 15:13:33 +0200 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2013-07-15 12:44:33 -0300 |
commit | ae17710117628de46d67ff28e545b52a45bd268e (patch) | |
tree | 59e9db8d906158fbebd31109826a7f5e9403069e | |
parent | 85d02ebea38a782a23c4af65619d253dc08f8a26 (diff) | |
download | kmod-ae17710117628de46d67ff28e545b52a45bd268e.tar.gz |
static-nodes: don't fail if modules.devname not found
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.
-rw-r--r-- | tools/static-nodes.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/tools/static-nodes.c b/tools/static-nodes.c index 96bb71e..351c02b 100644 --- a/tools/static-nodes.c +++ b/tools/static-nodes.c @@ -155,7 +155,8 @@ static int do_static_nodes(int argc, char *argv[]) { struct utsname kernel; char modules[PATH_MAX]; - FILE *in = NULL, *out = stdout; + const char *output = "/dev/stdout"; + FILE *in = NULL, *out = NULL; const struct static_nodes_format *format = &static_nodes_format_human; char buf[4096]; int ret = EXIT_SUCCESS; @@ -170,13 +171,7 @@ 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; - } + output = optarg; break; case 'f': valid = 0; @@ -217,12 +212,24 @@ static int do_static_nodes(int argc, char *argv[]) goto finish; } - snprintf(modules, sizeof(modules), "/lib/modules/%s/modules.devname", - kernel.release); + snprintf(modules, sizeof(modules), "/lib/modules/%s/modules.devname", kernel.release); in = fopen(modules, "re"); if (in == NULL) { - fprintf(stderr, "Error: could not open /lib/modules/%s/modules.devname - %m\n", - kernel.release); + 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; + } + + out = fopen(output, "we"); + if (out == NULL) { + fprintf(stderr, "Error: could not create %s - %m\n", output); ret = EXIT_FAILURE; goto finish; } |