[PATCH 1/2] depmod: change depfile functions to return int

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If a function returns zero, the file won't be generated

Signed-off-by: Michal Marek <mmarek@xxxxxxx>
---
 depmod.c |   36 ++++++++++++++++++++++++++----------
 tables.c |   24 ++++++++++++++++--------
 tables.h |   16 ++++++++--------
 3 files changed, 50 insertions(+), 26 deletions(-)

diff --git a/depmod.c b/depmod.c
index 4c8caa0..3ac5070 100644
--- a/depmod.c
+++ b/depmod.c
@@ -434,7 +434,7 @@ static const char *compress_path(const char *path, const char *basedir)
 	return path;
 }
 
-static void output_deps(struct module *modules,
+static int output_deps(struct module *modules,
 			FILE *out, char *dirname)
 {
 	struct module *i;
@@ -453,12 +453,13 @@ static void output_deps(struct module *modules,
 		}
 		fprintf(out, "\n");
 	}
+	return 1;
 }
 
 /* warn whenever duplicate module aliases, deps, or symbols are found. */
 int warn_dups = 0;
 
-static void output_deps_bin(struct module *modules,
+static int output_deps_bin(struct module *modules,
 			FILE *out, char *dirname)
 {
 	struct module *i;
@@ -495,6 +496,8 @@ static void output_deps_bin(struct module *modules,
 	
 	index_write(index, out);
 	index_destroy(index);
+
+	return 1;
 }
 
 
@@ -769,7 +772,7 @@ static struct module *parse_modules(struct module *list)
 }
 
 /* Simply dump hash table. */
-static void output_symbols(struct module *unused, FILE *out, char *dirname)
+static int output_symbols(struct module *unused, FILE *out, char *dirname)
 {
 	unsigned int i;
 
@@ -786,9 +789,10 @@ static void output_symbols(struct module *unused, FILE *out, char *dirname)
 			}
 		}
 	}
+	return 1;
 }
 
-static void output_symbols_bin(struct module *unused, FILE *out, char *dirname)
+static int output_symbols_bin(struct module *unused, FILE *out, char *dirname)
 {
 	struct index_node *index;
 	unsigned int i;
@@ -817,9 +821,11 @@ static void output_symbols_bin(struct module *unused, FILE *out, char *dirname)
 	
 	index_write(index, out);
 	index_destroy(index);
+
+	return 1;
 }
 
-static void output_aliases(struct module *modules, FILE *out, char *dirname)
+static int output_aliases(struct module *modules, FILE *out, char *dirname)
 {
 	struct module *i;
 	struct elf_file *file;
@@ -849,9 +855,10 @@ static void output_aliases(struct module *modules, FILE *out, char *dirname)
 		}
 		strtbl_free(tbl);
 	}
+	return 1;
 }
 
-static void output_aliases_bin(struct module *modules, FILE *out, char *dirname)
+static int output_aliases_bin(struct module *modules, FILE *out, char *dirname)
 {
 	struct module *i;
 	struct elf_file *file;
@@ -901,11 +908,13 @@ static void output_aliases_bin(struct module *modules, FILE *out, char *dirname)
 	
 	index_write(index, out);
 	index_destroy(index);
+
+	return 1;
 }
 
 struct depfile {
 	char *name;
-	void (*func)(struct module *, FILE *, char *dirname);
+	int (*func)(struct module *, FILE *, char *dirname);
 	int map_file;
 };
 
@@ -1368,6 +1377,7 @@ int main(int argc, char *argv[])
 
 	for (i = 0; i < sizeof(depfiles)/sizeof(depfiles[0]); i++) {
 		FILE *out;
+		int res;
 		struct depfile *d = &depfiles[i];
 		char depname[strlen(dirname) + 1 + strlen(d->name) + 1];
 		char tmpname[strlen(dirname) + 1 + strlen(d->name) +
@@ -1388,12 +1398,18 @@ int main(int argc, char *argv[])
 			if (ends_in(depname, ".bin"))
 				continue;
 		}
-		d->func(list, out, dirname);
-		if (!doing_stdout) {
-			fclose(out);
+		res = d->func(list, out, dirname);
+		if (doing_stdout)
+			continue;
+		fclose(out);
+		if (res) {
 			if (rename(tmpname, depname) < 0)
 				fatal("Could not rename %s into %s: %s\n",
 					tmpname, depname, strerror(errno));
+		} else {
+			if (unlink(tmpname) < 0)
+				warn("Could not delete %s: %s\n",
+					tmpname, strerror(errno));
 		}
 	}
 
diff --git a/tables.c b/tables.c
index 2f44450..c862920 100644
--- a/tables.c
+++ b/tables.c
@@ -34,7 +34,7 @@ static void output_pci_entry(struct pci_device_id *pci, char *name, FILE *out,
 		END(pci->class_mask, conv));
 }
 
-void output_pci_table(struct module *modules, FILE *out, char *dirname)
+int output_pci_table(struct module *modules, FILE *out, char *dirname)
 {
 	struct module *i;
 
@@ -53,6 +53,7 @@ void output_pci_table(struct module *modules, FILE *out, char *dirname)
 		for (e = t->pci_table; e->vendor; e = (void *)e + t->pci_size)
 			output_pci_entry(e, shortname, out, i->file->conv);
 	}
+	return 1;
 }
 
 /* We set driver_info to zero */
@@ -78,7 +79,7 @@ static void output_usb_entry(struct usb_device_id *usb, char *name, FILE *out,
 		END(usb->bInterfaceProtocol, conv));
 }
 
