linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] static-nodes: don't fail if modules.devname not found
@ 2013-07-14 11:56 Tom Gundersen
  2013-07-14 11:56 ` [PATCH 2/2] static-nodes: create parent directories of output file Tom Gundersen
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Tom Gundersen @ 2013-07-14 11:56 UTC (permalink / raw)
  To: linux-modules; +Cc: Tom Gundersen

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];
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-07-14 19:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 1/2] static-nodes: don't fail if modules.devname not found Dave Reisner
2013-07-14 13:02   ` Tom Gundersen
2013-07-14 19:57 ` Kay Sievers

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).