An initial modproble implementation. Quite suboptimal still,
authorEric Andersen <andersen@codepoet.org>
Sun, 22 Jul 2001 23:01:03 +0000 (23:01 -0000)
committerEric Andersen <andersen@codepoet.org>
Sun, 22 Jul 2001 23:01:03 +0000 (23:01 -0000)
but it does work...

modprobe.c [new file with mode: 0644]
modutils/modprobe.c [new file with mode: 0644]

diff --git a/modprobe.c b/modprobe.c
new file mode 100644 (file)
index 0000000..971ff0a
--- /dev/null
@@ -0,0 +1,121 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * really dumb modprobe implementation for busybox
+ * Copyright (C) 2001 Lineo, davidm@lineo.com
+ */
+
+#include <stdio.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <string.h>
+#include "busybox.h"
+
+static char cmd[128];
+
+extern int modprobe_main(int argc, char** argv)
+{
+       int     ch, rc = 0;
+       int     loadall = 0, showconfig = 0, debug = 0, autoclean = 0, list = 0;
+       int     show_only = 0, quiet = 0, remove = 0, do_syslog = 0, verbose = 0;
+       char    *load_type = NULL, config = NULL;
+
+       while ((ch = getopt(argc, argv, "acdklnqrst:vVC:")) != -1)
+               switch(ch) {
+               case 'a':
+                       loadall++;
+                       break;
+               case 'c':
+                       showconfig++;
+                       break;
+               case 'd':
+                       debug++;
+                       break;
+               case 'k':
+                       autoclean++;
+                       break;
+               case 'l':
+                       list++;
+                       break;
+               case 'n':
+                       show_only++;
+                       break;
+               case 'q':
+                       quiet++;
+                       break;
+               case 'r':
+                       remove++;
+                       break;
+               case 's':
+                       do_syslog++;
+                       break;
+               case 't':
+                       load_type = optarg;
+                       break;
+               case 'v':
+                       verbose++;
+                       break;
+               case 'C':
+                       config = optarg;
+                       break;
+               case 'V':
+               default:
+                       show_usage();
+                       break;
+               }
+
+       if (load_type || config) {
+               fprintf(stderr, "-t and -C not supported\n");
+               exit(EXIT_FAILURE);
+       }
+
+       if (showconfig)
+               exit(EXIT_SUCCESS);
+       
+       if (list)
+               exit(EXIT_SUCCESS);
+       
+       if (remove) {
+               do {
+                       sprintf(cmd, "rmmod %s %s %s",
+                                       optind >= argc ? "-a" : "",
+                                       do_syslog ? "-s" : "",
+                                       optind < argc ? argv[optind] : "");
+                       if (do_syslog)
+                               syslog(LOG_INFO, "%s", cmd);
+                       if (show_only || verbose)
+                               printf("%s\n", cmd);
+                       if (!show_only)
+                               rc = system(cmd);
+               } while (++optind < argc);
+               exit(EXIT_SUCCESS);
+       }
+
+       if (optind >= argc) {
+               fprintf(stderr, "No module or pattern provided\n");
+               exit(EXIT_FAILURE);
+       }
+
+       sprintf(cmd, "insmod %s %s %s",
+                       do_syslog ? "-s" : "",
+                       quiet ? "-q" : "",
+                       autoclean ? "-k" : "");
+       while (optind < argc) {
+               strcat(cmd, argv[optind]);
+               strcat(cmd, " ");
+               optind++;
+       }
+       if (do_syslog)
+               syslog(LOG_INFO, "%s", cmd);
+       if (show_only || verbose)
+               printf("%s\n", cmd);
+       if (!show_only)
+               rc = system(cmd);
+       else
+               rc = 0;
+
+       exit(rc ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
new file mode 100644 (file)
index 0000000..971ff0a
--- /dev/null
@@ -0,0 +1,121 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * really dumb modprobe implementation for busybox
+ * Copyright (C) 2001 Lineo, davidm@lineo.com
+ */
+
+#include <stdio.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <syslog.h>
+#include <string.h>
+#include "busybox.h"
+
+static char cmd[128];
+
+extern int modprobe_main(int argc, char** argv)
+{
+       int     ch, rc = 0;
+       int     loadall = 0, showconfig = 0, debug = 0, autoclean = 0, list = 0;
+       int     show_only = 0, quiet = 0, remove = 0, do_syslog = 0, verbose = 0;
+       char    *load_type = NULL, config = NULL;
+
+       while ((ch = getopt(argc, argv, "acdklnqrst:vVC:")) != -1)
+               switch(ch) {
+               case 'a':
+                       loadall++;
+                       break;
+               case 'c':
+                       showconfig++;
+                       break;
+               case 'd':
+                       debug++;
+                       break;
+               case 'k':
+                       autoclean++;
+                       break;
+               case 'l':
+                       list++;
+                       break;
+               case 'n':
+                       show_only++;
+                       break;
+               case 'q':
+                       quiet++;
+                       break;
+               case 'r':
+                       remove++;
+                       break;
+               case 's':
+                       do_syslog++;
+                       break;
+               case 't':
+                       load_type = optarg;
+                       break;
+               case 'v':
+                       verbose++;
+                       break;
+               case 'C':
+                       config = optarg;
+                       break;
+               case 'V':
+               default:
+                       show_usage();
+                       break;
+               }
+
+       if (load_type || config) {
+               fprintf(stderr, "-t and -C not supported\n");
+               exit(EXIT_FAILURE);
+       }
+
+       if (showconfig)
+               exit(EXIT_SUCCESS);
+       
+       if (list)
+               exit(EXIT_SUCCESS);
+       
+       if (remove) {
+               do {
+                       sprintf(cmd, "rmmod %s %s %s",
+                                       optind >= argc ? "-a" : "",
+                                       do_syslog ? "-s" : "",
+                                       optind < argc ? argv[optind] : "");
+                       if (do_syslog)
+                               syslog(LOG_INFO, "%s", cmd);
+                       if (show_only || verbose)
+                               printf("%s\n", cmd);
+                       if (!show_only)
+                               rc = system(cmd);
+               } while (++optind < argc);
+               exit(EXIT_SUCCESS);
+       }
+
+       if (optind >= argc) {
+               fprintf(stderr, "No module or pattern provided\n");
+               exit(EXIT_FAILURE);
+       }
+
+       sprintf(cmd, "insmod %s %s %s",
+                       do_syslog ? "-s" : "",
+                       quiet ? "-q" : "",
+                       autoclean ? "-k" : "");
+       while (optind < argc) {
+               strcat(cmd, argv[optind]);
+               strcat(cmd, " ");
+               optind++;
+       }
+       if (do_syslog)
+               syslog(LOG_INFO, "%s", cmd);
+       if (show_only || verbose)
+               printf("%s\n", cmd);
+       if (!show_only)
+               rc = system(cmd);
+       else
+               rc = 0;
+
+       exit(rc ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+