diff options
Diffstat (limited to 'modutils/modutils.c')
| -rw-r--r-- | modutils/modutils.c | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/modutils/modutils.c b/modutils/modutils.c index f437a9829..969926db9 100644 --- a/modutils/modutils.c +++ b/modutils/modutils.c | |||
| @@ -25,7 +25,7 @@ void FAST_FUNC replace(char *s, char what, char with) | |||
| 25 | } | 25 | } |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | char * FAST_FUNC replace_underscores(char *s) | 28 | char* FAST_FUNC replace_underscores(char *s) |
| 29 | { | 29 | { |
| 30 | replace(s, '-', '_'); | 30 | replace(s, '-', '_'); |
| 31 | return s; | 31 | return s; |
| @@ -45,7 +45,7 @@ int FAST_FUNC string_to_llist(char *string, llist_t **llist, const char *delim) | |||
| 45 | return len; | 45 | return len; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | char * FAST_FUNC filename2modname(const char *filename, char *modname) | 48 | char* FAST_FUNC filename2modname(const char *filename, char *modname) |
| 49 | { | 49 | { |
| 50 | int i; | 50 | int i; |
| 51 | char *from; | 51 | char *from; |
| @@ -62,24 +62,6 @@ char * FAST_FUNC filename2modname(const char *filename, char *modname) | |||
| 62 | return modname; | 62 | return modname; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | const char * FAST_FUNC moderror(int err) | ||
| 66 | { | ||
| 67 | switch (err) { | ||
| 68 | case -1: | ||
| 69 | return "no such module"; | ||
| 70 | case ENOEXEC: | ||
| 71 | return "invalid module format"; | ||
| 72 | case ENOENT: | ||
| 73 | return "unknown symbol in module, or unknown parameter"; | ||
| 74 | case ESRCH: | ||
| 75 | return "module has wrong symbol version"; | ||
| 76 | case ENOSYS: | ||
| 77 | return "kernel does not support requested operation"; | ||
| 78 | default: | ||
| 79 | return strerror(err); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | char * FAST_FUNC parse_cmdline_module_options(char **argv) | 65 | char * FAST_FUNC parse_cmdline_module_options(char **argv) |
| 84 | { | 66 | { |
| 85 | char *options; | 67 | char *options; |
| @@ -95,6 +77,11 @@ char * FAST_FUNC parse_cmdline_module_options(char **argv) | |||
| 95 | return options; | 77 | return options; |
| 96 | } | 78 | } |
| 97 | 79 | ||
| 80 | /* Return: | ||
| 81 | * 0 on success, | ||
| 82 | * -errno on open/read error, | ||
| 83 | * errno on init_module() error | ||
| 84 | */ | ||
| 98 | int FAST_FUNC bb_init_module(const char *filename, const char *options) | 85 | int FAST_FUNC bb_init_module(const char *filename, const char *options) |
| 99 | { | 86 | { |
| 100 | size_t len; | 87 | size_t len; |
| @@ -104,6 +91,7 @@ int FAST_FUNC bb_init_module(const char *filename, const char *options) | |||
| 104 | if (!options) | 91 | if (!options) |
| 105 | options = ""; | 92 | options = ""; |
| 106 | 93 | ||
| 94 | //TODO: audit bb_init_module_24 to match error code convention | ||
| 107 | #if ENABLE_FEATURE_2_4_MODULES | 95 | #if ENABLE_FEATURE_2_4_MODULES |
| 108 | if (get_linux_version_code() < KERNEL_VERSION(2,6,0)) | 96 | if (get_linux_version_code() < KERNEL_VERSION(2,6,0)) |
| 109 | return bb_init_module_24(filename, options); | 97 | return bb_init_module_24(filename, options); |
| @@ -111,19 +99,40 @@ int FAST_FUNC bb_init_module(const char *filename, const char *options) | |||
| 111 | 99 | ||
| 112 | /* Use the 2.6 way */ | 100 | /* Use the 2.6 way */ |
| 113 | len = INT_MAX - 4095; | 101 | len = INT_MAX - 4095; |
| 114 | rc = ENOENT; | 102 | errno = ENOMEM; /* may be changed by e.g. open errors below */ |
| 115 | image = xmalloc_open_zipped_read_close(filename, &len); | 103 | image = xmalloc_open_zipped_read_close(filename, &len); |
| 116 | if (image) { | 104 | if (!image) |
| 117 | rc = 0; | 105 | return -errno; |
| 118 | if (init_module(image, len, options) != 0) | ||
| 119 | rc = errno; | ||
| 120 | free(image); | ||
| 121 | } | ||
| 122 | 106 | ||
| 107 | errno = 0; | ||
| 108 | init_module(image, len, options); | ||
| 109 | rc = errno; | ||
| 110 | free(image); | ||
| 123 | return rc; | 111 | return rc; |
| 124 | } | 112 | } |
| 125 | 113 | ||
| 126 | int FAST_FUNC bb_delete_module(const char *module, unsigned int flags) | 114 | int FAST_FUNC bb_delete_module(const char *module, unsigned int flags) |
| 127 | { | 115 | { |
| 128 | return delete_module(module, flags); | 116 | errno = 0; |
| 117 | delete_module(module, flags); | ||
| 118 | return errno; | ||
| 119 | } | ||
| 120 | |||
| 121 | const char* FAST_FUNC moderror(int err) | ||
| 122 | { | ||
| 123 | switch (err) { | ||
| 124 | case -1: /* btw: it's -EPERM */ | ||
| 125 | return "no such module"; | ||
| 126 | case ENOEXEC: | ||
| 127 | return "invalid module format"; | ||
| 128 | case ENOENT: | ||
| 129 | return "unknown symbol in module, or unknown parameter"; | ||
| 130 | case ESRCH: | ||
| 131 | return "module has wrong symbol version"; | ||
| 132 | case ENOSYS: | ||
| 133 | return "kernel does not support requested operation"; | ||
| 134 | } | ||
| 135 | if (err < 0) /* should always be */ | ||
| 136 | err = -err; | ||
| 137 | return strerror(err); | ||
| 129 | } | 138 | } |
