diff options
author | Matt Kraai <kraai@debian.org> | 2001-04-13 14:40:15 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2001-04-13 14:40:15 +0000 |
commit | 0f50bca9aaae78fd23a2ab7890e81c88473a4a25 (patch) | |
tree | 71e0b976e816ab3a2f34e68d1d7dca2d4e817a5e /modutils | |
parent | 445fb952b8becc78889d3079e3053f76aa2eba9c (diff) | |
download | busybox-w32-0f50bca9aaae78fd23a2ab7890e81c88473a4a25.tar.gz busybox-w32-0f50bca9aaae78fd23a2ab7890e81c88473a4a25.tar.bz2 busybox-w32-0f50bca9aaae78fd23a2ab7890e81c88473a4a25.zip |
Fix infinite loop and reallocate if too many modules.
Diffstat (limited to 'modutils')
-rw-r--r-- | modutils/lsmod.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/modutils/lsmod.c b/modutils/lsmod.c index 0f1b09b9e..76ed2fdd8 100644 --- a/modutils/lsmod.c +++ b/modutils/lsmod.c | |||
@@ -69,19 +69,36 @@ static const int NEW_MOD_VISITED = 8; | |||
69 | static const int NEW_MOD_USED_ONCE = 16; | 69 | static const int NEW_MOD_USED_ONCE = 16; |
70 | static const int NEW_MOD_INITIALIZING = 64; | 70 | static const int NEW_MOD_INITIALIZING = 64; |
71 | 71 | ||
72 | static int my_query_module(const char *name, int which, void **buf, | ||
73 | size_t *bufsize, size_t *ret) | ||
74 | { | ||
75 | int my_ret; | ||
76 | |||
77 | my_ret = query_module(name, which, *buf, *bufsize, ret); | ||
78 | |||
79 | if (my_ret == -1 && errno == ENOSPC) { | ||
80 | *buf = xrealloc(*buf, *ret); | ||
81 | *bufsize = *ret; | ||
82 | |||
83 | my_ret = query_module(name, which, *buf, *bufsize, ret); | ||
84 | } | ||
85 | |||
86 | return my_ret; | ||
87 | } | ||
72 | 88 | ||
73 | extern int lsmod_main(int argc, char **argv) | 89 | extern int lsmod_main(int argc, char **argv) |
74 | { | 90 | { |
75 | struct module_info info; | 91 | struct module_info info; |
76 | char *module_names, *mn, *deps, *dn; | 92 | char *module_names, *mn, *deps, *dn; |
77 | size_t bufsize, nmod, count, i, j; | 93 | size_t bufsize, depsize, nmod, count, i, j; |
78 | 94 | ||
79 | module_names = xmalloc(bufsize = 256); | 95 | module_names = xmalloc(bufsize = 256); |
80 | deps = xmalloc(bufsize); | 96 | if (my_query_module(NULL, QM_MODULES, (void **)&module_names, &bufsize, |
81 | if (query_module(NULL, QM_MODULES, module_names, bufsize, &nmod)) { | 97 | &nmod)) { |
82 | perror_msg_and_die("QM_MODULES"); | 98 | perror_msg_and_die("QM_MODULES"); |
83 | } | 99 | } |
84 | 100 | ||
101 | deps = xmalloc(depsize = 256); | ||
85 | printf("Module Size Used by\n"); | 102 | printf("Module Size Used by\n"); |
86 | for (i = 0, mn = module_names; i < nmod; mn += strlen(mn) + 1, i++) { | 103 | for (i = 0, mn = module_names; i < nmod; mn += strlen(mn) + 1, i++) { |
87 | if (query_module(mn, QM_INFO, &info, sizeof(info), &count)) { | 104 | if (query_module(mn, QM_INFO, &info, sizeof(info), &count)) { |
@@ -92,15 +109,12 @@ extern int lsmod_main(int argc, char **argv) | |||
92 | /* else choke */ | 109 | /* else choke */ |
93 | perror_msg_and_die("module %s: QM_INFO", mn); | 110 | perror_msg_and_die("module %s: QM_INFO", mn); |
94 | } | 111 | } |
95 | while (query_module(mn, QM_REFS, deps, bufsize, &count)) { | 112 | if (my_query_module(mn, QM_REFS, (void **)&deps, &depsize, &count)) { |
96 | if (errno == ENOENT) { | 113 | if (errno == ENOENT) { |
97 | /* The module was removed out from underneath us. */ | 114 | /* The module was removed out from underneath us. */ |
98 | continue; | 115 | continue; |
99 | } | 116 | } |
100 | if (errno != ENOSPC) { | 117 | perror_msg_and_die("module %s: QM_REFS", mn); |
101 | error_msg_and_die("module %s: QM_REFS", mn); | ||
102 | } | ||
103 | deps = xrealloc(deps, bufsize = count); | ||
104 | } | 118 | } |
105 | printf("%-20s%8lu%4ld ", mn, info.size, info.usecount); | 119 | printf("%-20s%8lu%4ld ", mn, info.size, info.usecount); |
106 | if (info.flags & NEW_MOD_DELETED) | 120 | if (info.flags & NEW_MOD_DELETED) |