diff options
| author | Eric Andersen <andersen@codepoet.org> | 2001-07-22 23:01:03 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 2001-07-22 23:01:03 +0000 |
| commit | 0139ca92ff4b960e904d18bc0254499e163e2545 (patch) | |
| tree | 7b4a71d62e40ada03496bbd0e17b6dc38dcfeb74 /modutils | |
| parent | 8d79ce832062873e6328f616ebb0c80db32020e3 (diff) | |
| download | busybox-w32-0139ca92ff4b960e904d18bc0254499e163e2545.tar.gz busybox-w32-0139ca92ff4b960e904d18bc0254499e163e2545.tar.bz2 busybox-w32-0139ca92ff4b960e904d18bc0254499e163e2545.zip | |
An initial modproble implementation. Quite suboptimal still,
but it does work...
Diffstat (limited to 'modutils')
| -rw-r--r-- | modutils/modprobe.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c new file mode 100644 index 000000000..971ff0afa --- /dev/null +++ b/modutils/modprobe.c | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * really dumb modprobe implementation for busybox | ||
| 4 | * Copyright (C) 2001 Lineo, davidm@lineo.com | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <stdio.h> | ||
| 8 | #include <getopt.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | #include <syslog.h> | ||
| 12 | #include <string.h> | ||
| 13 | #include "busybox.h" | ||
| 14 | |||
| 15 | static char cmd[128]; | ||
| 16 | |||
| 17 | extern int modprobe_main(int argc, char** argv) | ||
| 18 | { | ||
| 19 | int ch, rc = 0; | ||
| 20 | int loadall = 0, showconfig = 0, debug = 0, autoclean = 0, list = 0; | ||
| 21 | int show_only = 0, quiet = 0, remove = 0, do_syslog = 0, verbose = 0; | ||
| 22 | char *load_type = NULL, config = NULL; | ||
| 23 | |||
| 24 | while ((ch = getopt(argc, argv, "acdklnqrst:vVC:")) != -1) | ||
| 25 | switch(ch) { | ||
| 26 | case 'a': | ||
| 27 | loadall++; | ||
| 28 | break; | ||
| 29 | case 'c': | ||
| 30 | showconfig++; | ||
| 31 | break; | ||
| 32 | case 'd': | ||
| 33 | debug++; | ||
| 34 | break; | ||
| 35 | case 'k': | ||
| 36 | autoclean++; | ||
| 37 | break; | ||
| 38 | case 'l': | ||
| 39 | list++; | ||
| 40 | break; | ||
| 41 | case 'n': | ||
| 42 | show_only++; | ||
| 43 | break; | ||
| 44 | case 'q': | ||
| 45 | quiet++; | ||
| 46 | break; | ||
| 47 | case 'r': | ||
| 48 | remove++; | ||
| 49 | break; | ||
| 50 | case 's': | ||
| 51 | do_syslog++; | ||
| 52 | break; | ||
| 53 | case 't': | ||
| 54 | load_type = optarg; | ||
| 55 | break; | ||
| 56 | case 'v': | ||
| 57 | verbose++; | ||
| 58 | break; | ||
| 59 | case 'C': | ||
| 60 | config = optarg; | ||
| 61 | break; | ||
| 62 | case 'V': | ||
| 63 | default: | ||
| 64 | show_usage(); | ||
| 65 | break; | ||
| 66 | } | ||
| 67 | |||
| 68 | if (load_type || config) { | ||
| 69 | fprintf(stderr, "-t and -C not supported\n"); | ||
| 70 | exit(EXIT_FAILURE); | ||
| 71 | } | ||
| 72 | |||
| 73 | if (showconfig) | ||
| 74 | exit(EXIT_SUCCESS); | ||
| 75 | |||
| 76 | if (list) | ||
| 77 | exit(EXIT_SUCCESS); | ||
| 78 | |||
| 79 | if (remove) { | ||
| 80 | do { | ||
| 81 | sprintf(cmd, "rmmod %s %s %s", | ||
| 82 | optind >= argc ? "-a" : "", | ||
| 83 | do_syslog ? "-s" : "", | ||
| 84 | optind < argc ? argv[optind] : ""); | ||
| 85 | if (do_syslog) | ||
| 86 | syslog(LOG_INFO, "%s", cmd); | ||
| 87 | if (show_only || verbose) | ||
| 88 | printf("%s\n", cmd); | ||
| 89 | if (!show_only) | ||
| 90 | rc = system(cmd); | ||
| 91 | } while (++optind < argc); | ||
| 92 | exit(EXIT_SUCCESS); | ||
| 93 | } | ||
| 94 | |||
| 95 | if (optind >= argc) { | ||
| 96 | fprintf(stderr, "No module or pattern provided\n"); | ||
| 97 | exit(EXIT_FAILURE); | ||
| 98 | } | ||
| 99 | |||
| 100 | sprintf(cmd, "insmod %s %s %s", | ||
| 101 | do_syslog ? "-s" : "", | ||
| 102 | quiet ? "-q" : "", | ||
| 103 | autoclean ? "-k" : ""); | ||
| 104 | while (optind < argc) { | ||
| 105 | strcat(cmd, argv[optind]); | ||
| 106 | strcat(cmd, " "); | ||
| 107 | optind++; | ||
| 108 | } | ||
| 109 | if (do_syslog) | ||
| 110 | syslog(LOG_INFO, "%s", cmd); | ||
| 111 | if (show_only || verbose) | ||
| 112 | printf("%s\n", cmd); | ||
| 113 | if (!show_only) | ||
| 114 | rc = system(cmd); | ||
| 115 | else | ||
| 116 | rc = 0; | ||
| 117 | |||
| 118 | exit(rc ? EXIT_FAILURE : EXIT_SUCCESS); | ||
| 119 | } | ||
| 120 | |||
| 121 | |||
