/
depmod.c
141 lines (120 loc) · 3.03 KB
/
depmod.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* depmod
*
* Create dependency file for modprobe, the kernel loadable modules loader.
*
* Copyright 1994, 1995, 1996, 1997 Jacques Gelinas <jack@solucorp.qc.ca>
* Additional modifications: Björn Ekwall <bj0rn@blox.se> February, March 1999
*
* This file is part of the Linux modutils.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <assert.h>
#include <string.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <ctype.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <syslog.h>
#include <limits.h>
#include <elf.h>
#include "busybox.h"
#include "modutils.h"
extern int depmod_main(int argc, char **argv)
{
int ret = -1;
int stdmode = 0;
int err = 0;
int o;
char *file_syms = NULL;
char *conf_file = NULL;
char *base_dir = "";
char *module_dir = NULL;
while ((o = getopt(argc, argv, "aAb:C:eF:hnqsvVru")) != EOF) {
switch (o) {
case 'A':
case 'a':
flag_quick = o == 'A';
stdmode = 1; /* Probe standard directory */
break; /* using the config file */
case 'b':
base_dir = optarg;
break;
case 'C':
conf_file = optarg;
break;
case 'e':
flag_showerror = 1;
break;
case 'F':
file_syms = optarg;
break;
case 'h':
return 0;
break;
case 'n':
flag_dry = 1;
break;
case 'q':
flag_quiet = 1;
break;
case 'u':
flag_unresolved_error = 1;
break;
default:
err = 1;
break;
}
}
if (err) {
bb_error_msg("Aborting");
return EXIT_FAILURE;
}
argc -= optind;
argv += optind;
k_version = get_kernel_version(k_strversion);
if (k_version != -1) {
char tmdn[FILENAME_MAX];
char real_module_dir[FILENAME_MAX];
snprintf(tmdn, FILENAME_MAX, "%s" _PATH_MODULES "/%s/", base_dir, k_strversion);
if (realpath (tmdn, real_module_dir) == NULL)
module_dir = tmdn;
else
module_dir = real_module_dir;
}
else
return EXIT_FAILURE;
if (k_version > MODUTILS_MINIMAL_VERSION_2_6)
#ifdef CONFIG_FEATURE_2_6_MODULES
ret = depmod_main_2_6(argc, argv, stdmode || argc == 0, file_syms, base_dir, module_dir);
#else
return EXIT_FAILURE;
#endif
else
{
#ifdef CONFIG_FEATURE_2_4_MODULES
ret = depmod_main_2_4(argc, argv, stdmode || argc == 0, file_syms, base_dir, module_dir, file_syms);
#else
return EXIT_FAILURE;
#endif /* CONFIG_FEATURE_2_4_MODULES */
}
return ret;
}