# HG changeset patch # User Rob Landley # Date 1372016311 18000 # Node ID d0ab54f6234604f065b3137550b64131c320f515 # Parent a81921ce493016898c9ff45cc92c807290d76c9d Modinfo cleanups. Don't use xopen() if you want to iterate through multiple files. Don't abort if unable to open the file, but return error if it can't map it. (And leak the filehandle.) All modinfo_file() actually uses is the filename, no reason to go through dirtree() for that. Nothing is actually _checking_ the return value of modinfo_file(). Avoid global data outside of toy_union. Make sure extension is at end of file (we can add support for more extensions later). diff -r a81921ce4930 -r d0ab54f62346 toys/other/modinfo.c --- a/toys/other/modinfo.c Sun Jun 23 14:02:16 2013 -0500 +++ b/toys/other/modinfo.c Sun Jun 23 14:38:31 2013 -0500 @@ -20,39 +20,33 @@ long mod; ) -static char *modinfo_tags[] = { - "alias", "license", "description", "author", "firmware", - "vermagic", "srcversion", "intree", "parm", "depends", -}; - static void output_field(char *field, char *value) { - int len; - - if (TT.field && strcmp(TT.field, field)) return; - - len = strlen(field); - - if (TT.field) xprintf("%s", value); - else xprintf("%s:%*s%s", field, 15 - len, "", value); + if (!TT.field) xprintf("%s:%*c", field, 15 - strlen(field), ' '); + else if (!strcmp(TT.field, field)) return; + xprintf("%s", value); xputc((toys.optflags & FLAG_0) ? 0 : '\n'); } -static int modinfo_file(struct dirtree *dir) +static void modinfo_file(char *full_name) { int fd, len, i; - char *buf, *pos, *full_name; + char *buf = 0, *pos, *modinfo_tags[] = { + "alias", "license", "description", "author", "firmware", + "vermagic", "srcversion", "intree", "parm", "depends", + }; - full_name = dirtree_path(dir, NULL); + if (-1 != (fd = open(full_name, O_RDONLY))) { + len = fdlength(fd); + if (!(buf = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0))) close(fd); + } + + if (!buf) { + perror_msg("%s", full_name); + return; + } + output_field("filename", full_name); - fd = xopen(full_name, O_RDONLY); - free(full_name); - - len = fdlength(fd); - if (!(buf = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0))) { - perror_msg("mmap %s", full_name); - return 1; - } for (pos = buf; pos < buf+len; pos++) { if (*pos) continue; @@ -68,7 +62,6 @@ munmap(buf, len); close(fd); - return 0; } static int check_module(struct dirtree *new) @@ -87,7 +80,10 @@ } if (s[len] || strcmp(new->name+len, ".ko")) break; - modinfo_file(new); + modinfo_file(s = dirtree_path(new, NULL)); + free(s); + + return DIRTREE_ABORT; } } @@ -96,15 +92,15 @@ void modinfo_main(void) { - struct utsname uts; - - if (uname(&uts) < 0) perror_exit("bad uname"); - sprintf(toybuf, "/lib/modules/%s", uts.release); + for(TT.mod = 0; TT.mod