This incorporates Posix math support into ash. The Posix math support
[oweals/busybox.git] / modprobe.c
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_opt = 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_opt++;
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_opt) {
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