-void output_usb_table(struct module *modules, FILE *out, char *dirname)
+int output_usb_table(struct module *modules, FILE *out, char *dirname)
 {
 	struct module *i;
 
@@ -104,6 +105,7 @@ void output_usb_table(struct module *modules, FILE *out, char *dirname)
 		     e = (void *)e + t->usb_size)
 			output_usb_entry(e, shortname, out, i->file->conv);
 	}
+	return 1;
 }
 
 static void output_ieee1394_entry(struct ieee1394_device_id *fw, char *name,
@@ -118,7 +120,7 @@ static void output_ieee1394_entry(struct ieee1394_device_id *fw, char *name,
 		END(fw->version, conv));
 }
 
-void output_ieee1394_table(struct module *modules, FILE *out, char *dirname)
+int output_ieee1394_table(struct module *modules, FILE *out, char *dirname)
 {
 	struct module *i;
 
@@ -138,6 +140,7 @@ void output_ieee1394_table(struct module *modules, FILE *out, char *dirname)
 		     fw = (void *) fw + t->ieee1394_size)
 			output_ieee1394_entry(fw, shortname, out, i->file->conv);
 	}
+	return 1;
 }
 
 
@@ -151,7 +154,7 @@ static void output_ccw_entry(struct ccw_device_id *ccw, char *name, FILE *out,
 		END(ccw->dev_type, conv), END(ccw->dev_model, conv));
 }
 
-void output_ccw_table(struct module *modules, FILE *out, char *dirname)
+int output_ccw_table(struct module *modules, FILE *out, char *dirname)
 {
 	struct module *i;
 
@@ -172,6 +175,7 @@ void output_ccw_table(struct module *modules, FILE *out, char *dirname)
 		     e = (void *) e + t->ccw_size)
 			output_ccw_entry(e, shortname, out, i->file->conv);
 	}
+	return 1;
 }
 
 #define ISAPNP_VENDOR(a,b,c)	(((((a)-'A'+1)&0x3f)<<2)|\
@@ -192,7 +196,7 @@ static void put_isapnp_id(FILE *out, const char *id)
 	fprintf(out, " 0x%04x     0x%04x    ", vendor, device);
 }
 
-void output_isapnp_table(struct module *modules, FILE *out, char *dirname)
+int output_isapnp_table(struct module *modules, FILE *out, char *dirname)
 {
 	struct module *i;
 
@@ -238,6 +242,7 @@ void output_isapnp_table(struct module *modules, FILE *out, char *dirname)
 			}
 		}
 	}
+	return 1;
 }
 
 #define MATCH_bustype   1
@@ -412,7 +417,7 @@ static int output_input_entry_64_old(struct input_device_id_old_64 *input,
 	return 0;
 }
 
-void output_input_table(struct module *modules, FILE *out, char *dirname)
+int output_input_table(struct module *modules, FILE *out, char *dirname)
 {
 	struct module *i;
 
@@ -468,6 +473,7 @@ void output_input_table(struct module *modules, FILE *out, char *dirname)
 			}
 		}				
 	}
+	return 1;
 }
 
 static void output_serio_entry(struct serio_device_id *serio, char *name, FILE *out)
@@ -482,7 +488,7 @@ static void output_serio_entry(struct serio_device_id *serio, char *name, FILE *
 }
 
 
-void output_serio_table(struct module *modules, FILE *out, char *dirname)
+int output_serio_table(struct module *modules, FILE *out, char *dirname)
 {
 	struct module *i;
 
@@ -500,6 +506,7 @@ void output_serio_table(struct module *modules, FILE *out, char *dirname)
 		for (e = t->serio_table; e->type || e->proto; e = (void *)e + t->serio_size)
 			output_serio_entry(e, shortname, out);
 	}
+	return 1;
 }
 
 
@@ -542,7 +549,7 @@ static void output_of_entry(struct of_device_id *dev, char *name, FILE *out)
 	free(compatible);
 }
 
-void output_of_table(struct module *modules, FILE *out, char *dirname)
+int output_of_table(struct module *modules, FILE *out, char *dirname)
 {
 	struct module *i;
 
@@ -560,4 +567,5 @@ void output_of_table(struct module *modules, FILE *out, char *dirname)
                      e = (void *)e + t->of_size)
 			output_of_entry(e, shortname, out);
 	}
+	return 1;
 }
diff --git a/tables.h b/tables.h
index 8a1420f..920e8df 100644
--- a/tables.h
+++ b/tables.h
@@ -175,13 +175,13 @@ struct of_device_id {
 
 /* Functions provided by tables.c */
 struct module;
-void output_usb_table(struct module *modules, FILE *out, char *dirname);
-void output_ieee1394_table(struct module *modules, FILE *out, char *dirname);
-void output_pci_table(struct module *modules, FILE *out, char *dirname);
-void output_ccw_table(struct module *modules, FILE *out, char *dirname);
-void output_isapnp_table(struct module *modules, FILE *out, char *dirname);
-void output_input_table(struct module *modules, FILE *out, char *dirname);
-void output_serio_table(struct module *modules, FILE *out, char *dirname);
-void output_of_table(struct module *modules, FILE *out, char *dirname);
+int output_usb_table(struct module *modules, FILE *out, char *dirname);
+int output_ieee1394_table(struct module *modules, FILE *out, char *dirname);
+int output_pci_table(struct module *modules, FILE *out, char *dirname);
+int output_ccw_table(struct module *modules, FILE *out, char *dirname);
+int output_isapnp_table(struct module *modules, FILE *out, char *dirname);
+int output_input_table(struct module *modules, FILE *out, char *dirname);
+int output_serio_table(struct module *modules, FILE *out, char *dirname);
+int output_of_table(struct module *modules, FILE *out, char *dirname);
 
 #endif /* MODINITTOOLS_TABLES_H */
-- 
1.6.3.3

--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux