Fixed segfault with 'cut -f 1 -d:' and added 'cut -s' suport.
[oweals/busybox.git] / insmod.c
index dfea51832634f292d1eef5aef46b06a0fdc1df8c..00646887755be1c51baab0dd13d087648c91fdf4 100644 (file)
--- a/insmod.c
+++ b/insmod.c
@@ -40,6 +40,7 @@
 #include <assert.h>
 #include <sys/utsname.h>
 #include <sys/syscall.h>
+#include <linux/unistd.h>
 
 //----------------------------------------------------------------------------
 //--------modutils module.h, lines 45-242
@@ -70,7 +71,7 @@
 #ifndef MODUTILS_MODULE_H
 #define MODUTILS_MODULE_H 1
 
-#ident "$Id: insmod.c,v 1.8 2000/06/12 23:11:16 andersen Exp $"
+#ident "$Id: insmod.c,v 1.11 2000/06/26 11:16:22 andersen Exp $"
 
 /* This file contains the structures used by the 2.0 and 2.1 kernels.
    We do not use the kernel headers directly because we do not wish
@@ -276,7 +277,7 @@ int delete_module(const char *);
 #ifndef MODUTILS_OBJ_H
 #define MODUTILS_OBJ_H 1
 
-#ident "$Id: insmod.c,v 1.8 2000/06/12 23:11:16 andersen Exp $"
+#ident "$Id: insmod.c,v 1.11 2000/06/26 11:16:22 andersen Exp $"
 
 /* The relocatable object is manipulated using elfin types.  */
 
@@ -529,6 +530,8 @@ _syscall2(int, new_sys_init_module, const char *, name,
 _syscall5(int, old_sys_init_module, const char *, name, char *, code,
                  unsigned, codesize, struct old_mod_routines *, routines,
                  struct old_symbol_table *, symtab)
+_syscall5(int, query_module, const char *, name, int, which,
+               void *, buf, size_t, bufsize, size_t*, ret);
 #ifndef BB_RMMOD
 _syscall1(int, delete_module, const char *, name)
 #else
@@ -1186,8 +1189,10 @@ old_process_module_arguments(struct obj_file *f, int argc, char **argv)
                int *loc;
 
                p = *argv;
-               if ((q = strchr(p, '=')) == NULL)
+               if ((q = strchr(p, '=')) == NULL) {
+                       argc--;
                        continue;
+                }
                *q++ = '\0';
 
                sym = obj_find_symbol(f, p);
@@ -1207,9 +1212,7 @@ old_process_module_arguments(struct obj_file *f, int argc, char **argv)
                        str = alloca(strlen(q));
                        for (r = str, q++; *q != '"'; ++q, ++r) {
                                if (*q == '\0') {
-                                       fprintf(stderr,
-                                                       "improperly terminated string argument for %s\n",
-                                                       p);
+                                       fprintf(stderr, "improperly terminated string argument for %s\n", p);
                                        return 0;
                                } else if (*q == '\\')
                                        switch (*++q) {
@@ -1338,7 +1341,7 @@ static int old_get_kernel_symbols(void)
 
        nks = get_kernel_syms(NULL);
        if (nks < 0) {
-               perror("get_kernel_syms: %m");
+               errorMsg("get_kernel_syms: %s: %s", m_name, strerror(errno));
                return 0;
        }
 
@@ -1519,7 +1522,7 @@ old_init_module(const char *m_name, struct obj_file *f,
                                                          m_size | (flag_autoclean ? OLD_MOD_AUTOCLEAN
                                                                                : 0), &routines, symtab);
        if (ret)
-               perror("init_module: %m");
+               errorMsg("init_module: %s: %s", m_name, strerror(errno));
 
        free(image);
        free(symtab);
@@ -1549,8 +1552,10 @@ new_process_module_arguments(struct obj_file *f, int argc, char **argv)
                int min, max, n;
 
                p = *argv;
-               if ((q = strchr(p, '=')) == NULL)
+               if ((q = strchr(p, '=')) == NULL) {
+                       argc--;
                        continue;
+                }
 
                key = alloca(q - p + 6);
                memcpy(key, "parm_", 5);
@@ -1834,7 +1839,7 @@ static int new_get_kernel_symbols(void)
                        module_names = xrealloc(module_names, bufsize = ret);
                        goto retry_modules_load;
                }
-               perror("QM_MODULES: %m\n");
+               errorMsg("QM_MODULES: %s", strerror(errno));
                return 0;
        }
 
@@ -1853,7 +1858,7 @@ static int new_get_kernel_symbols(void)
                                /* The module was removed out from underneath us.  */
                                continue;
                        }
