Skip to contentSkip to conversation

depmod: Don't insert comment in modules.devname if otherwise empty

PATCH Applied Josh Triplett 3 participants 4 messages Jan 10, 2016 – Jan 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 depmod: Don't insert comment in modules.devname if otherwise empty

This allows tools to detect the file as empty, such as via systemd's ConditionFileNotEmpty.
---

The string constant extends past 80 columns, per CODING-STYLE.

The motivation for this patch came from Debian bug 810367. This change would allow kmod-static-nodes.service to use ConditionFileNotEmpty instead of ConditionPathExists.

 tools/depmod.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
tools/depmod.c +8 -4
index a585d47..6e9bb4d 100644
@@ -1999,8 +1999,7 @@ static int output_builtin_bin(struct depmod *depmod, FILE *out)
 static int output_devname(struct depmod *depmod, FILE *out)
 {
 	size_t i;
-
-	fputs("# Device nodes to trigger on-demand module loading.\n", out);
+	bool empty = true;
 
 	for (i = 0; i < depmod->modules.count; i++) {
 		const struct mod *mod = depmod->modules.array[i];
@@ -2036,10 +2035,15 @@ static int output_devname(struct depmod *depmod, FILE *out)
 		}
 
 		if (devname != NULL) {
-			if (type != '\0')
+			if (type != '\0') {
+				if (empty) {
+					fputs("# Device nodes to trigger on-demand module loading.\n",
+					      out);
+					empty = false;
+				}
 				fprintf(out, "%s %s %c%u:%u\n", mod->modname,
 					devname, type, major, minor);
-			else
+                        } else
 				ERR("Module '%s' has devname (%s) but "
 				    "lacks major and minor information. "
 				    "Ignoring.\n", mod->modname, devname);
Signature · 1 line
2.7.0.rc3
#1 lore raw
Quoted 36 lines · Josh Triplett

This allows tools to detect the file as empty, such as via systemd's ConditionFileNotEmpty.
---

The string constant extends past 80 columns, per CODING-STYLE.

The motivation for this patch came from Debian bug 810367. This change would allow kmod-static-nodes.service to use ConditionFileNotEmpty instead of ConditionPathExists.

 tools/depmod.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
tools/depmod.c +5 -3
index a585d47..6e9bb4d 100644
@@ -1999,8 +1999,7 @@ static int output_builtin_bin(struct depmod *depmod, FILE *out)
 static int output_devname(struct depmod *depmod, FILE *out)
 {
        size_t i;
-
-       fputs("# Device nodes to trigger on-demand module loading.\n", out);
+       bool empty = true;
 
        for (i = 0; i < depmod->modules.count; i++) {
                const struct mod *mod = depmod->modules.array[i];
@@ -2036,10 +2035,15 @@ static int output_devname(struct depmod *depmod, FILE *out)
                }
 
                if (devname != NULL) {
-                       if (type != '\0')
+                       if (type != '\0') {
+                               if (empty) {
+                                       fputs("# Device nodes to trigger on-demand module loading.\n",
+                                             out);

tools/depmod.c static int output_devname(struct depmod *depmod, FILE *out)

Quoted 10 lines
tools/depmod.c +3 -2
+                                       empty = false;
+                               }
                                fprintf(out, "%s %s %c%u:%u\n", mod->modname,
                                        devname, type, major, minor);
-                       else
+                        } else
                                ERR("Module '%s' has devname (%s) but "
                                    "lacks major and minor information. "
                                    "Ignoring.\n", mod->modname, devname);
--

Applied, thanks.

Lucas De Marchi

#2 lore raw

Re: Bug#810367: [PATCH] depmod: Don't insert comment in modules.devname if otherwise empty

Hey Josh, Lucas,

Lucas De Marchi [2016-01-11 10:43 -0200]:

Quoted 3 lines · Josh Triplett
Quoted 2 lines

This allows tools to detect the file as empty, such as via systemd's ConditionFileNotEmpty.

As pointed out on https://github.com/systemd/systemd/pull/2301: Why does this file get created at all if it's going to be empty?

Thanks,

Martin

Signature · 2 lines
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
#3 lore raw

Re: Bug#810367: [PATCH] depmod: Don't insert comment in modules.devname if otherwise empty

Hi Martin

Quoted 9 lines · Martin Pitt

Hey Josh, Lucas,

Lucas De Marchi [2016-01-11 10:43 -0200]:

Quoted 3 lines · Josh Triplett
Quoted 2 lines

This allows tools to detect the file as empty, such as via systemd's ConditionFileNotEmpty.

As pointed out on https://github.com/systemd/systemd/pull/2301: Why does this file get created at all if it's going to be empty?

The only reason I can think of is to avoid breaking current programs that depend on its existence since it is created since forever.

Lucas De Marchi