Tom Gundersen
2013-07-14 11:56:17 UTC
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);
+ 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) {
+ out = fopen(output, "we");
+ if (out == NULL) {
+ fprintf(stderr, "Error: could not create %s!\n",
+ output);
+ ret = EXIT_FAILURE;
+ goto finish;
+ }
+ }
+
while (fgets(buf, sizeof(buf), in) != NULL) {
char modname[PATH_MAX];
char devname[PATH_MAX];
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);
+ 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) {
+ out = fopen(output, "we");
+ if (out == NULL) {
+ fprintf(stderr, "Error: could not create %s!\n",
+ output);
+ ret = EXIT_FAILURE;
+ goto finish;
+ }
+ }
+
while (fgets(buf, sizeof(buf), in) != NULL) {
char modname[PATH_MAX];
char devname[PATH_MAX];
--
1.8.3.2
1.8.3.2