Fix the pwd and group functions. The bb_ stuff was a leftover from
[oweals/busybox.git] / insmod.c
index e52da91e447466a5eb87c0493bd0e54e235f8ff9..57a152c013f8ae0ef7c7a36d974ae5cfc6fdf0ac 100644 (file)
--- a/insmod.c
+++ b/insmod.c
@@ -2,7 +2,7 @@
 /*
  * Mini insmod implementation for busybox
  *
- * Copyright (C) 1999,2000 by Lineo, inc.
+ * Copyright (C) 1999,2000,2001 by Lineo, inc.
  * Written by Erik Andersen <andersen@lineo.com>
  * and Ron Alder <alder@lineo.com>
  *
 #include <dirent.h>
 #include <ctype.h>
 #include <assert.h>
+#include <string.h>
 #include <getopt.h>
 #include <sys/utsname.h>
+#include <sys/syscall.h>
+#include <linux/unistd.h>
 
 //----------------------------------------------------------------------------
 //--------modutils module.h, lines 45-242
@@ -78,7 +81,7 @@
 #ifndef MODUTILS_MODULE_H
 static const int MODUTILS_MODULE_H = 1;
 
-#ident "$Id: insmod.c,v 1.38 2001/01/24 23:34:48 andersen Exp $"
+#ident "$Id: insmod.c,v 1.44 2001/01/27 09:33:38 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
@@ -284,7 +287,7 @@ int delete_module(const char *);
 #ifndef MODUTILS_OBJ_H
 static const int MODUTILS_OBJ_H = 1;
 
-#ident "$Id: insmod.c,v 1.38 2001/01/24 23:34:48 andersen Exp $"
+#ident "$Id: insmod.c,v 1.44 2001/01/27 09:33:38 andersen Exp $"
 
 /* The relocatable object is manipulated using elfin types.  */
 
@@ -339,7 +342,7 @@ static const int MODUTILS_OBJ_H = 1;
 #define Elf32_RelM     Elf32_Rel
 
 #else
-#error insmod.c no platform specified
+#error Sorry, but insmod.c does not yet support this architecture...
 #endif
 
 #ifndef ElfW
@@ -2889,7 +2892,7 @@ extern int insmod_main( int argc, char **argv)
 #endif
 
        /* Parse any options */
-       while ((opt = getopt(argc, argv, "fkvxL")) > 0) {
+       while ((opt = getopt(argc, argv, "fkvxLo:")) > 0) {
                switch (opt) {
                        case 'f':                       /* force loading */
                                flag_force_load = 1;
@@ -2903,6 +2906,9 @@ extern int insmod_main( int argc, char **argv)
                        case 'x':                       /* do not export externs */
                                flag_export = 0;
                                break;
+                       case 'o':                       /* name the output module */
+                               strncpy(m_name, optarg, BUFSIZ);
+                               break;
                        case 'L':                       /* Stub warning */
                                /* This is needed for compatibility with modprobe.
                                 * In theory, this does locking, but we don't do
@@ -2928,8 +2934,10 @@ extern int insmod_main( int argc, char **argv)
 
        if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o')
                len -= 2;
-       memcpy(m_name, tmp, len);
-       strcpy(m_fullName, m_name);
+       strncpy(m_fullName, tmp, len);
+       if (*m_name == '\0') {
+               strcpy(m_name, m_fullName);
+       }
        strcat(m_fullName, ".o");
 
        /* Get a filedesc for the module */
@@ -3039,6 +3047,9 @@ extern int insmod_main( int argc, char **argv)
        }
        obj_allocate_commons(f);
 
+       /* done with the module name, on to the optional var=value arguments */
+       ++optind;
+
        if (optind < argc) {
                if (m_has_modinfo
                        ? !new_process_module_arguments(f, argc - optind, argv + optind) 
@@ -3058,11 +3069,8 @@ extern int insmod_main( int argc, char **argv)
        m_size = obj_load_size(f);
 
 
-       errno = 0;
        m_addr = create_module(m_name, m_size);
-       switch (errno) {
-       case 0:
-               break;
+       if (m_addr==-1) switch (errno) {
        case EEXIST:
                error_msg("A module named %s already exists\n", m_name);
                goto out;