+ struct module_info info;
+ char *module_names, *mn, *deps, *dn;
+ size_t bufsize, nmod, count, i, j;
+
+ module_names = xmalloc(bufsize = 256);
+ deps = xmalloc(bufsize);
+ if (query_module(NULL, QM_MODULES, module_names, bufsize, &nmod)) {
+ fatalError("QM_MODULES: %s\n", strerror(errno));
+ }
+
+ printf("Module Size Used by\n");
+ for (i = 0, mn = module_names; i < nmod; mn += strlen(mn) + 1, i++) {
+ if (query_module(mn, QM_INFO, &info, sizeof(info), &count)) {
+ if (errno == ENOENT) {
+ /* The module was removed out from underneath us. */
+ continue;
+ }
+ /* else choke */
+ fatalError("module %s: QM_INFO: %s\n", mn, strerror(errno));
+ }
+ while (query_module(mn, QM_REFS, deps, bufsize, &count)) {
+ if (errno == ENOENT) {
+ /* The module was removed out from underneath us. */
+ continue;
+ }
+ if (errno != ENOSPC) {
+ fatalError("module %s: QM_REFS: %s", mn, strerror(errno));
+ }
+ deps = xrealloc(deps, bufsize = count);
+ }
+ printf("%-20s%8lu%4ld ", mn, info.size, info.usecount);
+ if (count) printf("[");
+ for (j = 0, dn = deps; j < count; dn += strlen(dn) + 1, j++) {
+ printf("%s%s", dn, (j==count-1)? "":" ");
+ }
+ if (count) printf("] ");
+
+ if (info.flags & NEW_MOD_DELETED)
+ printf("(deleted)");
+ else if (info.flags & NEW_MOD_INITIALIZING)
+ printf("(initializing)");
+ else if (!(info.flags & NEW_MOD_RUNNING))
+ printf("(uninitialized)");
+ else {
+ if (info.flags & NEW_MOD_AUTOCLEAN)
+ printf("(autoclean) ");
+ if (!(info.flags & NEW_MOD_USED_ONCE))
+ printf("(unused)");
+ }
+ printf("\n");
+ }
+