-                       perror("query_module: QM_INFO: %m");
+                       errorMsg("query_module: QM_INFO: %s: %s", mn, strerror(errno));
                        return 0;
                }
 
@@ -1868,7 +1873,7 @@ static int new_get_kernel_symbols(void)
                                /* The module was removed out from underneath us.  */
                                continue;
                        default:
-                               perror("query_module: QM_SYMBOLS: %m");
+                               errorMsg("query_module: QM_SYMBOLS: %s: %s", mn, strerror(errno));
                                return 0;
                        }
                }
@@ -1893,7 +1898,7 @@ static int new_get_kernel_symbols(void)
                        syms = xrealloc(syms, bufsize = ret);
                        goto retry_kern_sym_load;
                }
-               perror("kernel: QM_SYMBOLS: %m");
+               errorMsg("kernel: QM_SYMBOLS: %s", strerror(errno));
                return 0;
        }
        nksyms = nsyms = ret;
@@ -2074,7 +2079,7 @@ new_init_module(const char *m_name, struct obj_file *f,
 
        ret = new_sys_init_module(m_name, (struct new_module *) image);
        if (ret)
-               perror("init_module: %m");
+               errorMsg("init_module: %s: %s", m_name, strerror(errno));
 
        free(image);
 
@@ -2454,7 +2459,7 @@ struct obj_file *obj_load(FILE * fp)
 
        fseek(fp, 0, SEEK_SET);
        if (fread(&f->header, sizeof(f->header), 1, fp) != 1) {
-               perror("error reading ELF header: %m");
+               errorMsg("error reading ELF header: %s", strerror(errno));
                return NULL;
        }
 
@@ -2493,7 +2498,7 @@ struct obj_file *obj_load(FILE * fp)
        section_headers = alloca(sizeof(ElfW(Shdr)) * shnum);
        fseek(fp, f->header.e_shoff, SEEK_SET);
        if (fread(section_headers, sizeof(ElfW(Shdr)), shnum, fp) != shnum) {
-               perror("error reading ELF section headers: %m");
+               errorMsg("error reading ELF section headers: %s", strerror(errno));
                return NULL;
        }
 
@@ -2523,8 +2528,7 @@ struct obj_file *obj_load(FILE * fp)
                                sec->contents = xmalloc(sec->header.sh_size);
                                fseek(fp, sec->header.sh_offset, SEEK_SET);
                                if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) {
-                                       fprintf(stderr,
-                                                       "error reading ELF section data: %m\n");
+                                       errorMsg("error reading ELF section data: %s", strerror(errno));
                                        return NULL;
                                }
                        } else {
@@ -2721,8 +2725,7 @@ extern int insmod_main( int argc, char **argv)
                        if (m_filename[0] == '\0'
                                || ((fp = fopen(m_filename, "r")) == NULL)) 
                        {
-                               perror("No module by that name found in " _PATH_MODULES
-                                          "\n");
+                               errorMsg("No module named '%s' found in '%s'\n", m_fullName, _PATH_MODULES);
                                exit(FALSE);
                        }
                }
@@ -2854,7 +2857,7 @@ extern int insmod_main( int argc, char **argv)
                                m_size);
                goto out;
        default:
-               perror("create_module: %m");
+               errorMsg("create_module: %s: %s", m_name, strerror(errno));
                goto out;
        }
 
@@ -2875,5 +2878,5 @@ extern int insmod_main( int argc, char **argv)
 
 out:
        fclose(fp);
-       exit(exit_status);
+       return(exit_status);
 }